コード例 #1
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);
        }
コード例 #2
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());
        }