ExponentialBackoff implements BackoffFunction { @Override public long getBackoffTimeMillis(final int reconnectAttempt) { if (reconnectAttempt <= 0) { return 0; } return (long) Math.min(maxTime, minTime * Math.pow(factor, reconnectAttempt - 1)); } ExponentialBackoff(final long minTime, final long maxTime, final double factor); @Override long getBackoffTimeMillis(final int reconnectAttempt);  }
@Test public void testSimple() { int minTime = 10; int maxTime = 1000; double factor = 2.0; ExponentialBackoff exponentialBackoff = new ExponentialBackoff(minTime, maxTime, factor); assertEquals(0, exponentialBackoff.getBackoffTimeMillis(-1)); assertEquals(0, exponentialBackoff.getBackoffTimeMillis(0)); assertEquals(minTime, exponentialBackoff.getBackoffTimeMillis(1)); assertEquals(minTime * factor, exponentialBackoff.getBackoffTimeMillis(2), EPSILON); assertEquals(minTime * factor * factor, exponentialBackoff.getBackoffTimeMillis(3), EPSILON); assertEquals(maxTime, exponentialBackoff.getBackoffTimeMillis(10), EPSILON); }