Exemplo n.º 1
0
        public void Outgoing_TCP_stream_must_materialize_correctly_when_used_in_multiple_flows()
        {
            var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
            var server   = new Server(this);

            var tcpWriteProbe1     = new TcpWriteProbe(this);
            var tcpReadProbe1      = new TcpReadProbe(this);
            var tcpWriteProbe2     = new TcpWriteProbe(this);
            var tcpReadProbe2      = new TcpReadProbe(this);
            var outgoingConnection = new Tcp().CreateExtension(Sys as ExtendedActorSystem).OutgoingConnection(server.Address);

            var conn1F = Source.FromPublisher(tcpWriteProbe1.PublisherProbe)
                         .ViaMaterialized(outgoingConnection, Keep.Both)
                         .To(Sink.FromSubscriber(tcpReadProbe1.SubscriberProbe))
                         .Run(Materializer).Item2;
            var serverConnection1 = server.WaitAccept();
            var conn2F            = Source.FromPublisher(tcpWriteProbe2.PublisherProbe)
                                    .ViaMaterialized(outgoingConnection, Keep.Both)
                                    .To(Sink.FromSubscriber(tcpReadProbe2.SubscriberProbe))
                                    .Run(Materializer).Item2;
            var serverConnection2 = server.WaitAccept();

            ValidateServerClientCommunication(testData, serverConnection1, tcpReadProbe1, tcpWriteProbe1);
            ValidateServerClientCommunication(testData, serverConnection2, tcpReadProbe2, tcpWriteProbe2);

            conn1F.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
            conn2F.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
            var conn1 = conn1F.Result;
            var conn2 = conn2F.Result;

            // Since we have already communicated over the connections we can have short timeouts for the tasks
            ((IPEndPoint)conn1.RemoteAddress).Port.Should().Be(((IPEndPoint)server.Address).Port);
            ((IPEndPoint)conn2.RemoteAddress).Port.Should().Be(((IPEndPoint)server.Address).Port);
            ((IPEndPoint)conn1.LocalAddress).Port.Should().NotBe(((IPEndPoint)conn2.LocalAddress).Port);

            tcpWriteProbe1.Close();
            tcpReadProbe1.Close();

            server.Close();
        }
Exemplo n.º 2
0
        public void Outgoing_TCP_stream_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 });

                var server = new Server(this);

                var tcpReadProbe  = new TcpReadProbe(this);
                var tcpWriteProbe = new TcpWriteProbe(this);
                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                .Run(Materializer);
                var serverConnection = server.WaitAccept();

                ValidateServerClientCommunication(testData, serverConnection, tcpReadProbe, tcpWriteProbe);

                tcpWriteProbe.Close();
                tcpReadProbe.Close();
                server.Close();
            }, Materializer);
        }
Exemplo n.º 3
0
        public void Outgoing_TCP_stream_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] {1, 2, 3, 4, 5});

                var server = new Server(this);

                var tcpReadProbe = new TcpReadProbe(this);
                var tcpWriteProbe = new TcpWriteProbe(this);
                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                    .Run(Materializer);
                var serverConnection = server.WaitAccept();

                ValidateServerClientCommunication(testData, serverConnection, tcpReadProbe, tcpWriteProbe);

                tcpWriteProbe.Close();
                tcpReadProbe.Close();
                server.Close();
            }, Materializer);
        }
Exemplo n.º 4
0
        public void Outgoing_TCP_stream_must_materialize_correctly_when_used_in_multiple_flows()
        {
            var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
            var server = new Server(this);

            var tcpWriteProbe1 = new TcpWriteProbe(this);
            var tcpReadProbe1 = new TcpReadProbe(this);
            var tcpWriteProbe2 = new TcpWriteProbe(this);
            var tcpReadProbe2 = new TcpReadProbe(this);
            var outgoingConnection = new Tcp().CreateExtension(Sys as ExtendedActorSystem).OutgoingConnection(server.Address);

            var conn1F = Source.FromPublisher(tcpWriteProbe1.PublisherProbe)
                    .ViaMaterialized(outgoingConnection, Keep.Both)
                    .To(Sink.FromSubscriber(tcpReadProbe1.SubscriberProbe))
                    .Run(Materializer).Item2;
            var serverConnection1 = server.WaitAccept();
            var conn2F = Source.FromPublisher(tcpWriteProbe2.PublisherProbe)
                    .ViaMaterialized(outgoingConnection, Keep.Both)
                    .To(Sink.FromSubscriber(tcpReadProbe2.SubscriberProbe))
                    .Run(Materializer).Item2;
            var serverConnection2 = server.WaitAccept();

            ValidateServerClientCommunication(testData, serverConnection1, tcpReadProbe1, tcpWriteProbe1);
            ValidateServerClientCommunication(testData, serverConnection2, tcpReadProbe2, tcpWriteProbe2);

            conn1F.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
            conn2F.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
            var conn1 = conn1F.Result;
            var conn2 = conn2F.Result;

            // Since we have already communicated over the connections we can have short timeouts for the tasks
            ((IPEndPoint) conn1.RemoteAddress).Port.Should().Be(((IPEndPoint) server.Address).Port);
            ((IPEndPoint) conn2.RemoteAddress).Port.Should().Be(((IPEndPoint) server.Address).Port);
            ((IPEndPoint) conn1.LocalAddress).Port.Should().NotBe(((IPEndPoint) conn2.LocalAddress).Port);

            tcpWriteProbe1.Close();
            tcpReadProbe1.Close();

            server.Close();
        }