public void should_not_send_messages_to_persistence_twice_if_persistence_goes_up_and_down() { using (MessageId.PauseIdGeneration()) { // Stopping persistence InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new MemoryStream(), PersistencePeer)); InnerTransport.Messages.Clear(); var ackedMessage = new FakeCommand(456).ToTransportMessage(); Transport.AckMessage(ackedMessage); InnerTransport.AckedMessages.ShouldBeEmpty(); // starting persistence - should send enqueued messages Transport.OnPeerUpdated(PersistencePeer.Id, PeerUpdateAction.Started); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(new MessageHandled(ackedMessage.Id).ToTransportMessage(Self), PersistencePeer) }); // Stopping persistence again InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new MemoryStream(), PersistencePeer)); InnerTransport.Messages.Clear(); // starting persistence again - should not have anything to send Transport.OnPeerUpdated(PersistencePeer.Id, PeerUpdateAction.Started); InnerTransport.ExpectNothing(); } }
public void should_not_send_messages_to_persistence_twice_if_persistence_goes_up_and_down() { using (MessageId.PauseIdGeneration()) { PeerDirectory.Setup(directory => directory.GetPeersHandlingMessage(new MessageBinding(new MessageTypeId(typeof(PersistMessageCommand)), BindingKey.Empty))) .Returns(new List <Peer> { PersistencePeer }); // Stopping persistence InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new byte[0], PersistencePeer)); InnerTransport.Messages.Clear(); var ackedMessage = new FakeCommand(456).ToTransportMessage(); Transport.AckMessage(ackedMessage); InnerTransport.AckedMessages.ShouldBeEmpty(); // starting persistence - should send enqueued messages Transport.OnPeerUpdated(PersistencePeer.Id, PeerUpdateAction.Started); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(new MessageHandled(ackedMessage.Id).ToTransportMessage(Self), PersistencePeer) }); // Stopping persistence again InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new byte[0], PersistencePeer)); InnerTransport.Messages.Clear(); // starting persistence again - should not have anything to send Transport.OnPeerUpdated(PersistencePeer.Id, PeerUpdateAction.Started); InnerTransport.ExpectNothing(); } }
public void should_not_lose_messages_when_persistent_transport_goes_down_and_comes_back_up() { using (MessageId.PauseIdGeneration()) { PeerDirectory.Setup(directory => directory.GetPeersHandlingMessage(new MessageBinding(new MessageTypeId(typeof(PersistMessageCommand)), BindingKey.Empty))) .Returns(new List <Peer> { PersistencePeer }); // Stopping persistence InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new byte[0], PersistencePeer)); InnerTransport.ExpectExactly(new TransportMessageSent(new TransportMessage(MessageTypeId.PersistenceStoppingAck, new byte[0], Self), PersistencePeer)); InnerTransport.Messages.Clear(); // should enqueue messages to persistence var message = new FakeCommand(123).ToTransportMessage(); var ackedMessage = new FakeCommand(456).ToTransportMessage(); Transport.Send(message, new[] { AnotherPersistentPeer }); Transport.AckMessage(ackedMessage); InnerTransport.AckedMessages.ShouldBeEmpty(); InnerTransport.ExpectExactly(new TransportMessageSent(message, AnotherPersistentPeer)); InnerTransport.Messages.Clear(); // starting persistence - should send enqueued messages Transport.OnPeerUpdated(PersistencePeer.Id, PeerUpdateAction.Started); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(new PersistMessageCommand(message, new[] { AnotherPersistentPeer.Id }).ToTransportMessage(Self), PersistencePeer), new TransportMessageSent(new MessageHandled(ackedMessage.Id).ToTransportMessage(Self), PersistencePeer) }); InnerTransport.Messages.Clear(); InnerTransport.AckedMessages.Clear(); // should send messages without going through the queue Transport.Send(message, new[] { AnotherPersistentPeer }); Transport.AckMessage(ackedMessage); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(message, AnotherPersistentPeer), new TransportMessageSent(new PersistMessageCommand(message, new[] { AnotherPersistentPeer.Id }).ToTransportMessage(Self), PersistencePeer), new TransportMessageSent(new MessageHandled(ackedMessage.Id).ToTransportMessage(Self), PersistencePeer), }); } }
public void should_publish_a_MessageHandled_event_after_a_persistent_message_is_processed_by_the_bus() { Transport.Start(); using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123).ToTransportMessage(); InnerTransport.RaiseMessageReceived(new ReplayPhaseEnded(StartMessageReplayCommand.ReplayId).ToTransportMessage()); InnerTransport.RaiseMessageReceived(command); Transport.AckMessage(command); InnerTransport.ExpectExactly(new TransportMessageSent(new MessageHandled(command.Id).ToTransportMessage(Self), new[] { PersistencePeer })); } }
public void should_not_publish_a_MessageHandled_event_after_a_non_persistent_message_is_processed_by_the_bus() { Transport.Start(); using (MessageId.PauseIdGeneration()) { var command = new FakeNonPersistentCommand(123).ToTransportMessage(); InnerTransport.RaiseMessageReceived(new ReplayPhaseEnded(StartMessageReplayCommand.ReplayId).ToTransportMessage()); InnerTransport.RaiseMessageReceived(command); Transport.AckMessage(command); InnerTransport.ExpectNothing(); } }
public void should_not_lose_messages_when_persistent_transport_goes_down_and_comes_back_up() { using (MessageId.PauseIdGeneration()) { // Stopping persistence InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new MemoryStream(), PersistencePeer)); InnerTransport.ExpectExactly(new TransportMessageSent(new TransportMessage(MessageTypeId.PersistenceStoppingAck, new MemoryStream(), Self), PersistencePeer)); InnerTransport.Messages.Clear(); // should enqueue messages to persistence var message = new FakeCommand(123).ToTransportMessage(); var ackedMessage = new FakeCommand(456).ToTransportMessage(); Transport.Send(message, new[] { AnotherPersistentPeer }); Transport.AckMessage(ackedMessage); InnerTransport.AckedMessages.ShouldBeEmpty(); InnerTransport.ExpectExactly(new TransportMessageSent(message, AnotherPersistentPeer, true)); InnerTransport.Messages.Clear(); // starting persistence - should send enqueued messages Transport.OnPeerUpdated(PersistencePeer.Id, PeerUpdateAction.Started); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(message.ToPersistTransportMessage(AnotherPersistentPeer.Id), PersistencePeer), new TransportMessageSent(new MessageHandled(ackedMessage.Id).ToTransportMessage(Self), PersistencePeer) }); InnerTransport.Messages.Clear(); InnerTransport.AckedMessages.Clear(); // should send messages without going through the queue Transport.Send(message, new[] { AnotherPersistentPeer }); Transport.AckMessage(ackedMessage); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(message, AnotherPersistentPeer, true).ToPersistence(PersistencePeer), new TransportMessageSent(new MessageHandled(ackedMessage.Id).ToTransportMessage(Self), PersistencePeer), }); } }
public void should_consider_WasPersisted_before_publishing_a_MessageHandled_event(bool wasPersisted) { Transport.Start(); using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123).ToTransportMessage(wasPersisted: wasPersisted); InnerTransport.RaiseMessageReceived(new ReplayPhaseEnded(StartMessageReplayCommand.ReplayId).ToTransportMessage()); InnerTransport.RaiseMessageReceived(command); Transport.AckMessage(command); if (wasPersisted) { InnerTransport.ExpectExactly(new TransportMessageSent(new MessageHandled(command.Id).ToTransportMessage(Self), PersistencePeer)); } else { InnerTransport.ExpectNothing(); } } }
public void should_discard_messages_waiting_for_persistence_on_stop() { using (MessageId.PauseIdGeneration()) { Transport.Start(); PeerDirectory.Setup(directory => directory.GetPeersHandlingMessage(new MessageBinding(MessageTypeId.PersistenceStoppingAck, BindingKey.Empty))) .Returns(new List <Peer> { PersistencePeer }); // Stopping persistence InnerTransport.RaiseMessageReceived(new TransportMessage(MessageTypeId.PersistenceStopping, new byte[0], PersistencePeer)); InnerTransport.Messages.Clear(); var ackedMessage = new FakeCommand(456).ToTransportMessage(); Transport.AckMessage(ackedMessage); Transport.Stop(); Transport.Start(); } }