public async void TestPingTimeoutTcp() { Peer sender = null; Peer recv1 = null; ChannelCreator cc = null; try { sender = new PeerBuilder(new Number160("0x9876")) .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask()) .SetP2PId(55) .SetPorts(2424) .Start(); recv1 = new PeerBuilder(new Number160("0x1234")) .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask()) .SetP2PId(55) .SetPorts(8088) .Start(); var handshake1 = new PingRpc(sender.PeerBean, sender.ConnectionBean, false, true, true); var handshake2 = new PingRpc(recv1.PeerBean, recv1.ConnectionBean, false, true, true); cc = await recv1.ConnectionBean.Reservation.CreateAsync(0, 1); var tr = handshake1.PingTcpAsync(recv1.PeerAddress, cc, new DefaultConnectionConfiguration()); try { await tr; Assert.Fail("Timeout should have let task fail."); } catch (Exception) { Assert.IsTrue(tr.IsFaulted); } } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } if (recv1 != null) { recv1.ShutdownAsync().Wait(); } } }
public async void TestPingTcpToJava() { // setup Java server and get it's PeerAddress _tcs = new TaskCompletionSource <PeerAddress>(); ThreadPool.QueueUserWorkItem(delegate { JarRunner.Run("JavaPingReceiver-start", DataReceived); }); PeerAddress server = await _tcs.Task; // ping & test Peer sender = null; ChannelCreator cc = null; try { // setup .NET sender sender = new PeerBuilder(new Number160("0x9876")). SetP2PId(55). SetPorts(2424). Start(); cc = await sender.ConnectionBean.Reservation.CreateAsync(0, 1); var handshake = new PingRpc(sender.PeerBean, sender.ConnectionBean); var task = handshake.PingTcpAsync(server, cc, new DefaultConnectionConfiguration()); var responseMessage = await task; Assert.IsTrue(task.IsCompleted && !task.IsFaulted); Assert.AreEqual(responseMessage.Sender, server); Assert.IsTrue(responseMessage.Type == Message.MessageType.Ok); Assert.IsTrue(responseMessage.Command == Core.Rpc.Rpc.Commands.Ping.GetNr()); } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } JarRunner.WriteToProcess("JavaPingReceiver-stop"); } }
public async void TestPingHandlerError() { Peer sender = null; Peer recv1 = null; ChannelCreator cc = null; try { sender = new PeerBuilder(new Number160("0x9876")) .SetP2PId(55) .SetPorts(2424) .Start(); recv1 = new PeerBuilder(new Number160("0x1234")) .SetP2PId(55) .SetPorts(8088) .Start(); var handshake1 = new PingRpc(sender.PeerBean, sender.ConnectionBean, false, true, false); var handshake2 = new PingRpc(recv1.PeerBean, recv1.ConnectionBean, false, true, false); cc = await recv1.ConnectionBean.Reservation.CreateAsync(0, 1); var tr = handshake1.PingTcpAsync(recv1.PeerAddress, cc, new DefaultConnectionConfiguration()); await tr; Assert.IsTrue(tr.IsFaulted); } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } if (recv1 != null) { recv1.ShutdownAsync().Wait(); } } }
public async void TestPingTimeoutTcp() { Peer sender = null; Peer recv1 = null; ChannelCreator cc = null; try { sender = new PeerBuilder(new Number160("0x9876")) .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask()) .SetP2PId(55) .SetPorts(2424) .Start(); recv1 = new PeerBuilder(new Number160("0x1234")) .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask()) .SetP2PId(55) .SetPorts(8088) .Start(); var handshake1 = new PingRpc(sender.PeerBean, sender.ConnectionBean, false, true, true); var handshake2 = new PingRpc(recv1.PeerBean, recv1.ConnectionBean, false, true, true); cc = await recv1.ConnectionBean.Reservation.CreateAsync(0, 1); var tr = handshake1.PingTcpAsync(recv1.PeerAddress, cc, new DefaultConnectionConfiguration()); try { await tr; Assert.Fail("Timeout should have let task fail."); } catch (Exception) { Assert.IsTrue(tr.IsFaulted); } } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } if (recv1 != null) { recv1.ShutdownAsync().Wait(); } } }
public async void TestPingHandlerError() { Peer sender = null; Peer recv1 = null; ChannelCreator cc = null; try { sender = new PeerBuilder(new Number160("0x9876")) .SetP2PId(55) .SetPorts(2424) .Start(); recv1 = new PeerBuilder(new Number160("0x1234")) .SetP2PId(55) .SetPorts(8088) .Start(); var handshake1 = new PingRpc(sender.PeerBean, sender.ConnectionBean, false, true, false); var handshake2 = new PingRpc(recv1.PeerBean, recv1.ConnectionBean, false, true, false); cc = await recv1.ConnectionBean.Reservation.CreateAsync(0, 1); var tr = handshake1.PingTcpAsync(recv1.PeerAddress, cc, new DefaultConnectionConfiguration()); await tr; Assert.IsTrue(tr.IsFaulted); } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } if (recv1 != null) { recv1.ShutdownAsync().Wait(); } } }
public async void TestPingTcpToJava() { // setup Java server and get it's PeerAddress _tcs = new TaskCompletionSource<PeerAddress>(); ThreadPool.QueueUserWorkItem(delegate { JarRunner.Run("JavaPingReceiver-start", DataReceived); }); PeerAddress server = await _tcs.Task; // ping & test Peer sender = null; ChannelCreator cc = null; try { // setup .NET sender sender = new PeerBuilder(new Number160("0x9876")). SetP2PId(55). SetPorts(2424). Start(); cc = await sender.ConnectionBean.Reservation.CreateAsync(0, 1); var handshake = new PingRpc(sender.PeerBean, sender.ConnectionBean); var task = handshake.PingTcpAsync(server, cc, new DefaultConnectionConfiguration()); var responseMessage = await task; Assert.IsTrue(task.IsCompleted && !task.IsFaulted); Assert.AreEqual(responseMessage.Sender, server); Assert.IsTrue(responseMessage.Type == Message.MessageType.Ok); Assert.IsTrue(responseMessage.Command == Core.Rpc.Rpc.Commands.Ping.GetNr()); } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } JarRunner.WriteToProcess("JavaPingReceiver-stop"); } }