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++; } } }
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); }
public void TestImmediateComesFirst() { NullTransport t = new NullTransport(); MockConnexion cnx = new MockConnexion(); cnx.Scheduler = new RoundRobinPacketScheduler(cnx); cnx.Transports.Add(t); /// Send a bunch of messages that should be aggregated. /// Then send a message that should go immediately (i.e., sent /// before any of the aggregated messages). for (int i = 1; i < 6; i++) { cnx.Scheduler.Schedule(new ObjectMessage((byte)(i % 2), i), MessageDeliveryRequirements.LeastStrict, null); Assert.AreEqual(0, t.BytesSent); Assert.AreEqual(0, cnx.SentPackets.Count); } cnx.Scheduler.Schedule(new StringMessage(0, "foo"), new MessageDeliveryRequirements(Reliability.Unreliable, MessageAggregation.Immediate, Ordering.Unordered), null); Assert.IsTrue(t.BytesSent > 0); Assert.IsTrue(cnx.SentPackets.Count > 0); int msgNo = 0; foreach (TransportPacket tp in cnx.SentPackets) { if (msgNo == 0) { // Firt message should be the immediate message cnx.Marshaller.Unmarshal(tp, t, delegate(object sender, MessageEventArgs mea) { Assert.IsInstanceOfType(typeof(StringMessage), mea.Message); Assert.AreEqual("foo", ((StringMessage)mea.Message).Text); }); msgNo++; } while(tp.Length > 0) { cnx.Marshaller.Unmarshal(tp, t, delegate(object sender, MessageEventArgs mea) { Assert.AreEqual(msgNo, ((ObjectMessage)mea.Message).Object); Assert.AreEqual(msgNo % 2, ((ObjectMessage)mea.Message).ChannelId); }); msgNo++; } } }
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++; } } }
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); }