示例#1
0
        public async Task Should_be_observable_at_the_outer_level()
        {
            var observer = new RetryObserver();

            var count = 0;
            IPipe <TestContext> pipe = Pipe.New <TestContext>(x =>
            {
                x.UseRetry(r =>
                {
                    r.None();
                    r.ConnectRetryObserver(observer);
                });
                x.UseRetry(r => r.Interval(4, TimeSpan.FromMilliseconds(2)));
                x.UseExecute(payload =>
                {
                    count++;
                    throw new IntentionalTestException("Kaboom!");
                });
            });

            var context = new TestContext();

            Assert.That(async() => await pipe.Send(context), Throws.TypeOf <IntentionalTestException>());

            Assert.That(count, Is.EqualTo(5));

            await observer.RetryFault;

            Assert.That(observer.RetryFaultCount, Is.EqualTo(1));
        }
示例#2
0
        public async Task Should_be_observable_with_no_retry_allowed()
        {
            var observer = new RetryObserver();

            var count = 0;
            IPipe <TestContext> pipe = Pipe.New <TestContext>(x =>
            {
                x.UseRetry(r =>
                {
                    r.None();
                    r.ConnectRetryObserver(observer);
                });
                x.UseExecute(payload =>
                {
                    count++;
                    throw new IntentionalTestException("Kaboom!");
                });
            });

            var context = new TestContext();

            Assert.That(async() => await pipe.Send(context), Throws.TypeOf <IntentionalTestException>());

            Assert.That(count, Is.EqualTo(1));

            await observer.RetryFault;

            Assert.That(observer.RetryFaultCount, Is.EqualTo(1));
        }
示例#3
0
        public async Task Should_retry_and_then_succeed_without_repeating_forever()
        {
            var observer = new RetryObserver();

            var count = 0;
            IPipe <TestContext> pipe = Pipe.New <TestContext>(x =>
            {
                x.UseRetry(r =>
                {
                    r.Immediate(1);
                    r.ConnectRetryObserver(observer);
                });
                x.UseExecute(payload =>
                {
                    var current = Interlocked.Increment(ref count);

                    if (current == 1)
                    {
                        throw new IntentionalTestException("Kaboom!");
                    }
                });
            });

            var context = new TestContext();

            await pipe.Send(context);

            Assert.That(count, Is.EqualTo(2));

            Assert.That(observer.PostFault.IsCompleted);
            Assert.That(observer.RetryComplete.IsCompleted);
        }
        public void Subscribe(IMaybeObserver <T> observer)
        {
            var parent = new RetryObserver(observer, source, times);

            observer.OnSubscribe(parent);
            parent.Next();
        }
示例#5
0
        public void Subscribe(ISingleObserver <T> observer)
        {
            var parent = new RetryObserver(observer, source, handler);

            observer.OnSubscribe(parent);
            parent.Next();
        }
示例#6
0
        protected override void ConfigureInMemoryBus(IInMemoryBusFactoryConfigurator configurator)
        {
            _retryObserver = new RetryObserver();

            configurator.UseRetry(x =>
            {
                x.Interval(1, TimeSpan.FromMinutes(1));
                x.ConnectRetryObserver(_retryObserver);
            });

            base.ConfigureInMemoryBus(configurator);
        }