Ejemplo n.º 1
0
        public void PortAvailability()
        {
            IDuplexInputChannel anInputChannel1 = MessagingSystemFactory.CreateDuplexInputChannel("tcp://[::1]:8044/");
            IDuplexInputChannel anInputChannel2 = MessagingSystemFactory.CreateDuplexInputChannel("tcp://127.0.0.1:8044/");

            try
            {
                anInputChannel1.StartListening();
                anInputChannel2.StartListening();

                Console.WriteLine("Available IP addresses:");
                string[] anAvailableIpAddresses = TcpMessagingSystemFactory.GetAvailableIpAddresses();
                foreach (string anIpAddress in anAvailableIpAddresses)
                {
                    Console.WriteLine(anIpAddress);
                }

                bool aResult = TcpMessagingSystemFactory.IsPortAvailableForTcpListening("tcp://[::1]:8044/");
                Assert.IsFalse(aResult);

                aResult = TcpMessagingSystemFactory.IsPortAvailableForTcpListening("tcp://0.0.0.0:8044/");
                Assert.IsTrue(aResult);
            }
            finally
            {
                anInputChannel1.StopListening();
                anInputChannel2.StopListening();
            }
        }
        public void B01_Pinging_StopListening()
        {
            IDuplexInputChannel aDuplexInputChannel = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);

            IDuplexOutputChannel aDuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            AutoResetEvent aDisconnectedEvent = new AutoResetEvent(false);

            bool aDisconnectedFlag = false;

            aDuplexOutputChannel.ConnectionClosed += (x, y) =>
            {
                aDisconnectedFlag = true;
                aDisconnectedEvent.Set();
            };

            try
            {
                // Start listening.
                aDuplexInputChannel.StartListening();

                // Start pinging and wait 5 seconds.
                aDuplexOutputChannel.OpenConnection();
                Thread.Sleep(5000);

                Assert.IsFalse(aDisconnectedFlag);

                // Stop listener, therefore the ping response will not come and the channel should indicate the disconnection.
                aDuplexInputChannel.StopListening();

                aDisconnectedEvent.WaitOne();

                Assert.IsTrue(aDisconnectedFlag);
                Assert.IsFalse(aDuplexOutputChannel.IsConnected);
            }
            finally
            {
                aDuplexOutputChannel.CloseConnection();
                aDuplexInputChannel.StopListening();
            }
        }
        public void B02_Pinging_DisconnectResponseReceiver()
        {
            IDuplexInputChannel  aDuplexInputChannel  = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);
            IDuplexOutputChannel aDuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            AutoResetEvent aDisconnectedEvent = new AutoResetEvent(false);

            bool aDisconnectedFlag = false;

            aDuplexOutputChannel.ConnectionClosed += (x, y) =>
            {
                aDisconnectedFlag = true;
                aDisconnectedEvent.Set();
            };

            try
            {
                // Start listening.
                aDuplexInputChannel.StartListening();

                // Allow some time for pinging.
                aDuplexOutputChannel.OpenConnection();
                Thread.Sleep(2000);

                Assert.IsFalse(aDisconnectedFlag);

                // Disconnect the duplex output channel.
                aDuplexInputChannel.DisconnectResponseReceiver(aDuplexOutputChannel.ResponseReceiverId);

                aDisconnectedEvent.WaitOne();

                Assert.IsTrue(aDisconnectedFlag);
                Assert.IsFalse(aDuplexOutputChannel.IsConnected);
            }
            finally
            {
                aDuplexOutputChannel.CloseConnection();
                aDuplexInputChannel.StopListening();
            }
        }
        public void B04_Pinging_CloseConnection()
        {
            IDuplexInputChannel aDuplexInputChannel = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);

            IDuplexOutputChannel aDuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            AutoResetEvent aConnectionClosedEvent    = new AutoResetEvent(false);
            string         aClosedResponseReceiverId = "";

            aDuplexInputChannel.ResponseReceiverDisconnected += (x, y) =>
            {
                aClosedResponseReceiverId = y.ResponseReceiverId;
                aConnectionClosedEvent.Set();
            };

            try
            {
                // Start listening.
                aDuplexInputChannel.StartListening();

                // Allow some time for pinging.
                aDuplexOutputChannel.OpenConnection();
                Thread.Sleep(2000);

                Assert.AreEqual("", aClosedResponseReceiverId);

                // Close connection. Therefore the duplex input channel will not get any pings anymore.
                aDuplexOutputChannel.CloseConnection();

                aConnectionClosedEvent.WaitOne();

                Assert.AreEqual(aDuplexOutputChannel.ResponseReceiverId, aClosedResponseReceiverId);
                Assert.IsFalse(aDuplexOutputChannel.IsConnected);
            }
            finally
            {
                aDuplexOutputChannel.CloseConnection();
                aDuplexInputChannel.StopListening();
            }
        }
        public virtual void ConnectionNotGranted()
        {
            IDuplexInputChannel  anInputChannel  = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);
            IDuplexOutputChannel anOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            try
            {
                myConnectionNotGranted = true;

                anInputChannel.StartListening();

                // Client opens the connection.
                Assert.Throws <InvalidOperationException>(() => anOutputChannel.OpenConnection());
            }
            finally
            {
                myConnectionNotGranted = false;

                anOutputChannel.CloseConnection();
                anInputChannel.StopListening();
            }
        }
        public virtual void AuthenticationTimeout()
        {
            IDuplexInputChannel  anInputChannel  = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);
            IDuplexOutputChannel anOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            try
            {
                myAuthenticationSleep = TimeSpan.FromMilliseconds(3000);

                anInputChannel.StartListening();

                // Client opens the connection.
                Assert.Throws <TimeoutException>(() => anOutputChannel.OpenConnection());
            }
            finally
            {
                myAuthenticationSleep = TimeSpan.FromMilliseconds(0);

                anOutputChannel.CloseConnection();
                anInputChannel.StopListening();
            }
        }
        public void TestPortAvailability()
        {
            IDuplexInputChannel anInputChannel1 = MessagingSystemFactory.CreateDuplexInputChannel("udp://[::1]:8045/");
            IDuplexInputChannel anInputChannel2 = MessagingSystemFactory.CreateDuplexInputChannel("udp://127.0.0.1:8045/");

            try
            {
                anInputChannel1.StartListening();
                anInputChannel2.StartListening();

                bool aResult = UdpMessagingSystemFactory.IsPortAvailableForUdpListening("tcp://[::1]:8045/");
                Assert.IsFalse(aResult);

                aResult = UdpMessagingSystemFactory.IsPortAvailableForUdpListening("tcp://0.0.0.0:8046/");
                Assert.IsTrue(aResult);
            }
            finally
            {
                anInputChannel1.StopListening();
                anInputChannel2.StopListening();
            }
        }
        public virtual void AuthenticationCancelledByClient()
        {
            IDuplexInputChannel  anInputChannel  = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);
            IDuplexOutputChannel anOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            try
            {
                myClientCancelAuthentication = true;

                anInputChannel.StartListening();

                Exception anException = null;
                try
                {
                    // Client opens the connection.
                    anOutputChannel.OpenConnection();
                }
                catch (Exception err)
                {
                    anException = err;
                }

                Assert.IsInstanceOf <InvalidOperationException>(anException);

                // Check that the AuthenticationCancelled calleback was called.
                Assert.IsTrue(myAuthenticationCancelled);
            }
            finally
            {
                myClientCancelAuthentication = false;
                myAuthenticationCancelled    = false;

                anOutputChannel.CloseConnection();
                anInputChannel.StopListening();
            }
        }
