HeartbeatModeOutputRateCalculator implements ModeOutputRateCalculator { @Override public OutputRateCalculationResult calculateOutputRate(double currentRate, double maximumOutputRate, SendCounters counters) { if (counters.onlySuccessess()) { return new OutputRateCalculationResult(slowModeRate, OutputRateCalculator.Mode.SLOW); } return new OutputRateCalculationResult(currentRate, OutputRateCalculator.Mode.HEARTBEAT); } HeartbeatModeOutputRateCalculator(double slowModeRate); @Override OutputRateCalculationResult calculateOutputRate(double currentRate,
                                                           double maximumOutputRate,
                                                           SendCounters counters);  }
@Test public void shouldNotChangeAnythingIfThereWereAnyFailures() { counters.incrementSuccesses() .incrementFailures(); assertThat(calculator.calculateOutputRate(1, 20, counters)).hasRate(1).isInMode(OutputRateCalculator.Mode.HEARTBEAT); }
@Test public void shouldSwitchToSlowModeIfOnlySuccesses() { counters.incrementSuccesses(); assertThat(calculator.calculateOutputRate(1, 20, counters)).hasRate(SLOW_RATE).isInMode(OutputRateCalculator.Mode.SLOW); }