Beispiel #1
0
        public async void TestOrder()
        {
            Peer           sender = null;
            Peer           recv1  = null;
            ChannelCreator cc     = null;

            try
            {
                sender = new PeerBuilder(new Number160("0x50"))
                         .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                         .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(2525, 2525))
                         .SetP2PId(55)
                         .SetPorts(2525)
                         .Start();
                recv1 = new PeerBuilder(new Number160("0x20"))
                        .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                        .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(9099, 9099))
                        .SetP2PId(55)
                        .SetPorts(8088)
                        .Start();
                recv1.RawDataReply(new TestOrderRawDataReply());

                for (int i = 0; i < 500; i++)
                {
                    cc = await sender.ConnectionBean.Reservation.CreateAsync(0, 1);

                    var sendDirectBuilder = new SendDirectBuilder(sender, (PeerAddress)null);
                    var buffer            = AlternativeCompositeByteBuf.CompBuffer().WriteInt(i);
                    sendDirectBuilder.SetBuffer(new Buffer(buffer));
                    sendDirectBuilder.SetIsStreaming();

                    var tr = sender.DirectDataRpc.SendAsync(recv1.PeerAddress, sendDirectBuilder, cc);
                    Core.Utils.Utils.AddReleaseListener(cc, tr);
                    tr.ContinueWith(t =>
                    {
                        int j = t.Result.Buffer(0).BackingBuffer.ReadInt();
                        Console.WriteLine("Received {0}.", j);
                    });
                }
            }
            finally
            {
                if (sender != null)
                {
                    sender.ShutdownAsync().Wait();
                }
                if (recv1 != null)
                {
                    recv1.ShutdownAsync().Wait();
                }
                if (cc != null)
                {
                    cc.ShutdownAsync().Wait();
                }
            }
        }
Beispiel #2
0
        public async void TestDirect1()
        {
            Peer           sender = null;
            Peer           recv1  = null;
            ChannelCreator cc     = null;

            try
            {
                sender = new PeerBuilder(new Number160("0x50"))
                         .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                         .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(2525, 2525))
                         .SetP2PId(55)
                         .SetPorts(2525)
                         .Start();
                recv1 = new PeerBuilder(new Number160("0x20"))
                        .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                        .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(9099, 9099))
                        .SetP2PId(55)
                        .SetPorts(8088)
                        .Start();
                recv1.RawDataReply(new TestRawDataReply());

                cc = await sender.ConnectionBean.Reservation.CreateAsync(0, 1);

                var sendDirectBuilder = new SendDirectBuilder(sender, (PeerAddress)null);
                sendDirectBuilder.SetIsStreaming();
                sendDirectBuilder.SetIdleTcpSeconds(Int32.MaxValue);
                var buffer = CreateTestBuffer();
                sendDirectBuilder.SetBuffer(buffer);

                var   tr1 = sender.DirectDataRpc.SendAsync(recv1.PeerAddress, sendDirectBuilder, cc);
                await tr1;
                Assert.IsTrue(!tr1.IsFaulted);

                var ret = tr1.Result.Buffer(0);
                Assert.AreEqual(buffer, ret);
            }
            finally
            {
                if (sender != null)
                {
                    sender.ShutdownAsync().Wait();
                }
                if (recv1 != null)
                {
                    recv1.ShutdownAsync().Wait();
                }
                if (cc != null)
                {
                    cc.ShutdownAsync().Wait();
                }
            }
        }
Beispiel #3
0
        public async void TestDirect1()
        {
            Peer sender = null;
            Peer recv1 = null;
            ChannelCreator cc = null;
            try
            {
                sender = new PeerBuilder(new Number160("0x50"))
                    .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                    .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(2525, 2525))
                    .SetP2PId(55)
                    .SetPorts(2525)
                    .Start();
                recv1 = new PeerBuilder(new Number160("0x20"))
                    .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                    .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(9099, 9099))
                    .SetP2PId(55)
                    .SetPorts(8088)
                    .Start();
                recv1.RawDataReply(new TestRawDataReply());

                cc = await sender.ConnectionBean.Reservation.CreateAsync(0, 1);

                var sendDirectBuilder = new SendDirectBuilder(sender, (PeerAddress) null);
                sendDirectBuilder.SetIsStreaming();
                sendDirectBuilder.SetIdleTcpSeconds(Int32.MaxValue);
                var buffer = CreateTestBuffer();
                sendDirectBuilder.SetBuffer(buffer);

                var tr1 = sender.DirectDataRpc.SendAsync(recv1.PeerAddress, sendDirectBuilder, cc);
                await tr1;
                Assert.IsTrue(!tr1.IsFaulted);

                var ret = tr1.Result.Buffer(0);
                Assert.AreEqual(buffer, ret);
            }
            finally
            {
                if (sender != null)
                {
                    sender.ShutdownAsync().Wait();
                }
                if (recv1 != null)
                {
                    recv1.ShutdownAsync().Wait();
                }
                if (cc != null)
                {
                    cc.ShutdownAsync().Wait();
                }
            }
        }
Beispiel #4
0
        public async void TestOrder()
        {
            Peer sender = null;
            Peer recv1 = null;
            ChannelCreator cc = null;
            try
            {
                sender = new PeerBuilder(new Number160("0x50"))
                    .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                    .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(2525, 2525))
                    .SetP2PId(55)
                    .SetPorts(2525)
                    .Start();
                recv1 = new PeerBuilder(new Number160("0x20"))
                    .SetMaintenanceTask(Utils2.CreateInfiniteIntervalMaintenanceTask())
                    .SetChannelServerConfiguration(Utils2.CreateInfiniteTimeoutChannelServerConfiguration(9099, 9099))
                    .SetP2PId(55)
                    .SetPorts(8088)
                    .Start();
                recv1.RawDataReply(new TestOrderRawDataReply());

                for (int i = 0; i < 500; i++)
                {
                    cc = await sender.ConnectionBean.Reservation.CreateAsync(0, 1);

                    var sendDirectBuilder = new SendDirectBuilder(sender, (PeerAddress) null);
                    var buffer = AlternativeCompositeByteBuf.CompBuffer().WriteInt(i);
                    sendDirectBuilder.SetBuffer(new Buffer(buffer));
                    sendDirectBuilder.SetIsStreaming();

                    var tr = sender.DirectDataRpc.SendAsync(recv1.PeerAddress, sendDirectBuilder, cc);
                    Core.Utils.Utils.AddReleaseListener(cc, tr);
                    tr.ContinueWith(t =>
                    {
                        int j = t.Result.Buffer(0).BackingBuffer.ReadInt();
                        Console.WriteLine("Received {0}.", j);
                    });
                }
            }
            finally
            {
                if (sender != null)
                {
                    sender.ShutdownAsync().Wait();
                }
                if (recv1 != null)
                {
                    recv1.ShutdownAsync().Wait();
                }
                if (cc != null)
                {
                    cc.ShutdownAsync().Wait();
                }
            }
        }