Ejemplo n.º 9
0
        public void A01_Reconnect_DisconnectReceiver()
        {
            IDuplexInputChannel  aDuplexInputChannel  = MessagingSystemFactory.CreateDuplexInputChannel(ChannelId);
            IDuplexOutputChannel aDuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(ChannelId);

            Reconnecter aReconnecter = new Reconnecter(aDuplexOutputChannel, TimeSpan.FromMilliseconds(300), -1);

            AutoResetEvent         aReconnectEvent     = new AutoResetEvent(false);
            DuplexChannelEventArgs aReconnectEventArgs = null;

            aReconnecter.ConnectionOpened += (x, y) =>
            {
                aReconnectEventArgs = y;
                aReconnectEvent.Set();
            };

            AutoResetEvent         aDisconnectEvent     = new AutoResetEvent(false);
            DuplexChannelEventArgs aDisconnectEventArgs = null;

            aReconnecter.ConnectionClosed += (x, y) =>
            {
                aDisconnectEventArgs = y;
                aDisconnectEvent.Set();
            };


            AutoResetEvent aConnectionOpenedEvent = new AutoResetEvent(false);

            aDuplexOutputChannel.ConnectionOpened += (x, y) =>
            {
                aConnectionOpenedEvent.Set();
            };

            AutoResetEvent aConnectionClosedEvent = new AutoResetEvent(false);

            aDuplexOutputChannel.ConnectionClosed += (x, y) =>
            {
                aConnectionClosedEvent.Set();
            };

            try
            {
                aReconnecter.EnableReconnecting();

                // Start listening.
                aDuplexInputChannel.StartListening();
                aDuplexOutputChannel.OpenConnection();
                Thread.Sleep(2000);

                Assert.IsTrue(aDuplexOutputChannel.IsConnected);
                aConnectionOpenedEvent.WaitOne();

                // Disconnect the duplexoutput channel.
                aDuplexInputChannel.DisconnectResponseReceiver(aDuplexOutputChannel.ResponseReceiverId);

                // Wait until the disconnect is notified.
                aDisconnectEvent.WaitOne();
                aConnectionClosedEvent.WaitOne();

                Assert.AreEqual(aDuplexOutputChannel.ChannelId, aDisconnectEventArgs.ChannelId);
                Assert.AreEqual(aDuplexOutputChannel.ResponseReceiverId, aDisconnectEventArgs.ResponseReceiverId);

                // Wait until the reconnecter opens connection again.
                aReconnectEvent.WaitOne();
                Assert.AreEqual(aDuplexOutputChannel.ChannelId, aReconnectEventArgs.ChannelId);
                Assert.AreEqual(aDuplexOutputChannel.ResponseReceiverId, aReconnectEventArgs.ResponseReceiverId);

                Assert.IsTrue(aDuplexOutputChannel.IsConnected);

                aConnectionOpenedEvent.WaitOne();
            }
            finally
            {
                aReconnecter.DisableReconnecting();
                aDuplexOutputChannel.CloseConnection();
                aDuplexInputChannel.StopListening();
            }
        }