Ejemplo n.º 1
0
        public virtual void Duplex_09_StopListening()
        {
            ClientMockFarm aClients = new ClientMockFarm(MessagingSystemFactory, ChannelId, 3);
            ServiceMock    aService = new ServiceMock(MessagingSystemFactory, ChannelId);

            try
            {
                aService.InputChannel.StartListening();

                aClients.OpenConnectionsAsync();
                Assert.IsTrue(aClients.Clients[0].OutputChannel.IsConnected);
                Assert.IsTrue(aClients.Clients[1].OutputChannel.IsConnected);
                Assert.IsTrue(aClients.Clients[2].OutputChannel.IsConnected);

                aClients.WaitUntilAllConnectionsAreOpen(1000);
                aService.WaitUntilResponseReceiversConnectNotified(3, 1000);

                aService.InputChannel.StopListening();
                Assert.IsFalse(aService.InputChannel.IsListening);

                //aService.WaitUntilAllResponseReceiversDisconnectNotified(1000);
                aClients.WaitUntilAllConnectionsAreClosed(1000);
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClients.CloseAllConnections();
                aService.InputChannel.StopListening();

                // Wait for traces.
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 2
0
        private void SendBroadcastResponseMessage(string channelId, object broadcastMessage,
                                                  int numberOfClients, int numberOfMessages,
                                                  int openConnectionTimeout,
                                                  int allMessagesReceivedTimeout)
        {
            ThreadPool.SetMinThreads(50, 2);

            ClientMockFarm aClientFarm = new ClientMockFarm(MessagingSystemFactory, channelId, numberOfClients);
            ServiceMock    aService    = new ServiceMock(MessagingSystemFactory, channelId);

            try
            {
                aService.InputChannel.StartListening();
                aClientFarm.OpenConnectionsAsync();

                aClientFarm.WaitUntilAllConnectionsAreOpen(openConnectionTimeout);
                aService.WaitUntilResponseReceiversConnectNotified(numberOfClients, openConnectionTimeout);
                Assert.AreEqual(aClientFarm.Clients.Count(), aService.ConnectedResponseReceivers.Count());
                if (CompareResponseReceiverId)
                {
                    foreach (ClientMock aClient in aClientFarm.Clients)
                    {
                        Assert.IsTrue(aService.ConnectedResponseReceivers.Any(x => x.ResponseReceiverId == aClient.OutputChannel.ResponseReceiverId));
                    }
                }

                PerformanceTimer aStopWatch = new PerformanceTimer();
                aStopWatch.Start();

                for (int i = 0; i < numberOfMessages; ++i)
                {
                    aService.InputChannel.SendResponseMessage("*", broadcastMessage);
                }
                aClientFarm.WaitUntilAllResponsesAreReceived(numberOfMessages, allMessagesReceivedTimeout);

                aStopWatch.Stop();

                foreach (DuplexChannelMessageEventArgs aResponseMessage in aClientFarm.ReceivedResponses)
                {
                    Assert.AreEqual(broadcastMessage, aResponseMessage.Message);
                }
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClientFarm.CloseAllConnections();
                aService.InputChannel.StopListening();

                //EneterTrace.StopProfiler();
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 3
0
        public virtual void Duplex_11_CloseConnection()
        {
            ClientMockFarm aClients = new ClientMockFarm(MessagingSystemFactory, ChannelId, 2);
            ServiceMock    aService = new ServiceMock(MessagingSystemFactory, ChannelId);

            try
            {
                aService.InputChannel.StartListening();

                aClients.OpenConnectionsAsync();
                Assert.IsTrue(aClients.Clients[0].OutputChannel.IsConnected);
                Assert.IsTrue(aClients.Clients[1].OutputChannel.IsConnected);

                aClients.WaitUntilAllConnectionsAreOpen(1000);
                aService.WaitUntilResponseReceiversConnectNotified(2, 1000);
                string aResponseReceiverId1 = aService.ConnectedResponseReceivers[0].ResponseReceiverId;

                // Cient 1 closes the connection.
                aClients.Clients[0].OutputChannel.CloseConnection();
                Assert.IsFalse(aClients.Clients[0].OutputChannel.IsConnected);

                //aClients.Clients[0].WaitUntilConnectionClosedIsNotified(1000);
                aService.WaitUntilResponseRecieverIdDisconnectNotified(aResponseReceiverId1, 2000);
                if (CompareResponseReceiverId)
                {
                    Assert.AreEqual(aClients.Clients[0].OutputChannel.ResponseReceiverId, aService.DisconnectedResponseReceivers[0].ResponseReceiverId);
                }

                // Client 2 can send message.
                aClients.Clients[1].OutputChannel.SendMessage(myRequestMessage);

                aService.WaitUntilMessagesAreReceived(1, 1000);

                Assert.AreEqual(myRequestMessage, aService.ReceivedMessages[0].Message);
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClients.CloseAllConnections();
                aService.InputChannel.StopListening();

                // Wait for traces.
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 4
0
        private void SendMessageReceiveResponse(string channelId, object message, object responseMessage,
                                                int numberOfClients, int numberOfMessages,
                                                int openConnectionTimeout,
                                                int allMessagesReceivedTimeout)
        {
            ThreadPool.SetMinThreads(100, 2);

            ClientMockFarm aClientFarm = new ClientMockFarm(MessagingSystemFactory, channelId, numberOfClients);

            ServiceMock aService = new ServiceMock(MessagingSystemFactory, channelId);

            aService.DoOnMessageReceived_SendResponse(responseMessage);

            try
            {
                //EneterTrace.StartProfiler();

                aService.InputChannel.StartListening();
                aClientFarm.OpenConnectionsAsync();

                aClientFarm.WaitUntilAllConnectionsAreOpen(openConnectionTimeout);
                aService.WaitUntilResponseReceiversConnectNotified(numberOfClients, openConnectionTimeout);
                Assert.AreEqual(aClientFarm.Clients.Count(), aService.ConnectedResponseReceivers.Count());

                if (CompareResponseReceiverId)
                {
                    foreach (ClientMock aClient in aClientFarm.Clients)
                    {
                        Assert.IsTrue(aService.ConnectedResponseReceivers.Any(x => x.ResponseReceiverId == aClient.OutputChannel.ResponseReceiverId));
                    }
                }

                PerformanceTimer aStopWatch = new PerformanceTimer();
                aStopWatch.Start();

                aClientFarm.SendMessageAsync(message, numberOfMessages);
                aClientFarm.WaitUntilAllResponsesAreReceived(numberOfMessages, allMessagesReceivedTimeout);

                aStopWatch.Stop();

                // Wait little bit more for case there is an error that more messages are sent.
                Thread.Sleep(500);

                Assert.AreEqual(numberOfMessages * numberOfClients, aService.ReceivedMessages.Count());
                Assert.AreEqual(numberOfMessages * numberOfClients, aClientFarm.ReceivedResponses.Count());
                foreach (DuplexChannelMessageEventArgs aMessage in aService.ReceivedMessages)
                {
                    Assert.AreEqual(message, aMessage.Message);
                }
                foreach (DuplexChannelMessageEventArgs aResponseMessage in aClientFarm.ReceivedResponses)
                {
                    Assert.AreEqual(responseMessage, aResponseMessage.Message);
                }
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClientFarm.CloseAllConnections();
                aService.InputChannel.StopListening();

                //EneterTrace.StopProfiler();
                Thread.Sleep(200);
            }
        }