public void ThrowsIfTooManyMessageAreSent() { var time = new Time(); var config = new Config { MaxReliablePacketsInSendBufferPerConnection = 50, SequenceSize = 8 }; var instance = new AckTestInstance { connection = new SubIRawConnection() }; instance.ackSystem = new AckSystem(instance.connection, config, MAX_PACKET_SIZE, time, bufferPool); for (var i = 0; i < 50; i++) { instance.ackSystem.SendReliable(createRandomData(i)); // update to send batch instance.ackSystem.Update(); } var exception = Assert.Throws <InvalidOperationException>(() => { instance.ackSystem.SendReliable(createRandomData(51)); instance.ackSystem.Update(); }); var expected = new InvalidOperationException($"Max packets in send buffer reached for {instance.connection}"); Assert.That(exception, Has.Message.EqualTo(expected.Message)); }
public void SetUp() { var config = new Config(); maxSequence = (ushort)((1 << config.SequenceSize) - 1); instance = new AckTestInstance(); instance.connection = new SubIRawConnection(); instance.ackSystem = new AckSystem(instance.connection, new Config(), new Time(), bufferPool); // create and send n messages instance.messages = new List <byte[]>(); for (int i = 0; i < messageCount; i++) { instance.messages.Add(createRandomData(i + 1)); instance.ackSystem.SendNotify(instance.messages[i]); } // should have got 1 packet Assert.That(instance.connection.packets.Count, Is.EqualTo(messageCount)); // should not have null data Assert.That(instance.connection.packets, Does.Not.Contain(null)); }
public BadSocket(AckTestInstance instance1, AckTestInstance instance2) { ackSystem1 = instance1.ackSystem; ackSystem2 = instance2.ackSystem; connection1 = instance1.connection; connection2 = instance2.connection; }
public void SetUp() { time = new Time(); var config = new Config(); timeout = config.TimeBeforeEmptyAck; instance1 = new AckTestInstance(); instance1.connection = new SubIRawConnection(); instance1.ackSystem = new AckSystem(instance1.connection, config, MAX_PACKET_SIZE, time, bufferPool); instance2 = new AckTestInstance(); instance2.connection = new SubIRawConnection(); instance2.ackSystem = new AckSystem(instance2.connection, config, MAX_PACKET_SIZE, time, bufferPool); badSocket = new BadSocket(instance1, instance2); // create and send n messages instance1.messages = new List <byte[]>(); instance2.messages = new List <byte[]>(); receives1 = new List <byte[]>(); receives2 = new List <byte[]>(); }
public void ThrowIfRingBufferIsfull() { var time = new Time(); var config = new Config { MaxReliablePacketsInSendBufferPerConnection = 500, SequenceSize = 8 }; var instance = new AckTestInstance { connection = new SubIRawConnection() }; instance.ackSystem = new AckSystem(instance.connection, config, time, bufferPool); for (int i = 0; i < 255; i++) { instance.ackSystem.SendReliable(createRandomData(i)); // update to send batch instance.ackSystem.Update(); } InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => { instance.ackSystem.SendReliable(createRandomData(0)); instance.ackSystem.Update(); }); var expected = new InvalidOperationException($"Sent queue is full for {instance.connection}"); Assert.That(exception, Has.Message.EqualTo(expected.Message)); }
public void TearDown() { time = null; badSocket = null; instance1 = null; instance2 = null; receives1 = null; receives2 = null; System.GC.Collect(); }
public void SetUp() { var config = new Config(); maxSequence = (ushort)((1 << config.SequenceSize) - 1); instance1 = new AckTestInstance(); instance1.connection = new SubIRawConnection(); instance1.ackSystem = new AckSystem(instance1.connection, config, new Time(), bufferPool); instance2 = new AckTestInstance(); instance2.connection = new SubIRawConnection(); instance2.ackSystem = new AckSystem(instance2.connection, config, new Time(), bufferPool); // create and send n messages instance1.messages = new List <byte[]>(); instance2.messages = new List <byte[]>(); for (int i = 0; i < messageCount; i++) { instance1.messages.Add(createRandomData(i + 1)); instance2.messages.Add(createRandomData(i + 1)); // send inside loop so message sending alternates between 1 and 2 // send to conn1 instance1.ackSystem.SendNotify(instance1.messages[i]); // give to instance2 if received if (received2[i]) { instance2.ackSystem.ReceiveNotify(instance1.connection.packets[i], instance1.connection.packets[i].Length); } // send to conn2 instance2.ackSystem.SendNotify(instance2.messages[i]); // give to instance1 if received if (received1[i]) { instance1.ackSystem.ReceiveNotify(instance2.connection.packets[i], instance2.connection.packets[i].Length); } } // should have got 1 packet Assert.That(instance1.connection.packets.Count, Is.EqualTo(messageCount)); Assert.That(instance2.connection.packets.Count, Is.EqualTo(messageCount)); // should not have null data Assert.That(instance1.connection.packets, Does.Not.Contain(null)); Assert.That(instance2.connection.packets, Does.Not.Contain(null)); }
public void SetUp() { var config = new Config(); int mtu = config.MaxPacketSize; int bigSize = (int)(mtu * 1.5f); byte[] message = CreateBigData(1, bigSize); instance = new AckTestInstance(); instance.connection = new SubIRawConnection(); instance.ackSystem = new AckSystem(instance.connection, config, new Time(), bufferPool); // create and send n messages instance.messages = new List <byte[]>(); instance.messages.Add(message); instance.ackSystem.SendReliable(message); // should not have null data Assert.That(instance.connection.packets, Does.Not.Contain(null)); }
public void SetUp() { config = new Config(); var mtu = MAX_PACKET_SIZE; var bigSize = (int)(mtu * 1.5f); message = CreateBigData(1, bigSize); var sender = new AckTestInstance(); sender.connection = new SubIRawConnection(); sender.ackSystem = new AckSystem(sender.connection, config, MAX_PACKET_SIZE, new Time(), bufferPool); sender.ackSystem.SendReliable(message); packet1 = sender.packet(0); packet2 = sender.packet(1); var connection = new SubIRawConnection(); ackSystem = new AckSystem(connection, config, MAX_PACKET_SIZE, new Time(), bufferPool); }