public async Task DotNettyTcpTransport_should_cleanly_terminate_endpoints_upon_failed_outbound_connection() { var config = Sys.Settings.Config.GetConfig("akka.remote.dot-netty.tcp"); Assert.False(config.IsNullOrEmpty()); var t1 = new TcpTransport(Sys, config); try { var p1 = CreateTestProbe(); // bind var c1 = await t1.Listen(); c1.Item2.SetResult(new ActorAssociationEventListener(p1)); // t1 --> t2 association await Assert.ThrowsAsync <InvalidAssociationException>(async() => { var a = await t1.Associate(c1.Item1.WithPort(c1.Item1.Port + 100)); }); AwaitCondition(() => t1.ConnectionGroup.Count == 1); } finally { await t1.Shutdown(); } }
public async Task DotNettyTcpTransport_should_cleanly_terminate_active_endpoints_upon_outbound_disassociate() { var config = Sys.Settings.Config.GetConfig("akka.remote.dot-netty.tcp"); Assert.False(config.IsNullOrEmpty()); var t1 = new TcpTransport(Sys, config); var t2 = new TcpTransport(Sys, config); try { var p1 = CreateTestProbe(); var p2 = CreateTestProbe(); // bind var c1 = await t1.Listen(); c1.Item2.SetResult(new ActorAssociationEventListener(p1)); var c2 = await t2.Listen(); c2.Item2.SetResult(new ActorAssociationEventListener(p2)); // t1 --> t2 association var handle = await t1.Associate(c2.Item1); handle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p1)); var inboundHandle = p2.ExpectMsg <InboundAssociation>().Association; // wait for the inbound association handle to show up inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(p2)); AwaitCondition(() => t1.ConnectionGroup.Count == 2); AwaitCondition(() => t2.ConnectionGroup.Count == 2); var chan1 = t1.ConnectionGroup.Single(x => !x.Id.Equals(t1.ServerChannel.Id)); var chan2 = t2.ConnectionGroup.Single(x => !x.Id.Equals(t2.ServerChannel.Id)); // force a disassociation handle.Disassociate(); // verify that the connections are terminated p1.ExpectMsg <Disassociated>(); AwaitCondition(() => t1.ConnectionGroup.Count == 1); AwaitCondition(() => t2.ConnectionGroup.Count == 1); // verify that the connection channels were terminated on both ends chan1.CloseCompletion.IsCompleted.Should().BeTrue(); chan2.CloseCompletion.IsCompleted.Should().BeTrue(); } finally { await t1.Shutdown(); await t2.Shutdown(); } }