@Test
public void shouldStartToMonitorFailoverDbThatWasNotUsedIfMainDbBecomesNotOk() {

    // given:
    int periodWhenUnused = 5;
    int backOffMultiplier = 3;
    State s = createInitialLocalState(periodWhenUnused, backOffMultiplier);
    // when both dbs are ok:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, medium1, low1);
    // then:
    assertState(s, true, false, false, normalPeriod, periodWhenUnused, 0, 1);
    // when main db becomes not ok:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, high1, State.notMeasuredInThisCycle);
    // then:
    assertState(s, false, true, true, backOffMultiplier, normalPeriod, 1, 0);
    // when:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, State.notMeasuredInThisCycle, low2);
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, State.notMeasuredInThisCycle, low2);
    // then:
    assertState(s, true, true, true, backOffMultiplier, normalPeriod, 0, 0);
    // when main db becomes ok but not low:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, medium1, low2);
    // then:
    assertState(s, false, true, true, periodWhenUnused, normalPeriod, 1, 0);
    // when failover db becomes high:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, State.notMeasuredInThisCycle, high1);
    // then:
    assertState(s, true, false, false, normalPeriod, backOffMultiplier, 0, 1);
    // when:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, high2, State.notMeasuredInThisCycle);
    // then:
    assertState(s, false, false, true, backOffMultiplier, backOffMultiplier, 1, 2);
    // when
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, State.notMeasuredInThisCycle, State.notMeasuredInThisCycle);
    // then:
    assertState(s, false, true, true, backOffMultiplier, backOffMultiplier, 2, 0);
    // when:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, State.notMeasuredInThisCycle, high2);
    // then:
    assertState(s, true, false, false, backOffMultiplier, backOffMultiplier * backOffMultiplier, 0, 1);
    // when:
    s.updateLocalStateWithNewExecTimes(emptyLogPrefix, medium1, State.notMeasuredInThisCycle);
    // then:
    assertState(s, true, false, false, normalPeriod, backOffMultiplier * backOffMultiplier, 0, 2);
}