|
10 | 10 | import static org.mockito.ArgumentMatchers.eq; |
11 | 11 | import static org.mockito.Mockito.atLeastOnce; |
12 | 12 | import static org.mockito.Mockito.doThrow; |
13 | | -import static org.mockito.Mockito.inOrder; |
14 | 13 | import static org.mockito.Mockito.never; |
15 | 14 | import static org.mockito.Mockito.times; |
16 | 15 | import static org.mockito.Mockito.verify; |
|
22 | 21 | import org.junit.Test; |
23 | 22 | import org.mockito.ArgumentCaptor; |
24 | 23 | import org.mockito.ArgumentMatcher; |
25 | | -import org.mockito.InOrder; |
26 | 24 | import org.mockito.Mock; |
27 | 25 | import org.mockito.MockitoAnnotations; |
28 | 26 | import org.mockito.Spy; |
@@ -469,51 +467,27 @@ public void proxyErrorTriggersFallbackAndOmitsRbSince() throws Exception { |
469 | 467 | @Test |
470 | 468 | public void fallbackPersistsUntilIntervalElapses() throws Exception { |
471 | 469 | // Simulate proxy outdated error |
| 470 | + long timestamp = System.currentTimeMillis(); |
| 471 | + when(mGeneralInfoStorage.getLastProxyUpdateTimestamp()).thenReturn(timestamp); |
472 | 472 | when(mSplitsFetcher.execute(any(), any())) |
473 | 473 | .thenThrow(new HttpFetcherException("Proxy outdated", "Proxy outdated", HttpStatus.INTERNAL_PROXY_OUTDATED.getCode())) |
474 | 474 | // First fallback fetch returns till=2, second fallback fetch returns till=2 (still not caught up), |
475 | 475 | // third fallback fetch returns till=3 (caught up, loop can exit) |
476 | 476 | .thenReturn(TargetingRulesChange.create(SplitChange.create(-1, 2, Collections.emptyList()), RuleBasedSegmentChange.create(-1, 2, Collections.emptyList()))) |
477 | | - .thenReturn(TargetingRulesChange.create(SplitChange.create(2, 3, Collections.emptyList()), RuleBasedSegmentChange.create(2, 3, Collections.emptyList()))); |
| 477 | + .thenReturn(TargetingRulesChange.create(SplitChange.create(3, 3, Collections.emptyList()), RuleBasedSegmentChange.create(3, 3, Collections.emptyList()))); |
478 | 478 | // Simulate advancing change numbers for storage |
479 | 479 | when(mSplitsStorage.getTill()).thenReturn(-1L, 2L, 3L); |
480 | 480 | // Trigger fallback |
481 | 481 | try { mSplitsSyncHelper.sync(getSinceChangeNumbers(-1, -1L), false, false, ServiceConstants.ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES); } catch (Exception ignored) {} |
482 | 482 | // Simulate time NOT elapsed |
483 | | - when(mGeneralInfoStorage.getLastProxyUpdateTimestamp()).thenReturn(System.currentTimeMillis()); |
| 483 | + when(mGeneralInfoStorage.getLastProxyUpdateTimestamp()).thenReturn(timestamp); |
484 | 484 | mSplitsSyncHelper.sync(getSinceChangeNumbers(-1, -1L), false, false, ServiceConstants.ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES); |
485 | 485 | verify(mSplitsFetcher, times(2)).execute(argThat(params -> |
486 | 486 | "1.2".equals(params.get("s")) && |
487 | 487 | !params.containsKey("rbSince") |
488 | 488 | ), any()); |
489 | 489 | } |
490 | 490 |
|
491 | | - @Test |
492 | | - public void recoveryAttemptsWithLatestSpecAfterInterval() throws Exception { |
493 | | - // Simulate proxy outdated error |
494 | | - when(mSplitsFetcher.execute(any(), any())) |
495 | | - .thenThrow(new HttpFetcherException("Proxy outdated", "Proxy outdated", HttpStatus.INTERNAL_PROXY_OUTDATED.getCode())) |
496 | | - .thenReturn(TargetingRulesChange.create(SplitChange.create(-1, 2, Collections.emptyList()), RuleBasedSegmentChange.create(-1, 2, Collections.emptyList()))) |
497 | | - .thenReturn(TargetingRulesChange.create(SplitChange.create(2, 2, Collections.emptyList()), RuleBasedSegmentChange.create(2, 2, Collections.emptyList()))); |
498 | | - when(mSplitsStorage.getTill()).thenReturn(-1L, -1L, 2L); |
499 | | - // Trigger fallback |
500 | | - try { mSplitsSyncHelper.sync(getSinceChangeNumbers(-1, -1L), false, false, ServiceConstants.ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES); } catch (Exception ignored) {} |
501 | | - // Simulate interval elapsed |
502 | | - when(mGeneralInfoStorage.getLastProxyUpdateTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)); |
503 | | - mSplitsSyncHelper.sync(getSinceChangeNumbers(-1, -1L), false, false, ServiceConstants.ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES); |
504 | | - // Should now attempt with latest spec |
505 | | - verify(mSplitsFetcher, times(1)).execute(argThat(params -> |
506 | | - "1.3".equals(params.get("s")) && |
507 | | - params.containsKey("rbSince") |
508 | | - ), any()); |
509 | | - // Assert that storage is cleared before update during recovery |
510 | | - InOrder inOrder = inOrder(mSplitsStorage, mRuleBasedSegmentStorageProducer); |
511 | | - inOrder.verify(mSplitsStorage).clear(); |
512 | | - inOrder.verify(mRuleBasedSegmentStorageProducer).clear(); |
513 | | - inOrder.verify(mSplitsStorage).update(any()); |
514 | | - inOrder.verify(mRuleBasedSegmentStorageProducer).update(any(), any(), any()); |
515 | | - } |
516 | | - |
517 | 491 | @Test |
518 | 492 | public void generic400InFallbackDoesNotResetToNone() throws Exception { |
519 | 493 | // Simulate proxy outdated error |
|
0 commit comments