@Test void testRetryThirdTimeTrueLimitedMaxInterval() { // maxWait=3; period=1; maxPeriod=1 // will call at 0, 1, 1+1 RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(3); Predicate<String> predicate = retry(rawPredicate, 3, 1, 1, SECONDS); stopwatch.start(); assertTrue(predicate.apply("")); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(2000 - EARLY_RETURN_GRACE, duration, 2000 + SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0, 1000, 2000); }
@Test void testRetryThirdTimeTrue() { // maxWait=4; period=1; maxPeriod defaults to 1*10 // will call at 0, 1, 1+(1*1.5) RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(3); Predicate<String> predicate = retry(rawPredicate, 4, 1, SECONDS); stopwatch.start(); assertTrue(predicate.apply("")); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(2500 - EARLY_RETURN_GRACE, duration, 2500 + SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0, 1000, 1000 + 1500); }
@Test void testRetryWillRunOnceOnNegativeTimeout() { RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(1); Predicate<String> predicate = retry(rawPredicate, -1, 1, SECONDS); stopwatch.start(); assertTrue(predicate.apply("")); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(0, duration, 0 + SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0); }
@Test void testRetryAlwaysFalseMillis() { // maxWait=3; period=1; maxPeriod defaults to 1*10 // will call at 0, 1, 1+(1*1.5), 3 RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(Integer.MAX_VALUE); Predicate<String> predicate = retry(rawPredicate, 3, 1, SECONDS); stopwatch.start(); assertFalse(predicate.apply("")); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(3000 - EARLY_RETURN_GRACE, duration, 3000 + SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0, 1000, 1000 + 1500, 3000); }
@Test void testRetryFirstTimeTrue() { RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(1); Predicate<String> predicate = retry(rawPredicate, 4, 1, SECONDS); stopwatch.start(); assertTrue(predicate.apply("")); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(0, duration, 0 + SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0); }
@Test void testThirdTimeTrue() { // maxWait=4; period=1; maxPeriod defaults to 1*10 // will call at 0, 1, 1+(1*1.5) RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(2); Predicate<String> predicate = retry(rawPredicate, 4, 1, SECONDS); stopwatch.start(); predicate.apply(""); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(2500-EARLY_RETURN_GRACE, duration, 2500+SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0, 1000, 1000+1500); }
@Test void testThirdTimeTrueLimitedMaxInterval() { // maxWait=3; period=1; maxPeriod=1 // will call at 0, 1, 1+1 RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(2); Predicate<String> predicate = retry(rawPredicate, 3, 1, 1, SECONDS); stopwatch.start(); predicate.apply(""); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(2000-EARLY_RETURN_GRACE, duration, 2000+SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0, 1000, 2000); }