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 non_persistent_messages_should_not_be_sent_to_persistence_peer() { var message = new FakeNonPersistentCommand(123).ToTransportMessage(); Transport.Send(message, new[] { AnotherPersistentPeer }); InnerTransport.ExpectExactly(new TransportMessageSent(message, new[] { AnotherPersistentPeer })); }
public void persistent_messages_sent_to_non_persistent_peers_should_not_generate_a_persist_command() { using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(123).ToTransportMessage(Self); Transport.Send(message, new[] { AnotherNonPersistentPeer }); InnerTransport.ExpectExactly(new TransportMessageSent(message, AnotherNonPersistentPeer)); } }
public void should_send_persistent_message_only_to_the_persistence_when_peer_is_down() { using (MessageId.PauseIdGeneration()) { var message = new FakeCommand(123).ToTransportMessage(); var downPeer = new Peer(new PeerId("Another.Peer"), "tcp://anotherpeer:123", false); Transport.Send(message, new[] { downPeer }); InnerTransport.ExpectExactly(new TransportMessageSent(new PersistMessageCommand(message, new[] { downPeer.Id }).ToTransportMessage(Self), new[] { PersistencePeer })); } }
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_send_persistent_message_to_persistence_peer_and_to_the_peer() { using (MessageId.PauseIdGeneration()) { var message = new FakeCommand(123).ToTransportMessage(); Transport.Send(message, new[] { AnotherPersistentPeer }); InnerTransport.ExpectExactly( new TransportMessageSent(message, new[] { AnotherPersistentPeer }), new TransportMessageSent(new PersistMessageCommand(message, new[] { AnotherPersistentPeer.Id }).ToTransportMessage(Self), new[] { PersistencePeer }) ); } }
public void persistent_messages_sent_to_multiple_peers_should_only_be_persisted_for_persistent_ones() { using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(123).ToTransportMessage(Self); Transport.Send(message, new[] { AnotherPersistentPeer, AnotherNonPersistentPeer }); InnerTransport.ExpectExactly(new [] { new TransportMessageSent(message).To(AnotherPersistentPeer, true).To(AnotherNonPersistentPeer, false).ToPersistence(PersistencePeer), }); } }
public void should_send_persistent_message_to_the_persistence_and_to_the_peer() { using (MessageId.PauseIdGeneration()) { var message = new FakeCommand(123).ToTransportMessage(); Transport.Send(message, new[] { AnotherPersistentPeer }); InnerTransport.ExpectExactly(new[] { new TransportMessageSent(message).To(AnotherPersistentPeer, true).ToPersistence(PersistencePeer), }); } }
public void persistent_messages_sent_to_multiple_peers_should_only_be_persisted_for_persistent_ones() { using (MessageId.PauseIdGeneration()) { var message = new FakeEvent(123).ToTransportMessage(Self); var persistCommand = new PersistMessageCommand(message, new[] { AnotherPersistentPeer.Id }).ToTransportMessage(Self); Transport.Send(message, new[] { AnotherPersistentPeer, AnotherNonPersistentPeer }); InnerTransport.ExpectExactly( new TransportMessageSent(message, new[] { AnotherPersistentPeer, AnotherNonPersistentPeer }), new TransportMessageSent(persistCommand, new[] { PersistencePeer }) ); } }
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(); } } }