public async void TestPingTimeoutUdp() { 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(1, 0); var tr = handshake1.PingUdpAsync(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 TestPingUdpToJava() { // 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(1, 0); var handshake = new PingRpc(sender.PeerBean, sender.ConnectionBean); var task = handshake.PingUdpAsync(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 TestPingUdpToJava() { // 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(1, 0); var handshake = new PingRpc(sender.PeerBean, sender.ConnectionBean); var task = handshake.PingUdpAsync(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 TestPingUdp() { 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 handshake = new PingRpc(sender.PeerBean, sender.ConnectionBean); cc = await recv1.ConnectionBean.Reservation.CreateAsync(1, 0); var t = handshake.PingUdpAsync(recv1.PeerAddress, cc, new DefaultConnectionConfiguration()); await t; Assert.IsTrue(t.IsCompleted && !t.IsFaulted); } catch (Exception ex) { throw ex; } finally { if (cc != null) { cc.ShutdownAsync().Wait(); } if (sender != null) { sender.ShutdownAsync().Wait(); } if (recv1 != null) { recv1.ShutdownAsync().Wait(); } } }