@Override public void advanceClusterTime(int secs, int incSecs) throws InterruptedException { waitForIdle(); for (int amountLeft = secs; amountLeft > 0; amountLeft -= incSecs) { int diff = Math.min(incSecs, amountLeft); Time.advanceTimeSecs(diff); waitForIdle(); } }
/** * Wait for amt tuples to be fully processed timeoutMs happens. */ public void trackedWait(int amt, int timeoutMs) { final int target = amt + lastSpoutCommit.get(); final String id = cluster.getTrackedId(); Random rand = ThreadLocalRandom.current(); whileTimeout(timeoutMs, () -> { int se = globalAmt(id, "spout-emitted"); int transferred = globalAmt(id, "transferred"); int processed = globalAmt(id, "processed"); LOG.info("emitted {} target {} transferred {} processed {}", se, target, transferred, processed); return (target != se) || (transferred != processed); }, () -> { Time.advanceTimeSecs(1); try { Thread.sleep(rand.nextInt(200)); } catch (Exception e) { throw new RuntimeException(e); } }); lastSpoutCommit.set(target); }
private void validateBackoff(int expectedBackoffSeconds, KafkaSpoutMessageId msgId, KafkaSpoutRetryExponentialBackoff retryService) { Time.advanceTimeSecs(expectedBackoffSeconds - 1); assertThat("The message should not be ready for retry until the backoff has expired", retryService.isReady(msgId), is(false)); Time.advanceTimeSecs(1); assertThat(retryService.isReady(msgId), is(true)); }
Time.advanceTimeSecs(initialRetryDelaySecs); for (int i = 0; i < maxPollRecords; i++) { spout.nextTuple(); Time.advanceTimeSecs(initialRetryDelaySecs); spout.nextTuple(); verify(collector, never()).emit(any(), any(), any());
@Test public void testWillExpireCache() throws Exception { try (SimulatedTime t = new SimulatedTime()) { groupsMapping.prepare(topoConf); when(mockShell.execCommand(ShellUtils.getGroupsForUserCommand(TEST_USER_1))).thenReturn(TEST_TWO_GROUPS, TEST_NO_GROUPS); Set<String> firstGroups = groupsMapping.getGroups(TEST_USER_1); Time.advanceTimeSecs(CACHE_EXPIRATION_SECS * 2); Set<String> secondGroups = groupsMapping.getGroups(TEST_USER_1); assertThat(firstGroups, not(secondGroups)); assertThat(secondGroups, contains(TEST_NO_GROUPS)); } }
spout.fail(msgId); Time.advanceTimeSecs(initialRetryDelaySecs); for (int i = 0; i < numMessages; i++) { spout.nextTuple();
@Test public void testExponentialBackoff() { try (SimulatedTime time = new SimulatedTime()) { KafkaSpoutRetryExponentialBackoff retryService = new KafkaSpoutRetryExponentialBackoff(TimeInterval.seconds(0), TimeInterval.seconds(4), Integer.MAX_VALUE, TimeInterval.seconds(Integer.MAX_VALUE)); long offset = 0; KafkaSpoutMessageId msgId = retryService.getMessageId(testTopic, offset); msgId.incrementNumFails(); msgId.incrementNumFails(); //First failure is the initial delay, so not interesting //Expecting 4*2^(failCount-1) List<Integer> expectedBackoffsSecs = Arrays.asList(new Integer[]{8, 16, 32}); for (Integer expectedBackoffSecs : expectedBackoffsSecs) { retryService.schedule(msgId); Time.advanceTimeSecs(expectedBackoffSecs - 1); assertThat("The message should not be ready for retry until backoff " + expectedBackoffSecs + " has expired", retryService.isReady(msgId), is(false)); Time.advanceTimeSecs(1); assertThat("The message should be ready for retry once backoff " + expectedBackoffSecs + " has expired", retryService.isReady(msgId), is(true)); msgId.incrementNumFails(); retryService.remove(msgId); } } }
verifyUserIs(user, "bob"); Time.advanceTimeSecs(TimeUnit.HOURS.toSeconds(12)); verifyUserIs(user, "alice"); Time.advanceTimeSecs(TimeUnit.HOURS.toSeconds(13));
@Test public void testMaxDelay() { try (SimulatedTime time = new SimulatedTime()) { int maxDelaySecs = 2; KafkaSpoutRetryExponentialBackoff retryService = new KafkaSpoutRetryExponentialBackoff(TimeInterval.seconds(500), TimeInterval.seconds(0), 1, TimeInterval.seconds(maxDelaySecs)); long offset = 0; KafkaSpoutMessageId msgId = retryService.getMessageId(testTopic, offset); msgId.incrementNumFails(); retryService.schedule(msgId); Time.advanceTimeSecs(maxDelaySecs); assertThat("The message should be ready for retry after the max delay", retryService.isReady(msgId), is(true)); } }