Esempio n. 1
0
        public virtual void TestExpectedIOException()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(NewFlipFlopProxyProvider(UnreliableImplementation.TypeOfExceptionToFailWith.RemoteException
                                                                                                                , UnreliableImplementation.TypeOfExceptionToFailWith.UnreliableException), RetryPolicies
                                                                                       .FailoverOnNetworkException(RetryPolicies.TryOnceThenFail, 10, 1000, 10000));

            try
            {
                unreliable.FailsIfIdentifierDoesntMatch("no-such-identifier");
                NUnit.Framework.Assert.Fail("Should have thrown *some* exception");
            }
            catch (Exception e)
            {
                Assert.True("Expected IOE but got " + e.GetType(), e is IOException
                            );
            }
        }
Esempio n. 2
0
        public virtual void TestFailoverBetweenMultipleStandbys()
        {
            long millisToSleep             = 10000;
            UnreliableImplementation impl1 = new UnreliableImplementation("impl1", UnreliableImplementation.TypeOfExceptionToFailWith
                                                                          .StandbyException);

            TestFailoverProxy.FlipFlopProxyProvider <UnreliableInterface> proxyProvider = new
                                                                                          TestFailoverProxy.FlipFlopProxyProvider <UnreliableInterface>(typeof(UnreliableInterface
                                                                                                                                                               ), impl1, new UnreliableImplementation("impl2", UnreliableImplementation.TypeOfExceptionToFailWith
                                                                                                                                                                                                      .StandbyException));
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(proxyProvider, RetryPolicies.FailoverOnNetworkException(RetryPolicies.TryOnceThenFail
                                                                                                                                               , 10, 1000, 10000));

            new _Thread_328(millisToSleep, impl1).Start();
            string result = unreliable.FailsIfIdentifierDoesntMatch("renamed-impl1");

            Assert.Equal("renamed-impl1", result);
        }
Esempio n. 3
0
        public virtual void TestConcurrentMethodFailures()
        {
            TestFailoverProxy.FlipFlopProxyProvider <UnreliableInterface> proxyProvider = new
                                                                                          TestFailoverProxy.FlipFlopProxyProvider <UnreliableInterface>(typeof(UnreliableInterface
                                                                                                                                                               ), new TestFailoverProxy.SynchronizedUnreliableImplementation("impl1", UnreliableImplementation.TypeOfExceptionToFailWith
                                                                                                                                                                                                                             .StandbyException, 2), new UnreliableImplementation("impl2", UnreliableImplementation.TypeOfExceptionToFailWith
                                                                                                                                                                                                                                                                                 .StandbyException));
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(proxyProvider, RetryPolicies.FailoverOnNetworkException(10));

            TestFailoverProxy.ConcurrentMethodThread t1 = new TestFailoverProxy.ConcurrentMethodThread
                                                              (unreliable);
            TestFailoverProxy.ConcurrentMethodThread t2 = new TestFailoverProxy.ConcurrentMethodThread
                                                              (unreliable);
            t1.Start();
            t2.Start();
            t1.Join();
            t2.Join();
            Assert.Equal("impl2", t1.result);
            Assert.Equal("impl2", t2.result);
            Assert.Equal(1, proxyProvider.GetFailoversOccurred());
        }
Esempio n. 4
0
        public virtual void TestExceptionPropagatedForNonIdempotentVoid()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(NewFlipFlopProxyProvider(UnreliableImplementation.TypeOfExceptionToFailWith.IoException
                                                                                                                , UnreliableImplementation.TypeOfExceptionToFailWith.UnreliableException), RetryPolicies
                                                                                       .FailoverOnNetworkException(1));

            try
            {
                unreliable.NonIdempotentVoidFailsIfIdentifierDoesntMatch("impl2");
                NUnit.Framework.Assert.Fail("did not throw an exception");
            }
            catch (Exception)
            {
            }
        }
Esempio n. 5
0
        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
                             ());
        }
Esempio n. 6
0
        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
                             ());
        }