public void should_send_MessageProcessingFailed_if_unable_to_deserialize_message() { SetupPeersHandlingMessage <MessageProcessingFailed>(_peerUp); _bus.Start(); var command = new FakeCommand(123); _messageSerializer.AddSerializationExceptionFor(command.TypeId(), "Serialization error"); using (SystemDateTime.PauseTime()) using (MessageId.PauseIdGeneration()) { var transportMessage = command.ToTransportMessage(); var messageProcessingFailedBytes = new MessageProcessingFailed(null, null, null, DateTime.UtcNow, null).ToTransportMessage().Content; _messageSerializer.AddSerializationFuncFor <MessageProcessingFailed>(x => { x.FailingMessage.ShouldEqual(transportMessage); x.ExceptionUtcTime.ShouldEqual(SystemDateTime.UtcNow); x.ExceptionMessage.ShouldContain("Unable to deserialize message"); return(messageProcessingFailedBytes); }); _transport.RaiseMessageReceived(transportMessage); var processingFailedTransportMessage = new TransportMessage(MessageUtil.TypeId <MessageProcessingFailed>(), messageProcessingFailedBytes, _self); _transport.ExpectExactly(new TransportMessageSent(processingFailedTransportMessage, _peerUp)); } }
public void should_create_message_dispatch() { var command = new FakeCommand(123); var dispatch = _bus.CreateMessageDispatch(command.ToTransportMessage()); dispatch.Message.ShouldEqualDeeply(command); }
public void should_not_send_acknowledgement_when_message_handled() { var command = new FakeCommand(123); var dispatch = _bus.CreateMessageDispatch(command.ToTransportMessage()); dispatch.SetHandlerCount(1); dispatch.SetHandled(null, null); _transport.ExpectNothing(); }
public void should_not_consider_if_peer_is_up_to_send_commands([Values(true, false)] bool isTargetPeerUp) { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(456); SetupPeersHandlingMessage <FakeCommand>(isTargetPeerUp ? _peerUp : _peerDown); _bus.Send(command); _transport.ExpectExactly(new TransportMessageSent(command.ToTransportMessage(_self), new[] { isTargetPeerUp?_peerUp: _peerDown })); } }
public void should_ack_transport_when_handling_undeserializable_message() { var command = new FakeCommand(123); _messageSerializer.AddSerializationExceptionFor(command.TypeId()); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); _transport.AckedMessages.ShouldContain(transportMessage); }
public void should_dispatch_received_message() { var command = new FakeCommand(123); var invokerCalled = false; SetupDispatch(command, _ => invokerCalled = true); var transportMessageReceived = command.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); invokerCalled.ShouldBeTrue(); }
public void shoud_send_a_completion_message_without_error_code() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); SetupDispatch(command); var transportMessageReceived = command.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); var messageExecutionCompleted = new MessageExecutionCompleted(transportMessageReceived.Id, 0, null).ToTransportMessage(_self); _transport.ExpectExactly(new TransportMessageSent(messageExecutionCompleted, _peerUp)); } }
public void shoud_send_a_completion_message_with_error_code_on_exception() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); SetupDispatch(command, error: new Exception()); var transportMessageReceived = command.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, 1, null).ToTransportMessage(_self); _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp)); } }
public void should_dump_incoming_message_if_unable_to_deserialize_it() { var command = new FakeCommand(123); _messageSerializer.AddSerializationExceptionFor(command.TypeId()); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); var dumpFileName = System.IO.Directory.GetFiles(_bus.DeserializationFailureDumpDirectoryPath).ExpectedSingle(); dumpFileName.ShouldContain("Abc.Zebus.Tests.Messages.FakeCommand"); File.ReadAllBytes(dumpFileName).Length.ShouldEqual(2); }
public void shoud_send_a_completion_message_with_domain_exception_error_code() { using (MessageId.PauseIdGeneration()) { const int domainExceptionValue = 5000; var command = new FakeCommand(123); SetupDispatch(command, error: new DomainException(domainExceptionValue, "Domain Exception")); var transportMessageReceived = command.ToTransportMessage(_peerUp); _transport.RaiseMessageReceived(transportMessageReceived); var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, domainExceptionValue).ToTransportMessage(_self); _transport.ExpectExactly(new TransportMessageSent(expectedTransportMessage, _peerUp)); } }
public void should_create_custom_message_dispatch_for_PersistMessageCommand() { var command = new FakeCommand(123); var transportMessage = command.ToTransportMessage(); transportMessage.PersistentPeerIds = new List <PeerId> { new PeerId("Abc.SomePersistentPeer.0") }; var dispatch = _bus.CreateMessageDispatch(transportMessage); var persistCommand = dispatch.Message as PersistMessageCommand; persistCommand.ShouldNotBeNull(); persistCommand.Targets.ShouldBeEquivalentTo(transportMessage.PersistentPeerIds); persistCommand.TransportMessage.ShouldHaveSamePropertiesAs(transportMessage, "IsPersistTransportMessage", "PersistentPeerIds"); }
public void should_send_message() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(456); SetupPeersHandlingMessage <FakeCommand>(_peerUp); _bus.Send(command); var sentMessage = _transport.Messages.Single(); var expectedTransportMessage = command.ToTransportMessage(_self); sentMessage.TransportMessage.ShouldHaveSamePropertiesAs(expectedTransportMessage); var destination = sentMessage.Targets.Single(); destination.ShouldHaveSamePropertiesAs(_peerUp); } }
public void should_send_a_MessageProcessingFailed_on_unknown_error_with_local_processing() { using (SystemDateTime.PauseTime()) using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); var commandJson = JsonConvert.SerializeObject(command); var exception = new Exception("Exception message"); SetupDispatch(command, error: exception); SetupPeersHandlingMessage <FakeCommand>(_self); _bus.Send(command); var expectedTransportMessage = new MessageProcessingFailed(command.ToTransportMessage(_self), commandJson, exception.ToString(), SystemDateTime.UtcNow, new[] { typeof(FakeMessageHandler).FullName }).ToTransportMessage(_self); _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp)); } }
public void should_ack_transport_message_when_dispatch_done() { var command = new FakeCommand(123); SetupDispatch(command); SetupPeersHandlingMessage <FakeCommand>(_peerUp); var task = _bus.Send(command); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); task.Wait(10); _transport.AckedMessages.Count.ShouldEqual(1); _transport.AckedMessages[0].Id.ShouldEqual(transportMessage.Id); }
public void should_not_handle_command_locally_when_local_dispatch_is_disabled() { var command = new FakeCommand(1); var handled = false; SetupDispatch(command, _ => handled = true); SetupPeersHandlingMessage <FakeCommand>(_self); using (LocalDispatch.Disable()) using (MessageId.PauseIdGeneration()) { var completed = _bus.Send(command).Wait(5); handled.ShouldBeFalse(); completed.ShouldBeFalse(); _transport.ExpectExactly(new TransportMessageSent(command.ToTransportMessage(_self), _self)); } }
public void handlers_reply_with_an_int() { using (MessageId.PauseIdGeneration()) { const int commandReply = 456; var command = new FakeCommand(123); SetupDispatch(command, _ => _bus.Reply(commandReply)); var transportMessageReceived = command.ToTransportMessage(_peerUp); var expectedTransportMessage = new MessageExecutionCompleted(transportMessageReceived.Id, commandReply, null).ToTransportMessage(_self); _transport.RaiseMessageReceived(transportMessageReceived); var sentMessage = _transport.Messages.Single(); expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage); var destination = sentMessage.Targets.Single(); destination.ShouldHaveSamePropertiesAs(_peerUp); } }
public void handlers_reply_with_an_object() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); var commandResult = new FakeCommandResult("CommandResult", 45); var transportMessageReceived = command.ToTransportMessage(_peerUp); SetupDispatch(command, _ => _bus.Reply(commandResult)); var expectedExecutionCompleted = MessageExecutionCompleted.Success(transportMessageReceived.Id, commandResult, _messageSerializer); var expectedTransportMessage = expectedExecutionCompleted.ToTransportMessage(_self); _transport.RaiseMessageReceived(transportMessageReceived); var sentMessage = _transport.Messages.Single(); expectedTransportMessage.ShouldHaveSamePropertiesAs(sentMessage.TransportMessage); var destination = sentMessage.Targets.Single(); destination.ShouldHaveSamePropertiesAs(_peerUp); } }
public void should_forward_initiator_id() { using (MessageId.PauseIdGeneration()) { var receivedCommand = new FakeCommand(123); var eventToPublish = new FakeEvent(456); SetupDispatch(receivedCommand, _ => _bus.Publish(eventToPublish)); SetupPeersHandlingMessage <FakeEvent>(_peerDown); using (MessageContext.SetCurrent(MessageContext.CreateTest(new OriginatorInfo(_peerUp.Id, _peerUp.EndPoint, null, "x.initiator")))) { var transportMessageReceived = receivedCommand.ToTransportMessage(_peerUp); transportMessageReceived.Originator.InitiatorUserName.ShouldEqual("x.initiator"); _transport.RaiseMessageReceived(transportMessageReceived); } var sentMessage = _transport.Messages.Single(x => x.TransportMessage.MessageTypeId == eventToPublish.TypeId()); sentMessage.TransportMessage.Originator.InitiatorUserName.ShouldEqual("x.initiator"); } }
public void should_send_CustomMessageProcessingFailed_if_unable_to_deserialize_message() { using (MessageId.PauseIdGeneration()) { SetupPeersHandlingMessage <CustomProcessingFailed>(_peerUp); var serializerMock = new Mock <IMessageSerializer>(); serializerMock.Setup(serializer => serializer.Deserialize(It.IsAny <MessageTypeId>(), It.IsAny <byte[]>())) .Throws(new Exception("message")); var bus = new Bus(_transport, _directoryMock.Object, serializerMock.Object, _messageDispatcherMock.Object, new DefaultStoppingStrategy()); bus.Configure(_self.Id, "test"); var command = new FakeCommand(123); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); var processingFailed = new CustomProcessingFailed(typeof(Bus).FullName, "message", SystemDateTime.UtcNow); var processingFailedTransportMessage = new TransportMessage(processingFailed.TypeId(), new byte[0], _self); _transport.ExpectExactly(new TransportMessageSent(processingFailedTransportMessage, _peerUp)); } }
public void should_send_a_MessageProcessingFailed_on_dispatch_error() { SetupPeersHandlingMessage <MessageProcessingFailed>(_peerUp); _bus.Start(); using (SystemDateTime.PauseTime()) using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(123); var transportMessageReceived = command.ToTransportMessage(_peerUp); var dispatch = _bus.CreateMessageDispatch(transportMessageReceived); var exception = new Exception("Test error"); dispatch.SetHandlerCount(1); var invokerMock = new Mock <IMessageHandlerInvoker>(); invokerMock.SetupGet(x => x.MessageHandlerType).Returns(typeof(FakeMessageHandler)); dispatch.SetHandled(invokerMock.Object, exception); var commandJson = JsonConvert.SerializeObject(command); var expectedTransportMessage = new MessageProcessingFailed(transportMessageReceived, commandJson, exception.ToString(), SystemDateTime.UtcNow, new[] { typeof(FakeMessageHandler).FullName }).ToTransportMessage(_self); _transport.Expect(new TransportMessageSent(expectedTransportMessage, _peerUp)); } }