示例#1
0
        public void TestAck2()
        {
            SocketMessage package1 = new SocketMessage(Config.Default.PackageSize);

            package1.SetSeq(0);
            SocketMessage package2 = new SocketMessage(Config.Default.PackageSize);

            package2.SetSeq(1);
            SocketMessage package3 = new SocketMessage(Config.Default.PackageSize);

            package3.SetSeq(2);

            CongestionRecorder ackWaiter = new CongestionRecorder(3);
            PackageRectifier   rectifier = new PackageRectifier();

            ackWaiter.PushWait(package1, 1);
            ackWaiter.PushWait(package2, 2);
            ackWaiter.PushWait(package3, 3);

            rectifier.PushPackage(package3);
            rectifier.PushPackage(package1);


            ackWaiter.ReplyBefore((ushort)(rectifier.Serial - 1), 1, 1);
            ackWaiter.ReplyAfter((ushort)(rectifier.Serial - 1), rectifier.SerialBitFields, 1, 1);

            Assert.Equal(1, ackWaiter.Count);

            List <SocketMessage> outs = ackWaiter.PopLost(Timestamp.OneSecondTicks * 60, Timestamp.OneSecondTicks * 60);

            Assert.Equal(1, outs[0].GetSeq());
        }
示例#2
0
        public void TestPackageRectifierOutOfOrder()
        {
            SocketMessage package1 = new SocketMessage(Config.Default.PackageSize);

            package1.SetSeq(0);
            package1.WritePayload(new byte[] { 1 }, 0, 1);

            SocketMessage package2 = new SocketMessage(Config.Default.PackageSize);

            package2.SetSeq(1);
            package2.WritePayload(new byte[] { 5 }, 0, 1);

            SocketMessage package3 = new SocketMessage(Config.Default.PackageSize);

            package3.SetSeq(2);
            package3.WritePayload(new byte[] { 9 }, 0, 1);


            PackageRectifier receiver = new PackageRectifier();

            receiver.PushPackage(package3);

            SocketMessage stream1 = receiver.PopPackage();

            Assert.Equal(null, stream1);

            receiver.PushPackage(package2);


            SocketMessage stream2 = receiver.PopPackage();

            Assert.Equal(null, stream2);


            receiver.PushPackage(package1);

            Assert.Equal((byte)1, receiver.PopPackage().ReadPayload(0));
            Assert.Equal((byte)5, receiver.PopPackage().ReadPayload(0));
            Assert.Equal((byte)9, receiver.PopPackage().ReadPayload(0));
        }
示例#3
0
        public void TestPackageRectifierRepeat()
        {
            var package1 = new SocketMessage(Config.Default.PackageSize);

            package1.SetSeq(0);
            package1.WritePayload(new byte[] { 1 }, 0, 1);

            var package2 = new SocketMessage(Config.Default.PackageSize);

            package2.SetSeq(1);
            package2.WritePayload(new byte[] { 5 }, 0, 1);

            var package3 = new SocketMessage(Config.Default.PackageSize);

            package3.SetSeq(2);
            package3.WritePayload(new byte[] { 9 }, 0, 1);

            var package4 = new SocketMessage(Config.Default.PackageSize);

            package4.SetSeq(3);
            package4.WritePayload(new byte[] { 10 }, 0, 1);

            var package5 = new SocketMessage(Config.Default.PackageSize);

            package5.SetSeq(4);
            package5.WritePayload(new byte[] { 11 }, 0, 1);


            var receiver = new PackageRectifier();

            receiver.PushPackage(package3);


            var stream1 = receiver.PopPackage();

            Assert.AreEqual(null, stream1);

            receiver.PushPackage(package2);
            var stream2 = receiver.PopPackage();

            Assert.AreEqual(null, stream2);

            receiver.PushPackage(package1);


            Assert.AreEqual((byte)1, receiver.PopPackage().ReadPayload(0));
            Assert.AreEqual((byte)5, receiver.PopPackage().ReadPayload(0));
            Assert.AreEqual((byte)9, receiver.PopPackage().ReadPayload(0));


            receiver.PushPackage(package5);
            var stream4 = receiver.PopPackage();

            Assert.AreEqual(null, stream4);

            receiver.PushPackage(package2);
            var stream5 = receiver.PopPackage();

            Assert.AreEqual(null, stream5);

            receiver.PushPackage(package4);

            Assert.AreEqual((byte)10, receiver.PopPackage().ReadPayload(0));
            Assert.AreEqual((byte)11, receiver.PopPackage().ReadPayload(0));
        }