@Test public void maxAttemptsReached() { FixedBackOff backOff = new FixedBackOff(200L, 2); BackOffExecution execution = backOff.start(); assertEquals(200l, execution.nextBackOff()); assertEquals(200l, execution.nextBackOff()); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); }
@Test public void defaultInstance() { FixedBackOff backOff = new FixedBackOff(); BackOffExecution execution = backOff.start(); for (int i = 0; i < 100; i++) { assertEquals(FixedBackOff.DEFAULT_INTERVAL, execution.nextBackOff()); } }
@Test public void liveUpdate() { FixedBackOff backOff = new FixedBackOff(100L, 1); BackOffExecution execution = backOff.start(); assertEquals(100l, execution.nextBackOff()); backOff.setInterval(200l); backOff.setMaxAttempts(2); assertEquals(200l, execution.nextBackOff()); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); }
@Test public void startReturnDifferentInstances() { FixedBackOff backOff = new FixedBackOff(100L, 1); BackOffExecution execution = backOff.start(); BackOffExecution execution2 = backOff.start(); assertEquals(100l, execution.nextBackOff()); assertEquals(100l, execution2.nextBackOff()); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); assertEquals(BackOffExecution.STOP, execution2.nextBackOff()); }
@Test public void toStringContent() { FixedBackOff backOff = new FixedBackOff(200L, 10); BackOffExecution execution = backOff.start(); assertEquals( "FixedBackOff{interval=200, currentAttempts=0, maxAttempts=10}", execution.toString()); execution.nextBackOff(); assertEquals( "FixedBackOff{interval=200, currentAttempts=1, maxAttempts=10}", execution.toString()); execution.nextBackOff(); assertEquals( "FixedBackOff{interval=200, currentAttempts=2, maxAttempts=10}", execution.toString()); }
@Test public void noAttemptAtAll() { FixedBackOff backOff = new FixedBackOff(100L, 0L); BackOffExecution execution = backOff.start(); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); }