ReconnectDelayManager { public int getReconnectDelayMs(InetSocketAddress socketAddress) { return getReconnectDelayMs(socketAddress.getAddress()); } ReconnectDelayManager();  ReconnectDelayManager(final int initialReconnectDelayMs,
                                 final int maxReconnectDelayMs,
                                 final int reconnectDelayResetMs,
                                 final TimeProvider timeProvider); int getReconnectDelayMs(InetSocketAddress socketAddress); int getReconnectDelayMs(InetAddress address); static final int DEFAULT_RECONNECT_DELAY_INITIAL_MS; static final int DEFAULT_RECONNECT_MAX_DELAY_MS; static final int DEFAULT_RECONNECT_DELAY_RESET_TIME_MS; static TimeProvider DEFAULT_TIMEPROVIDER; }
@Test public void testSimple() throws Exception { ArrayList<Integer> values = new ArrayList<Integer>(); int delay = 0; while (delay < maxDelay) { delay = delayManager.getReconnectDelayMs(address); values.add(delay); } List<Integer> expected = Arrays.asList(100, 200, 400, 800, 1600, 3200, 6400, 10000); assertEquals(expected, values); assertEquals(maxDelay, delayManager.getReconnectDelayMs(address)); }
@Test public void testResetDelayMs() throws Exception { long now = System.currentTimeMillis(); timeProvider.setTime(now); int delay = 0; while (delay < maxDelay) { delay = delayManager.getReconnectDelayMs(address); } now += resetTime; timeProvider.setTime(now); assertEquals(initialDelay, delayManager.getReconnectDelayMs(address)); assertEquals(initialDelay * 2, delayManager.getReconnectDelayMs(address)); }