Пример #1
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
                             ());
        }
Пример #2
0
 public _Callable_216(AtomicReference <Thread> futureThread, CountDownLatch
                      latch, UnreliableInterface unreliable)
 {
     this.futureThread = futureThread;
     this.latch        = latch;
     this.unreliable   = unreliable;
 }
Пример #3
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
                             ());
        }
Пример #4
0
        public virtual void TestRetryForever()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.RetryForever);

            unreliable.AlwaysSucceeds();
            unreliable.FailsOnceThenSucceeds();
            unreliable.FailsTenTimesThenSucceeds();
        }
Пример #5
0
        public virtual void TestSucceedsTenTimesThenFailOver()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(NewFlipFlopProxyProvider(), new TestFailoverProxy.FailOverOnceOnAnyExceptionPolicy
                                                                                           ());

            for (int i = 0; i < 10; i++)
            {
                Assert.Equal("impl1", unreliable.SucceedsTenTimesThenFailsReturningString
                                 ());
            }
            Assert.Equal("impl2", unreliable.SucceedsTenTimesThenFailsReturningString
                             ());
        }
Пример #6
0
        public virtual void TestTryOnceThenFail()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.TryOnceThenFail);

            unreliable.AlwaysSucceeds();
            try
            {
                unreliable.FailsOnceThenSucceeds();
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (UnreliableInterface.UnreliableException)
            {
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
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)
            {
            }
        }
Пример #9
0
        public virtual void TestExponentialRetry()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.ExponentialBackoffRetry(5, 1L, TimeUnit.Nanoseconds
                                                                                                                                             ));

            unreliable.AlwaysSucceeds();
            unreliable.FailsOnceThenSucceeds();
            try
            {
                unreliable.FailsTenTimesThenSucceeds();
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (UnreliableInterface.UnreliableException)
            {
            }
        }
Пример #10
0
        public virtual void TestRetryUpToMaximumCountWithProportionalSleep()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.RetryUpToMaximumCountWithProportionalSleep(8, 1,
                                                                                                                                                                TimeUnit.Nanoseconds));

            unreliable.AlwaysSucceeds();
            unreliable.FailsOnceThenSucceeds();
            try
            {
                unreliable.FailsTenTimesThenSucceeds();
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (UnreliableInterface.UnreliableException)
            {
            }
        }
Пример #11
0
        public virtual void TestRpcInvocation()
        {
            // For a proxy method should return true
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.RetryForever);

            Assert.True(RetryInvocationHandler.IsRpcInvocation(unreliable));
            // Embed the proxy in ProtocolTranslator
            ProtocolTranslator xlator = new _ProtocolTranslator_83(unreliable);

            // For a proxy wrapped in ProtocolTranslator method should return true
            Assert.True(RetryInvocationHandler.IsRpcInvocation(xlator));
            // Ensure underlying proxy was looked at
            Assert.Equal(xlator.ToString(), "1");
            // For non-proxy the method must return false
            NUnit.Framework.Assert.IsFalse(RetryInvocationHandler.IsRpcInvocation(new object(
                                                                                      )));
        }
Пример #12
0
        public virtual void TestRetryByRemoteException()
        {
            IDictionary <Type, RetryPolicy> exceptionToPolicyMap = Collections.SingletonMap
                                                                   <Type, RetryPolicy>(typeof(UnreliableInterface.FatalException), RetryPolicies.TryOnceThenFail
                                                                                       );
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.RetryByRemoteException(RetryPolicies.RetryForever
                                                                                                                                            , exceptionToPolicyMap));

            try
            {
                unreliable.AlwaysFailsWithRemoteFatalException();
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (RemoteException)
            {
            }
        }
Пример #13
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
                            );
            }
        }
Пример #14
0
        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)
            {
            }
        }
Пример #15
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);
        }
Пример #16
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());
        }
Пример #17
0
        public virtual void TestRetryInterruptible()
        {
            UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface
                                                                                     >(unreliableImpl, RetryPolicies.RetryUpToMaximumTimeWithFixedSleep(10, 10, TimeUnit
                                                                                                                                                        .Seconds));
            CountDownLatch           latch        = new CountDownLatch(1);
            AtomicReference <Thread> futureThread = new AtomicReference <Thread
                                                                         >();
            ExecutorService    exec   = Executors.NewSingleThreadExecutor();
            Future <Exception> future = exec.Submit(new _Callable_216(futureThread, latch, unreliable
                                                                      ));

            latch.Await();
            Thread.Sleep(1000);
            // time to fail and sleep
            Assert.True(futureThread.Get().IsAlive());
            futureThread.Get().Interrupt();
            Exception e = future.Get(1, TimeUnit.Seconds);

            // should return immediately
            NUnit.Framework.Assert.IsNotNull(e);
            Assert.Equal(typeof(Exception), e.GetType());
            Assert.Equal("sleep interrupted", e.Message);
        }
Пример #18
0
 public ConcurrentMethodThread(UnreliableInterface unreliable)
 {
     this.unreliable = unreliable;
 }
Пример #19
0
 public _ProtocolTranslator_83(UnreliableInterface unreliable)
 {
     this.unreliable = unreliable;
     this.count      = 0;
 }