コード例 #1
0
        public void When_subscribing_multiple_events_should_throw_aggregate_exception_with_all_failures()
        {
            var context = new TestableSubscribeContext
            {
                EventTypes = new[] { typeof(EventA), typeof(EventB) }
            };

            // Marks this message as a SubscribeAll call
            context.Extensions.Set(MessageSession.SubscribeAllFlagKey, true);
            var state = context.Extensions.GetOrCreate <MessageDrivenSubscribeTerminator.Settings>();

            state.MaxRetries = 0;
            state.RetryDelay = TimeSpan.Zero;
            dispatcher.FailDispatch(10);

            // no publisher for EventB
            publishers.AddOrReplacePublishers("Test", new List <PublisherTableEntry>()
            {
                new PublisherTableEntry(typeof(EventA), PublisherAddress.CreateFromPhysicalAddresses("publisher1")),
            });

            var exception = Assert.ThrowsAsync <AggregateException>(() => subscribeTerminator.Invoke(context, c => Task.CompletedTask));

            Assert.AreEqual(2, exception.InnerExceptions.Count);
            Assert.IsTrue(exception.InnerExceptions.Any(e => e is QueueNotFoundException));                                                                    // exception from dispatcher
            Assert.IsTrue(exception.InnerExceptions.Any(e => e.Message.Contains($"No publisher address could be found for message type '{typeof(EventB)}'"))); // exception from terminator
        }
コード例 #2
0
    public Task SubscribeContext()
    {
        var context = new TestableSubscribeContext
        {
            EventType = typeof(MyMessage)
        };

        return(Verify(context));
    }
コード例 #3
0
        public async Task Should_Dispatch_according_to_max_retries_when_dispatch_fails()
        {
            var context = new TestableSubscribeContext();
            var state = context.Extensions.GetOrCreate<MessageDrivenSubscribeTerminator.Settings>();
            state.MaxRetries = 10;
            state.RetryDelay = TimeSpan.Zero;
            dispatcher.FailDispatch(10);

            await subscribeTerminator.Invoke(context, c => TaskEx.CompletedTask);

            Assert.AreEqual(1, dispatcher.DispatchedTransportOperations.Count);
            Assert.AreEqual(10, dispatcher.FailedNumberOfTimes);
        }
コード例 #4
0
        public async Task Should_Dispatch_according_to_max_retries_when_dispatch_fails()
        {
            var context = new TestableSubscribeContext();
            var state   = context.Extensions.GetOrCreate <MessageDrivenSubscribeTerminator.Settings>();

            state.MaxRetries = 10;
            state.RetryDelay = TimeSpan.Zero;
            dispatcher.FailDispatch(10);

            await subscribeTerminator.Invoke(context, c => Task.CompletedTask);

            Assert.AreEqual(1, dispatcher.DispatchedTransportOperations.Count);
            Assert.AreEqual(10, dispatcher.FailedNumberOfTimes);
        }
コード例 #5
0
        public void When_subscriptionmanager_throws_exception_on_subscribeAll()
        {
            var expectedException       = new Exception("expected exception");
            var fakeSubscriptionManager = new FakeSubscriptionManager(expectedException);
            var terminator =
                new NativeSubscribeTerminator(fakeSubscriptionManager, new MessageMetadataRegistry(_ => true));
            var testableSubscribeContext = new TestableSubscribeContext();

            testableSubscribeContext.Extensions.Set(MessageSession.SubscribeAllFlagKey, true);

            var exception = Assert.ThrowsAsync <Exception>(() => terminator.Invoke(testableSubscribeContext, _ => Task.CompletedTask));

            Assert.AreSame(expectedException, exception);
        }
コード例 #6
0
        public void Should_Throw_when_max_retries_reached()
        {
            var context = new TestableSubscribeContext();
            var state = context.Extensions.GetOrCreate<MessageDrivenSubscribeTerminator.Settings>();
            state.MaxRetries = 10;
            state.RetryDelay = TimeSpan.Zero;
            dispatcher.FailDispatch(11);

            Assert.That(async () =>
            {
                await subscribeTerminator.Invoke(context, c => TaskEx.CompletedTask);
            }, Throws.InstanceOf<QueueNotFoundException>());

            Assert.AreEqual(0, dispatcher.DispatchedTransportOperations.Count);
            Assert.AreEqual(11, dispatcher.FailedNumberOfTimes);
        }
コード例 #7
0
        public void Should_Throw_when_max_retries_reached()
        {
            var context = new TestableSubscribeContext();
            var state   = context.Extensions.GetOrCreate <MessageDrivenSubscribeTerminator.Settings>();

            state.MaxRetries = 10;
            state.RetryDelay = TimeSpan.Zero;
            dispatcher.FailDispatch(11);

            Assert.That(async() =>
            {
                await subscribeTerminator.Invoke(context, c => Task.CompletedTask);
            }, Throws.InstanceOf <QueueNotFoundException>());

            Assert.AreEqual(0, dispatcher.DispatchedTransportOperations.Count);
            Assert.AreEqual(11, dispatcher.FailedNumberOfTimes);
        }
コード例 #8
0
        public async Task Should_dispatch_to_all_publishers_for_all_events()
        {
            var context = new TestableSubscribeContext()
            {
                EventTypes = new[] { typeof(EventA), typeof(EventB) }
            };

            publishers.AddOrReplacePublishers("Test", new List <PublisherTableEntry>()
            {
                new PublisherTableEntry(typeof(EventA), PublisherAddress.CreateFromPhysicalAddresses("publisher1")),
                new PublisherTableEntry(typeof(EventA), PublisherAddress.CreateFromPhysicalAddresses("publisher2")),
                new PublisherTableEntry(typeof(EventB), PublisherAddress.CreateFromPhysicalAddresses("publisher1")),
                new PublisherTableEntry(typeof(EventB), PublisherAddress.CreateFromPhysicalAddresses("publisher2"))
            });

            await subscribeTerminator.Invoke(context, c => Task.CompletedTask);

            Assert.AreEqual(4, dispatcher.DispatchedTransportOperations.Count);
        }