Beispiel #1
0
        public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_server_closes_write_then_client_closes_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 });
                var server   = new Server(this);

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

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close client side read
                tcpReadProbe.TcpReadSubscription.Value.Cancel();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                serverConnection.ConfirmedClose();

                // Close client side write
                tcpWriteProbe.Close();
                serverConnection.ExpectClosed(Akka.IO.Tcp.ConfirmedClosed.Instance);
                serverConnection.ExpectTerminated();
            }, Materializer);
        }
Beispiel #2
0
        public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error_after_remote_has_closed_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 });
                var server   = new Server(this);

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

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close remote side write
                serverConnection.ConfirmedClose();
                tcpReadProbe.SubscriberProbe.ExpectComplete();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                tcpWriteProbe.TcpWriteSubscription.Value.SendError(new IllegalStateException("test"));
                serverConnection.ExpectClosed(c => c.IsErrorClosed);
                serverConnection.ExpectTerminated();
            }, Materializer);
        }
Beispiel #3
0
 private void ValidateServerClientCommunication(ByteString testData, ServerConnection serverConnection, TcpReadProbe readProbe, TcpWriteProbe writeProbe)
 {
     serverConnection.Write(testData);
     serverConnection.Read(5);
     readProbe.Read(5).ShouldBeEquivalentTo(testData);
     writeProbe.Write(testData);
     serverConnection.WaitRead().ShouldBeEquivalentTo(testData);
 }
Beispiel #4
0
        public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_closes_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.FromBytes(new byte[] { 1, 2, 3, 4, 5 });
                var server   = new Server(this);

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

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close client side read
                tcpReadProbe.TcpReadSubscription.Value.Cancel();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                // Close client side write
                tcpWriteProbe.Close();

                // Need a write on the server side to detect the close event
                AwaitAssert(() =>
                {
                    serverConnection.Write(testData);
                    serverConnection.ExpectClosed(c => c.IsErrorClosed, TimeSpan.FromMilliseconds(500));
                }, TimeSpan.FromSeconds(5));

                serverConnection.ExpectTerminated();
            }, Materializer);
        }
Beispiel #5
0
        public void Outgoing_TCP_stream_must_work_when_client_closes_write_then_remote_closes_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
                var server = new Server(this);

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

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                // Close client side write
                tcpWriteProbe.Close();
                serverConnection.ExpectClosed(Akka.IO.Tcp.PeerClosed.Instance);

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close server side write
                serverConnection.ConfirmedClose();
                tcpReadProbe.SubscriberProbe.ExpectComplete();

                serverConnection.ExpectClosed(Akka.IO.Tcp.ConfirmedClosed.Instance);
                serverConnection.ExpectTerminated();
            }, Materializer);
        }
Beispiel #6
0
 private void ValidateServerClientCommunication(ByteString testData, ServerConnection serverConnection, TcpReadProbe readProbe, TcpWriteProbe writeProbe)
 {
     serverConnection.Write(testData);
     serverConnection.Read(5);
     readProbe.Read(5).ShouldBeEquivalentTo(testData);
     writeProbe.Write(testData);
     serverConnection.WaitRead().ShouldBeEquivalentTo(testData);
 }
Beispiel #7
0
        public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error_after_remote_has_closed_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
                var server = new Server(this);

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

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close remote side write
                serverConnection.ConfirmedClose();
                tcpReadProbe.SubscriberProbe.ExpectComplete();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);
                
                tcpWriteProbe.TcpWriteSubscription.Value.SendError(new IllegalStateException("test"));
                serverConnection.ExpectClosed(c => c.IsErrorClosed);
                serverConnection.ExpectTerminated();
            }, Materializer);
        }
Beispiel #8
0
        public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_closes_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
                var server = new Server(this);

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

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close client side read
                tcpReadProbe.TcpReadSubscription.Value.Cancel();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                // Close client side write
                tcpWriteProbe.Close();

                // Need a write on the server side to detect the close event
                AwaitAssert(() =>
                {
                    serverConnection.Write(testData);
                    serverConnection.ExpectClosed(c=>c.IsErrorClosed, TimeSpan.FromMilliseconds(500));
                }, TimeSpan.FromSeconds(5));

                serverConnection.ExpectTerminated();
            }, Materializer);
        }