package org.distributeme.core.failing; import org.distributeme.core.ClientSideCallContext; import org.junit.Test; import static org.junit.Assert.assertEquals; public class FailoverTest { @Test public void testFailingToFailoverServer(){ String myServiceId = "FOO"; String failoverServiceId = new Failover().getRegistrationName(myServiceId); ClientSideCallContext ctx = new ClientSideCallContext(myServiceId, "foo", null); Failover f = new Failover(); assertEquals(myServiceId, f.getServiceIdForCall(ctx)); FailDecision firstFailure = f.callFailed(ctx); assertEquals(FailDecision.Reaction.RETRYONCE, firstFailure.getReaction()); assertEquals(failoverServiceId, firstFailure.getTargetService()); //this is what the stub does ctx.setServiceId(firstFailure.getTargetService()); ctx.increaseCallCount(); assertEquals(failoverServiceId, f.getServiceIdForCall(ctx)); //the following line is outcommented because it doesn't work and breaks the test, however the undelying logic isn#t necessery wrong, because //this situation is prevented by framework (RETRY_ONCE calls aren't executed third time)). //assertEquals(FailDecision.Reaction.FAIL, f.callFailed(ctx).getReaction()); //from now on, every request should go to failover service! ClientSideCallContext ctx2 = new ClientSideCallContext(myServiceId, "foo", null); assertEquals(failoverServiceId, f.getServiceIdForCall(ctx2)); } }