StartProcessing() public method

public StartProcessing ( ) : void
return void
Exemplo n.º 1
0
        public void EndpointInterfaceLifecycleTest()
        {
            // Host
            var host = new Mock <IApplicationHost>();

            // Endpoint to test
            TcpReceiveEndpoint receiveEndpoint = new TcpReceiveEndpoint();

            receiveEndpoint.Initialize(host.Object, new TcpReceieveOptions()
            {
                Endpoint = new IPEndPoint(IPAddress.Any, 6799), NoDelay = true, ReceiveBufferSize = 8192
            });
            receiveEndpoint.StartProcessing();

            // Try connection two clients and process messages

            Stopwatch watch = new Stopwatch();

            watch.Start();
            {
                TcpClient client = new TcpClient();
                client.NoDelay = true;
                client.Connect(IPAddress.Loopback, 6799);
                client.GetStream().Write(new byte[] { TcpReceieveOptions.SOH }, 0, 1);

                // Lets try a bit more message .. just for the fun of it ..
                for (int i = 0; i < 100; i++)
                {
                    client.GetStream().Write(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }, 0, 6);
                    receiveEndpoint.WaitForMessage();
                }
                client.GetStream().Write(new byte[] { TcpReceieveOptions.EOT }, 0, 1);
                client.Close();
            }

            //Assert.IsFalse(true, "{0}", watch.ElapsedMilliseconds);

            {
                TcpClient client = new TcpClient();
                client.NoDelay = true;
                client.Connect(IPAddress.Loopback, 6799);
                client.GetStream().Write(new byte[] { TcpReceieveOptions.SOH }, 0, 1);
                client.GetStream().Write(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }, 0, 6);
                receiveEndpoint.WaitForMessage();
                client.GetStream().Write(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }, 0, 6);
                receiveEndpoint.WaitForMessage();
                client.GetStream().Write(new byte[] { TcpReceieveOptions.EOT }, 0, 1);
                client.Close();
            }

            receiveEndpoint.StopProcessing();
            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.IsNotNull <byte[]>()), Times.Exactly(102));
            host.Verify(app => app.ProcessInPipeline(It.IsAny <TcpReceiveEndpoint>(), It.Is <byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
        }
Exemplo n.º 2
0
		public void EndpointInterfaceLifecycleTest()
		{
			// Host
			var host = new Mock<IApplicationHost>();

			// Endpoint to test
			TcpReceiveEndpoint receiveEndpoint = new TcpReceiveEndpoint();

			receiveEndpoint.Initialize(host.Object, new TcpReceieveOptions() { Endpoint = new IPEndPoint(IPAddress.Any, 6799), NoDelay = true, ReceiveBufferSize = 8192 });
			receiveEndpoint.StartProcessing();

			// Try connection two clients and process messages

			Stopwatch watch = new Stopwatch();
			watch.Start();
			{
				TcpClient client = new TcpClient();
				client.NoDelay = true;
				client.Connect(IPAddress.Loopback, 6799);
				client.GetStream().Write(new byte[] { TcpReceieveOptions.SOH }, 0, 1);

				// Lets try a bit more message .. just for the fun of it ..
				for (int i = 0; i < 100; i++)
				{
					client.GetStream().Write(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }, 0, 6);
					receiveEndpoint.WaitForMessage();
				}
				client.GetStream().Write(new byte[] { TcpReceieveOptions.EOT }, 0, 1);
				client.Close();
			}

			//Assert.IsFalse(true, "{0}", watch.ElapsedMilliseconds);

			{
				TcpClient client = new TcpClient();
				client.NoDelay = true;
				client.Connect(IPAddress.Loopback, 6799);
				client.GetStream().Write(new byte[] { TcpReceieveOptions.SOH }, 0, 1);
				client.GetStream().Write(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }, 0, 6);
				receiveEndpoint.WaitForMessage();
				client.GetStream().Write(new byte[] { TcpReceieveOptions.STX, 0x41, 0x41, 0x41, 0x41, TcpReceieveOptions.ETX }, 0, 6);
				receiveEndpoint.WaitForMessage();
				client.GetStream().Write(new byte[] { TcpReceieveOptions.EOT }, 0, 1);
				client.Close();
			}

			receiveEndpoint.StopProcessing();
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.IsNotNull<byte[]>()), Times.Exactly(102));
			host.Verify(app => app.ProcessInPipeline(It.IsAny<TcpReceiveEndpoint>(), It.Is<byte[]>(indata => indata.SequenceEqual(new byte[] { 0x41, 0x41, 0x41, 0x41 }))));
		}