예제 #1
0
            public async Task UnacknowledgedEventWithNonExpiredRetryPolicyIsRetriedAcrossAdditionalStarts()
            {
                var @event = new TestDurableEvent(SingleValue);
                await _bus.PublishDurable(@event);

                Assume.That(_eventsThatWillBeAcknowledged.ProcessedMessagePayload, Is.EqualTo(SingleValue));

                await _bus.Start();

                Assert.That(_eventsThatWillBeAcknowledged.ProcessedMessagePayload, Is.EqualTo(string.Format("{0}{0}", SingleValue)));
            }
예제 #2
0
            public async Task UnacknowledgedCommandWithNonExpiredRetryPolicyIsRetriedAcrossAdditionalStarts()
            {
                var command = new TestDurableCommand(SingleValue);
                await _bus.SendDurable(command);

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue));

                await _bus.Start();

                Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(string.Format("{0}{0}", SingleValue)));
            }
예제 #3
0
            public async Task CommandAndEventAreRetriedOnNextStart()
            {
                await _bus.SendDurable(new TestDurableCommand(SingleValue));

                await _bus.PublishDurable(new TestDurableEvent(SingleValue));

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue));
                Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue));

                await _bus.Start();

                Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(_doubleValue));
                Assert.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue));
            }
예제 #4
0
            public async Task CanRepublishDurableCommandsOnNextStart()
            {
                await SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus();

                //recreate the bus from scratch
                _bus = new DurableMessageBus(_retryPolicy);

                //re-register the command subscriber
                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);

                //calling start should re-hydrate the list of pending (unacknowledged) commands
                // and then process them using the re-registered subscriber
                await _bus.Start();

                //we should now have one more payload element received
                Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(_tripleValue), "Command not properly re-hydrated.");
            }
예제 #5
0
            public async Task CommandAndEventAreNotRetriedAcrossAdditionalStarts()
            {
                await _bus.SendDurable(new TestDurableCommand(SingleValue));

                await _bus.PublishDurable(new TestDurableEvent(SingleValue));

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue));
                Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue));

                //despite multiple calls to Start(), messages are NOT retried at all as per the retry policy setting
                for (int i = 0; i < 10; i++)
                {
                    await _bus.Start();
                }

                Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue));
                Assert.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue));
            }
예제 #6
0
            public async Task DurableEventsWithoutMatchingVersionAreDiscardedOnBusStart()
            {
                await SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus();

                //recreate the bus from scratch, set the version to be something *other* than the default empty string
                _bus = new DurableMessageBus(_retryPolicy)
                {
                    MessageVersionProvider = () => "not-the-default"
                };

                //re-register the event subscriber
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);

                //calling start should re-hydrate the list of pending (unacknowledged) events
                // and then process them using the re-registered subscriber
                await _bus.Start();

                //because the version of the command doesn't match, we should still only have original two payload elements received
                Assert.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue), "Event with wrong version not properly ignored.");
            }
예제 #7
0
            public async Task MessageIsNotSendToSubscriberOnStart()
            {
                const string singleValue = "0";

                //we need a retry policy with at least one retry
                //  so that we'd expect the call to Start() to attempt a retry
                var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan);

                var bus      = new DurableMessageBus(retryPolicy);
                var commands = new CommandSubscribers();

                bus.RegisterSubscriptionFor <TestDurableCommand>(commands.Handle);

                await bus.SendDurable(new TestDurableCommand(singleValue));

                Assume.That(commands.ProcessedMessagePayload, Is.EqualTo(singleValue), "Command Subscriber didn't receive the expected message.");

                bus.UnRegisterAllSubscriptionsFor <TestDurableCommand>();

                await bus.Start();

                Assert.That(commands.ProcessedMessagePayload, Is.EqualTo(singleValue), "Bus did not properly ignore queued command.");
            }
예제 #8
0
            private async Task SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus()
            {
                _doubleValue = string.Format("{0}{0}", SingleValue);
                _tripleValue = string.Format("{0}{0}{0}", SingleValue);

                _retryPolicy = new RetryPolicy(10, DateTimeUtility.PositiveOneHourTimeSpan);
                _bus         = new DurableMessageBus(_retryPolicy);

                _commands = new DurableCommandSubscribers();
                _events   = new DurableEventSubscribers();

                _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle);
                _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle);

                await _bus.SendDurable(new TestDurableCommand(SingleValue));

                await _bus.PublishDurable(new TestDurableEvent(SingleValue));

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue),
                            "Command Subscriber not registered for command as expected.");
                Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue),
                            "Event Subscriber not registered for event as expected.");

                await _bus.Start();

                Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(_doubleValue),
                            "Command Subscriber not registered for command as expected.");
                Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue),
                            "Event Subscriber not registered for event as expected.");

                await _bus.Stop();

                _bus = null;

                Assume.That(_bus, Is.Null);
            }