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); }
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); }
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); }
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); }
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); }
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); }
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); }