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