@Test public void noSleepOnNormalCase() { gatewayThrottler.handleCall(0); gatewayThrottler.handleCall(0); assertThat(lastSleepValue, is(0L)); }
public void handleCall(int transientErrors) { if (transientErrors > 0) { backOffTimeMs = Math.min(maxSleepTimeMs, backOffTimeMs + distribute(100)); } else { backOffTimeMs = Math.max(0, backOffTimeMs - distribute(10)); } sleepMs(backOffTimeMs); }
GatewayThrottler { public void handleCall(int transientErrors) { if (transientErrors > 0) { backOffTimeMs = Math.min(maxSleepTimeMs, backOffTimeMs + distribute(100)); } else { backOffTimeMs = Math.max(0, backOffTimeMs - distribute(10)); } sleepMs(backOffTimeMs); } }
GatewayThrottler { public void handleCall(int transientErrors) { if (transientErrors > 0) { backOffTimeMs = Math.min(maxSleepTimeMs, backOffTimeMs + distribute(100)); } else { backOffTimeMs = Math.max(0, backOffTimeMs - distribute(10)); } sleepMs(backOffTimeMs); } GatewayThrottler(long maxSleepTimeMs); }
GatewayThrottler { public void handleCall(int transientErrors) { if (transientErrors > 0) { backOffTimeMs = Math.min(maxSleepTimeMs, backOffTimeMs + distribute(100)); } else { backOffTimeMs = Math.max(0, backOffTimeMs - distribute(10)); } sleepMs(backOffTimeMs); } GatewayThrottler(long maxSleepTimeMs); void handleCall(int transientErrors); int distribute(int expected); }
GatewayThrottler { public void handleCall(int transientErrors) { if (transientErrors > 0) { backOffTimeMs = Math.min(maxSleepTimeMs, backOffTimeMs + distribute(100)); } else { backOffTimeMs = Math.max(0, backOffTimeMs - distribute(10)); } sleepMs(backOffTimeMs); } GatewayThrottler(long maxSleepTimeMs); void handleCall(int transientErrors); int distribute(int expected);  }