public virtual void TestFailoverOnNetworkExceptionIdempotentOperation() { UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface >(NewFlipFlopProxyProvider(UnreliableImplementation.TypeOfExceptionToFailWith.IoException , UnreliableImplementation.TypeOfExceptionToFailWith.UnreliableException), RetryPolicies .FailoverOnNetworkException(1)); Assert.Equal("impl1", unreliable.SucceedsOnceThenFailsReturningString ()); try { unreliable.SucceedsOnceThenFailsReturningString(); NUnit.Framework.Assert.Fail("should not have succeeded twice"); } catch (IOException e) { // Make sure we *don't* fail over since the first implementation threw an // IOException and this method is not idempotent Assert.Equal("impl1", e.Message); } Assert.Equal("impl1", unreliable.SucceedsOnceThenFailsReturningStringIdempotent ()); // Make sure we fail over since the first implementation threw an // IOException and this method is idempotent. Assert.Equal("impl2", unreliable.SucceedsOnceThenFailsReturningStringIdempotent ()); }
public virtual void TestFailoverOnStandbyException() { UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface >(NewFlipFlopProxyProvider(), RetryPolicies.FailoverOnNetworkException(1)); Assert.Equal("impl1", unreliable.SucceedsOnceThenFailsReturningString ()); try { unreliable.SucceedsOnceThenFailsReturningString(); NUnit.Framework.Assert.Fail("should not have succeeded twice"); } catch (UnreliableInterface.UnreliableException e) { // Make sure there was no failover on normal exception. Assert.Equal("impl1", e.Message); } unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface>(NewFlipFlopProxyProvider (UnreliableImplementation.TypeOfExceptionToFailWith.StandbyException, UnreliableImplementation.TypeOfExceptionToFailWith .UnreliableException), RetryPolicies.FailoverOnNetworkException(1)); Assert.Equal("impl1", unreliable.SucceedsOnceThenFailsReturningString ()); // Make sure we fail over since the first implementation threw a StandbyException Assert.Equal("impl2", unreliable.SucceedsOnceThenFailsReturningString ()); }
public virtual void TestNeverFailOver() { UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface >(NewFlipFlopProxyProvider(), RetryPolicies.TryOnceThenFail); unreliable.SucceedsOnceThenFailsReturningString(); try { unreliable.SucceedsOnceThenFailsReturningString(); NUnit.Framework.Assert.Fail("should not have succeeded twice"); } catch (UnreliableInterface.UnreliableException e) { Assert.Equal("impl1", e.Message); } }
public virtual void TestSuccedsOnceThenFailOver() { UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface >(NewFlipFlopProxyProvider(), new TestFailoverProxy.FailOverOnceOnAnyExceptionPolicy ()); Assert.Equal("impl1", unreliable.SucceedsOnceThenFailsReturningString ()); Assert.Equal("impl2", unreliable.SucceedsOnceThenFailsReturningString ()); try { unreliable.SucceedsOnceThenFailsReturningString(); NUnit.Framework.Assert.Fail("should not have succeeded more than twice"); } catch (UnreliableInterface.UnreliableException) { } }