Esempio n. 1
0
        public void TestOrder()
        {
            NullTransport t = new NullTransport();
            MockConnexion cnx = new MockConnexion();
            cnx.Scheduler = new ImmediatePacketScheduler(cnx);
            cnx.Transports.Add(t);

            uint lastBytesSent = 0;
            for (int i = 0; i < 6; i++)
            {
                cnx.Scheduler.Schedule(new ObjectMessage(0, i), MessageDeliveryRequirements.LeastStrict, null);
                Assert.IsTrue(lastBytesSent < t.BytesSent);
                lastBytesSent = t.BytesSent;
            }
            cnx.Flush();
            Assert.IsTrue(t.BytesSent == lastBytesSent, "Flush() should have made no difference to bytes sent");

            // check order
            int msgNo = 0;
            foreach (TransportPacket tp in cnx.SentPackets)
            {
                while (tp.Length > 0)
                {
                    cnx.Marshaller.Unmarshal(tp, t, delegate(object sender, MessageEventArgs mea) {
                        Assert.AreEqual(msgNo, ((ObjectMessage)mea.Message).Object,
                            "message was sent out of order!");
                    });
                    msgNo++;
                }
            }
        }
Esempio n. 2
0
        public void TestAggregationSendsNothingUntilFlush()
        {
            NullTransport t = new NullTransport();
            MockConnexion cnx = new MockConnexion();
            cnx.Scheduler = new RoundRobinPacketScheduler(cnx);
            cnx.Transports.Add(t);

            for (int i = 0; i < 6; i++)
            {
                cnx.Scheduler.Schedule(new ObjectMessage(0, i), MessageDeliveryRequirements.LeastStrict, null);
                Assert.AreEqual(0, t.BytesSent);
                Assert.AreEqual(0, cnx.SentPackets.Count);
            }
            cnx.Flush();
            Assert.IsTrue(t.BytesSent > 0);
            Assert.IsTrue(cnx.SentPackets.Count > 0);
        }
Esempio n. 3
0
        public void TestSendsOnSameChannelInOrder()
        {
            NullTransport t = new NullTransport();
            MockConnexion cnx = new MockConnexion();
            cnx.Scheduler = new RoundRobinPacketScheduler(cnx);
            cnx.Transports.Add(t);

            for (int i = 0; i < 6; i++)
            {
                cnx.Scheduler.Schedule(new ObjectMessage(0, i), MessageDeliveryRequirements.LeastStrict, null);
                Assert.AreEqual(0, t.BytesSent);
                Assert.AreEqual(0, cnx.SentPackets.Count);
            }
            cnx.Flush();
            Assert.IsTrue(t.BytesSent > 0);
            Assert.IsTrue(cnx.SentPackets.Count > 0);

            int msgNo = 0;
            foreach (TransportPacket tp in cnx.SentPackets)
            {
                while (tp.Length > 0)
                {
                    cnx.Marshaller.Unmarshal(tp, t, delegate(object sender, MessageEventArgs mea)
                    {
                        Assert.AreEqual(msgNo, ((ObjectMessage)mea.Message).Object);
                    });
                    msgNo++;
                }
            }
        }
Esempio n. 4
0
        public void TestSendFragmentedPacket()
        {
            NullTransport t = new NullTransport();
            t.MaximumPacketSize = 100;
            t.Reliability = Reliability.Reliable;
            t.Ordering = Ordering.Ordered;
            MockConnexion cnx = new MockConnexion();
            cnx.Marshaller = new LargeObjectMarshaller(new DotNetSerializingMarshaller());
            cnx.Scheduler = new RoundRobinPacketScheduler(cnx);
            cnx.Transports.Add(t);

            cnx.ErrorEvents += delegate(ErrorSummary es) { Assert.Fail(es.ToString()); };

            byte[] sentData = new byte[500];
            for (int i = 0; i < 6; i++)
            {
                uint bytesSent = t.BytesSent;
                cnx.Scheduler.Schedule(new BinaryMessage(0, sentData), MessageDeliveryRequirements.MostStrict, null);
                Assert.IsTrue(cnx.SentPackets.Count > 0);
                Assert.IsTrue(t.BytesSent - bytesSent > 500); // should be 500 + message headers
            }
            int lastSentPacketsCount = cnx.SentPackets.Count;
            cnx.Flush();
            Assert.IsTrue(cnx.SentPackets.Count == lastSentPacketsCount, "there should not be any data remaining");

            int msgNo = 0;
            foreach (TransportPacket tp in cnx.SentPackets)
            {
                while (tp.Length > 0)
                {
                    cnx.Marshaller.Unmarshal(tp, t, delegate(object sender, MessageEventArgs mea)
                    {
                        Assert.IsInstanceOfType(typeof(BinaryMessage), mea.Message);
                        Assert.AreEqual(sentData, ((BinaryMessage)mea.Message).Bytes);
                        msgNo++;
                    });
                }
            }
            Assert.AreEqual(6, msgNo);
        }