OutputRateCalculator { public void start() { maxRateProvider.start(); } OutputRateCalculator(ConfigFactory configFactory, MaxRateProvider maxRateProvider); OutputRateCalculationResult recalculateRate(SendCounters counters,
                                                       Mode currentMode, double currentRateLimit); void updateSubscription(Subscription newSubscription); void start(); void shutdown();  }
@Test public void shouldStartInNormalModeAndGraduallyIncreaseToMaximumWhenOnlySuccessfulDeliveries() { OutputRateCalculationScenario scenario = new OutputRateCalculationScenario(calculator); scenario.start(10).fastForwardWithSuccesses(10); scenario.verifyFinalResult(MAX_RATE, OutputRateCalculator.Mode.NORMAL); }
@Test public void shouldStartInNormalModeReachMaximumAndGoToHeartbeatViaSlowWhenDeliveryStartsFailing() { OutputRateCalculationScenario scenario = new OutputRateCalculationScenario(calculator); scenario.start(10).fastForwardWithSuccesses(10).nextInteration(2, 10).fastForwardWithFailures(20); scenario.verifyIntermediateResult(11, 1, OutputRateCalculator.Mode.SLOW) .verifyFinalResult(HEARTBEAT_RATE, OutputRateCalculator.Mode.HEARTBEAT); }
@Test public void shouldRecoverFromHeartbeatModeAndGetToMaximumViaSlowWhenDeliveringWithSuccess() { OutputRateCalculationScenario scenario = new OutputRateCalculationScenario(calculator); scenario.start(10).fastForwardWithFailures(10) .fastForwardWithSuccesses(15); scenario.verifyIntermediateResult(11, 1, OutputRateCalculator.Mode.SLOW) .verifyFinalResult(MAX_RATE, OutputRateCalculator.Mode.NORMAL); }
@Test public void shouldImmediatelySwitchToHeartbeatModeWhenAllMessagesFail() { OutputRateCalculationScenario scenario = new OutputRateCalculationScenario(calculator); scenario.start(10).fastForwardWithSuccesses(10).fastForwardWithFailures(2); scenario.verifyIntermediateResult(10, MAX_RATE, OutputRateCalculator.Mode.NORMAL) .verifyFinalResult(HEARTBEAT_RATE, OutputRateCalculator.Mode.HEARTBEAT); }