public async Task SetUp() { await ClearAllDataFiles(); var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan); _bus = new DurableMessageBus(retryPolicy); _commands = new CommandSubscribers(); _events = new EventSubscribers(); _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle); _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle); }
public async Task SetUp() { await ClearAllDataFiles(); var retryPolicy = new RetryPolicy(); Assume.That(retryPolicy.Retries, Is.EqualTo(0)); _bus = new DurableMessageBus(retryPolicy); _commands = new CommandSubscribers(); _events = new EventSubscribers(); _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle); _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle); }
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); }
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."); }
public void RegisterMessageBusSubscribers() { _messageBus.RegisterSubscriptionFor <ChangeNameCommand>(new ChangeNameCommandHandler(_messageBus).Handle); _messageBus.RegisterSubscriptionFor <NameChangedEvent>(new NameChangedEventViewModelHandler(_modelManager).Handle); _messageBus.RegisterSubscriptionFor <NameChangedEvent>(new NameChangedEventPersistenceHandler().Handle); var incrementCounterCommandHandler = new IncrementCounterCommandHandler(_messageBus); _messageBus.RegisterSubscriptionFor <IncrementCounterWithAckCommand>(incrementCounterCommandHandler.Handle); _messageBus.RegisterSubscriptionFor <IncrementCounterWithoutAckCommand>(incrementCounterCommandHandler.Handle); var counterIncrementedViewModelEventHandler = new CounterIncrementedViewModelEventHandler(_messageBus, _modelManager); _messageBus.RegisterSubscriptionFor <CounterIncrementedWithAckEvent>(counterIncrementedViewModelEventHandler.Handle); _messageBus.RegisterSubscriptionFor <CounterIncrementedWithoutAckEvent>(counterIncrementedViewModelEventHandler.Handle); }
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."); }
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."); }