private void simulateRequest(FailoverFeignTarget target) { // This method is called as a part of a request being invoked. // We need to update the mostRecentServerIndex, for the FailoverFeignTarget to track failures properly. target.url(); }
@Override public Request apply(RequestTemplate input) { if (input.url().indexOf("http") != 0) { input.insert(0, url()); } return input.request(); }
@Test public void failsOverMultipleTimesWithFailingLeader() { String initialUrl = normalTarget.url(); for (int i = 0; i < FAILOVERS; i++) { // The 'leader' is the initial node, and fails with non fast-failover exceptions (so without retry after). // The other nodes fail with retry afters. normalTarget.continueOrPropagate( normalTarget.url().equals(initialUrl) ? EXCEPTION_WITHOUT_RETRY_AFTER : EXCEPTION_WITH_RETRY_AFTER); } }
@Test public void blockingTimeoutExceptionResetsFailureCount() { String currentUrl = normalTarget.url(); for (int i = 0; i < ITERATIONS; i++) { for (int j = 1; j < normalTarget.failuresBeforeSwitching; j++) { simulateRequest(normalTarget); normalTarget.continueOrPropagate(EXCEPTION_WITHOUT_RETRY_AFTER); } normalTarget.continueOrPropagate(BLOCKING_TIMEOUT_EXCEPTION); assertThat(normalTarget.url()).isEqualTo(currentUrl); } }
@Test public void retriesOnSameNodeIfBlockingTimeoutIsLastAllowedFailureBeforeSwitch() { for (int i = 1; i < normalTarget.failuresBeforeSwitching; i++) { simulateRequest(normalTarget); normalTarget.continueOrPropagate(EXCEPTION_WITHOUT_RETRY_AFTER); } String currentUrl = normalTarget.url(); normalTarget.continueOrPropagate(BLOCKING_TIMEOUT_EXCEPTION); assertThat(normalTarget.url()).isEqualTo(currentUrl); }
@Override public Request apply(RequestTemplate input) { if (input.url().indexOf("http") != 0) { input.insert(0, url()); } return input.request(); }