public async Task Invoke_when_timeout_not_in_storage_should_process_successfully() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); await behavior.Invoke(CreateContext(Guid.NewGuid().ToString())); Assert.AreEqual(0, messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Count()); }
public void Should_replay_messages_on_all_handlers() { var peer = new Peer(new PeerId("Test"), "test://test"); var message = new TransportMessage(new MessageTypeId(typeof(FakeCommand)), new byte[20], peer); var dispatcher = new FakeMessageDispatcher(); var handler = new ReplayMessageHandler(dispatcher, new FakeDispatchFactory()); handler.Handle(new ReplayMessageCommand(message, new string[0])); dispatcher.LastDispatchFilter.Invoke(typeof(FakeHandler)).ShouldBeTrue(); dispatcher.LastDispatchFilter.Invoke(typeof(OtherFakeHandler)).ShouldBeTrue(); }
public void Should_replay_messages_on_failed_handlers() { var peer = new Peer(new PeerId("Test"), "test://test"); var message = new TransportMessage(new MessageTypeId(typeof(FakeCommand)), new MemoryStream(new byte[20]), peer); var dispatcher = new FakeMessageDispatcher(); var handler = new ReplayMessageHandler(dispatcher, new FakeDispatchFactory()); handler.Handle(new ReplayMessageCommand(message, new[] { typeof(FakeHandler).FullName })); dispatcher.LastDispatchFilter.Invoke(typeof(FakeHandler)).ShouldBeTrue(); dispatcher.LastDispatchFilter.Invoke(typeof(OtherFakeHandler)).ShouldBeFalse(); }
public async Task Invoke_when_using_dtc_should_enlist_dispatch_in_transaction() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); await behavior.Invoke(CreateContext(timeoutData.Id)); var transportOperation = messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Single(); Assert.AreEqual(DispatchConsistency.Default, transportOperation.RequiredDispatchConsistency); }
public void Invoke_when_removing_timeout_fails_should_throw_exception() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new FakeTimeoutStorage { OnPeek = (id, bag) => CreateTimeout(), OnTryRemove = (id, bag) => false // simulates a concurrent delete }; var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); Assert.That(async () => await behavior.Invoke(CreateContext(Guid.NewGuid().ToString())), Throws.InstanceOf<Exception>()); }
public async Task Invoke_when_message_dispatched_should_remove_timeout_from_timeout_storage() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); await behavior.Invoke(CreateContext(timeoutData.Id)); var result = await timeoutPersister.Peek(timeoutData.Id, null); Assert.Null(result); }
public void Invoke_when_removing_timeout_fails_should_throw_exception() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new FakeTimeoutStorage { OnPeek = (id, bag) => CreateTimeout(), OnTryRemove = (id, bag) => false // simulates a concurrent delete }; var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); Assert.That(async() => await behavior.Invoke(CreateContext(Guid.NewGuid().ToString())), Throws.InstanceOf <Exception>()); }
public async Task Invoke_should_pass_transport_transaction_from_message_context() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); var context = CreateContext(timeoutData.Id); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); await behavior.Invoke(context); Assert.AreSame(context.TransportTransaction, messageDispatcher.TransportTransactionUsed, "Wrong transport transaction passed to the dispatcher"); }