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();
            }
        }
示例#2
0
        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_publish_a_MessageHandled_event_after_a_persistent_message_is_processed_by_a_non_persistent_host()
        {
            Transport.Start();

            var command = new FakeCommand(123).ToTransportMessage();
            InnerTransport.RaiseMessageReceived(command);
            Thread.Sleep(10);

            InnerTransport.ExpectNothing();
        }
        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_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();
                }
            }
        }