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); }
public virtual void TestRetryUpToMaximumTimeWithFixedSleep() { UnreliableInterface unreliable = (UnreliableInterface)RetryProxy.Create <UnreliableInterface >(unreliableImpl, RetryPolicies.RetryUpToMaximumTimeWithFixedSleep(80, 10, TimeUnit .Nanoseconds)); unreliable.AlwaysSucceeds(); unreliable.FailsOnceThenSucceeds(); try { unreliable.FailsTenTimesThenSucceeds(); NUnit.Framework.Assert.Fail("Should fail"); } catch (UnreliableInterface.UnreliableException) { } }