예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        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();
            }
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        private static IMessage SendMessageOverMessageHub()
        {
            var messageTracer = new Mock<kino.Client.IMessageTracer>();
            var logger = new Mock<ILogger>();
            var sockrtFactory = new Mock<ISocketFactory>();
            var socket = new StubSocket();
            sockrtFactory.Setup(m => m.CreateDealerSocket()).Returns(socket);

            var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

            var messageHub = new MessageHub(sockrtFactory.Object,
                                            new CallbackHandlerStack(new ExpirableItemCollection<CorrelationId>(logger.Object)),
                                            new MessageHubConfiguration(),
                                            messageTracer.Object,
                                            logger.Object);
            messageHub.Start();
            messageHub.EnqueueRequest(message, callback);
            Thread.Sleep(AsyncOpCompletionDelay);

            return socket.GetSentMessages().BlockingLast(AsyncOpCompletionDelay);
        }