public void TestOnMessageHubStart_RegisterationMessageIsSent() { var messageHub = new MessageHub(socketFactory.Object, callbackHandlerStack.Object, config, messageTracer.Object, logger); try { messageHub.Start(); var sendingSocket = messageHubSocketFactory.GetSendingSocket(); var receivingSocket = messageHubSocketFactory.GetReceivingSocket(); var message = sendingSocket.GetSentMessages().BlockingLast(AsyncOpCompletionDelay); Assert.IsNotNull(message); var registration = message.GetPayload<RegisterInternalMessageRouteMessage>(); CollectionAssert.AreEqual(receivingSocket.GetIdentity(), registration.SocketIdentity); var handler = registration.MessageContracts.First(); CollectionAssert.AreEqual(Message.CurrentVersion, handler.Version); CollectionAssert.AreEqual(receivingSocket.GetIdentity(), handler.Identity); } finally { messageHub.Stop(); } }
public void TestEnqueueRequest_RegistersMessageAndExceptionHandlers() { var messageHub = new MessageHub(socketFactory.Object, callbackHandlerStack.Object, config, messageTracer.Object, logger); try { messageHub.Start(); var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity); var callback = new CallbackPoint(SimpleMessage.MessageIdentity); messageHub.EnqueueRequest(message, callback); Thread.Sleep(AsyncOp); callbackHandlerStack.Verify(m => m.Push(It.Is<CorrelationId>(c => Unsafe.Equals(c.Value, message.CorrelationId)), It.IsAny<IPromise>(), It.Is<IEnumerable<MessageIdentifier>>(en => ContainsMessageAndExceptionRegistrations(en))), Times.Once); } finally { messageHub.Stop(); } }
public void TestWhenMessageReceivedAndNoHandlerRegistered_PromiseIsNotResolved() { var messageHub = new MessageHub(socketFactory.Object, callbackHandlerStack.Object, config, messageTracer.Object, logger); try { messageHub.Start(); var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity); var callback = new CallbackPoint(SimpleMessage.MessageIdentity); var promise = messageHub.EnqueueRequest(message, callback); callbackHandlerStack.Setup(m => m.Pop(It.IsAny<CallbackHandlerKey>())).Returns((IPromise) null); messageHubSocketFactory.GetReceivingSocket().DeliverMessage(message); Thread.Sleep(AsyncOpCompletionDelay); Assert.IsFalse(promise.GetResponse().Wait(AsyncOpCompletionDelay)); } finally { messageHub.Stop(); } }
public void TestWhenExceptionMessageReceived_PromiseThrowsException() { var messageHub = new MessageHub(socketFactory.Object, callbackHandlerStack.Object, config, messageTracer.Object, logger); try { messageHub.Start(); var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity); var callback = new CallbackPoint(SimpleMessage.MessageIdentity); var promise = messageHub.EnqueueRequest(message, callback); callbackHandlerStack.Setup(m => m.Pop(It.IsAny<CallbackHandlerKey>())).Returns(promise); var errorMessage = Guid.NewGuid().ToString(); var exception = Message.Create(new ExceptionMessage {Exception = new Exception(errorMessage)}, ExceptionMessage.MessageIdentity); messageHubSocketFactory.GetReceivingSocket().DeliverMessage(exception); Assert.Throws<AggregateException>(() => { var response = promise.GetResponse().Result; }, errorMessage); Assert.DoesNotThrow(() => { var response = promise.GetResponse(); }); } finally { messageHub.Stop(); } }
public void TestWhenMessageReceived_CorrespondingPromiseResultSet() { var messageHub = new MessageHub(socketFactory.Object, callbackHandlerStack.Object, config, messageTracer.Object, logger); try { messageHub.Start(); var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity); var callback = new CallbackPoint(SimpleMessage.MessageIdentity); var promise = messageHub.EnqueueRequest(message, callback); callbackHandlerStack.Setup(m => m.Pop(It.IsAny<CallbackHandlerKey>())).Returns(promise); messageHubSocketFactory.GetReceivingSocket().DeliverMessage(message); var response = promise.GetResponse().Result; Assert.IsNotNull(response); Assert.AreEqual(message, response); } finally { messageHub.Stop(); } }
public void TestEnqueueRequest_SendsMessageWithCallbackReceiverIdentityEqualsToReceivingSocketIdentity() { var messageHub = new MessageHub(socketFactory.Object, callbackHandlerStack.Object, config, messageTracer.Object, logger); try { messageHub.Start(); var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity); var callback = new CallbackPoint(SimpleMessage.MessageIdentity); messageHub.EnqueueRequest(message, callback); Thread.Sleep(AsyncOp); var messageOut = messageHubSocketFactory.GetSendingSocket().GetSentMessages().Last(); var receivingSocket = messageHubSocketFactory.GetReceivingSocket(); Assert.IsNotNull(messageOut); CollectionAssert.AreEqual(receivingSocket.GetIdentity(), messageOut.CallbackReceiverIdentity); CollectionAssert.AreEqual(callback.MessageIdentity, messageOut.CallbackIdentity); } finally { messageHub.Stop(); } }