Example #1
0
 public void 到達保証なしチャンネルオーダー受信テスト()
 {
     for (int i = 0; i < 100; i++)
     {
         var ctx    = new TestChannelContext();
         var config = new UnreliableChannelConfig
         {
             Ordered = true,
         };
         using (var control = new UnreliableFlowControl(1, 1, ctx, config))
         {
             List <byte[]> buf = new List <byte[]>();
             short         id  = 1;
             for (int j = 0; j < 200; j++)
             {
                 buf.Add(GetRandam(Fragment.Size - 100 + j));
                 control.Send(GetFragments(buf[j], id++, Fragment.Size));
             }
             ctx.ShuffleSentQueue();
             int prev = -1;
             while (ctx.Receive(control, out var output))
             {
                 var ret = output.ToBytes();
                 Assert.IsTrue(prev < ret.Length);
                 prev = ret.Length;
                 output.RemoveRef(true);
             }
         }
     }
 }
Example #2
0
        public void 到達保証なしチャンネルランダム受信テスト()
        {
            var ctx = new TestChannelContext();

            using (var control = new UnreliableFlowControl(1, 1, ctx))
            {
                List <byte[]> buf = new List <byte[]>();
                short         id  = 1;
                for (int i = 0; i < 10; i++)
                {
                    buf.Add(GetRandam(2000));
                    control.Send(GetFragments(buf[i], id++, Fragment.Size));
                }
                ctx.ShuffleSentQueue();
                int count = 0;
                while (ctx.Receive(control, out var output))
                {
                    count++;
                    var ret = output.ToBytes();
                    Assert.IsTrue(buf.Any(x => Equals(x, ret)), "指定のデータが含まれている");
                    output.RemoveRef(true);
                }
                Assert.AreEqual(buf.Count, count, "同じ数読み取れている");
            }
        }
Example #3
0
 public void 到達保証ありチャンネルパケロステスト()
 {
     foreach (var ordered in new bool[] { true, false })
     {
         var ctx    = new TestChannelContext();
         var config = new ReliableChannelConfig
         {
             Ordered = ordered
         };
         using (var control = new ReliableFlowControl(1, 1, ctx, config))
         {
             List <byte[]> buf = new List <byte[]>();
             short         id  = 1;
             for (int i = 0; i < 10; i++)
             {
                 buf.Add(GetRandam(200 + i * 100));
                 control.Send(GetFragments(buf[buf.Count - 1], id++, Fragment.Size));
             }
             for (int i = 0; i < 50; i++)
             {
                 buf.Add(GetRandam(2000 + (int)(10000 * m_Random.NextDouble())));
                 control.Send(GetFragments(buf[buf.Count - 1], id++, Fragment.Size));
             }
             ctx.ShuffleSentQueue();
             int count = 0;
             while (count < buf.Count && ctx.Receive(control, out var output, 0.3))
             {
                 ctx.ShuffleSentQueue();
                 var ret = output.ToBytes();
                 if (ordered)
                 {
                     Assert.IsTrue(Equals(buf[count++], ret), "順番に届く");
                 }
                 else
                 {
                     count++;
                 }
                 output.RemoveRef(true);
             }
             Assert.AreEqual(buf.Count, count, "同じ数読み取れている");
         }
     }
 }