public void TestResendsAfterLosingAcks() { Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp); IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Loopback, testUdpPort); FixedRetryTimeout timeout = new FixedRetryTimeout(100, 6); using (TestServerWrapper server = new TestServerWrapper(serverEndPoint, timeout)) { Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp); // // // UdpConnectedClientTransmitter udpTransmitter = new UdpConnectedClientTransmitter(serverEndPoint); ClumsyTransmitter clumsyTransmitter = new ClumsyTransmitter(udpTransmitter, Console.Out); CdpTransmitter transmitter = new CdpTransmitter(clumsyTransmitter); Int64 startTicks = Stopwatch.GetTimestamp(); Console.WriteLine("[Sender {0} millis] Sending...", (Stopwatch.GetTimestamp() - startTicks).StopwatchTicksAsInt64Milliseconds()); UInt32 offset; Byte[] datagram = transmitter.RequestSendBuffer(10, out offset); for (Byte i = 0; i < 10; i++) { datagram[offset++] = (Byte)('A' + i); } clumsyTransmitter.DropAllReceivedDatagramsForTheNext(400); transmitter.ControllerSendPayloadWithAck(offset, timeout); server.TestSucceeded(); } }
public void SimpleTestMethod() { Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp); VirtualDatagramTransmitter transmitter = new VirtualDatagramTransmitter(); transmitter.Print(Console.Out); byte[] sendBuffer = new Byte[] { 0, 1, 2, 3, 4 }; byte[] receiveBuffer; Int32 length; // // Send Buffer // transmitter.Send(sendBuffer, 0, (UInt32)sendBuffer.Length); Assert.AreEqual(1, transmitter.DatagramsInSendQueue); // // Receive Buffer // receiveBuffer = new Byte[sendBuffer.Length]; length = transmitter.otherTransmitter.ReceiveNonBlocking(receiveBuffer, 0, (UInt32)receiveBuffer.Length); Assert.AreEqual(sendBuffer.Length, length); Assert.AreEqual(0, transmitter.DatagramsInSendQueue); CdpTest.AssertEqual(sendBuffer, receiveBuffer); length = transmitter.otherTransmitter.ReceiveNonBlocking(receiveBuffer, 0, (UInt32)sendBuffer.Length); Assert.AreEqual(-1, length); // // Send the buffer 5 times // for (int i = 0; i < 5; i++) { sendBuffer[0] = (Byte)i; transmitter.Send(sendBuffer, 0, (UInt32)sendBuffer.Length); Assert.AreEqual(i + 1, transmitter.DatagramsInSendQueue); } transmitter.Print(Console.Out); for (int i = 0; i < 5; i++) { Console.WriteLine("Receiving datagram {0}", i + 1); receiveBuffer = new Byte[sendBuffer.Length]; length = transmitter.otherTransmitter.ReceiveNonBlocking(receiveBuffer, 0, (UInt32)receiveBuffer.Length); Assert.AreEqual(sendBuffer.Length, length); Assert.AreEqual(4 - i, transmitter.DatagramsInSendQueue); sendBuffer[0] = (Byte)i; CdpTest.AssertEqual(sendBuffer, receiveBuffer); } length = transmitter.otherTransmitter.ReceiveNonBlocking(receiveBuffer, 0, (UInt32)sendBuffer.Length); Assert.AreEqual(-1, length); }
public void TestMethod1() { Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp); IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Loopback, testUdpPort); FixedRetryTimeout timeout = new FixedRetryTimeout(500, 6); using (TestServerWrapper server = new TestServerWrapper(serverEndPoint, timeout)) { UdpConnectedClientTransmitter udpTransmitter = new UdpConnectedClientTransmitter(serverEndPoint); CdpTransmitter transmitter = new CdpTransmitter(udpTransmitter); UInt32 offset; Byte[] myMessage; Byte[] payloadBuffer; // // Send and wait for ack // myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack"); payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset); Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length); offset += (UInt32)myMessage.Length; Console.WriteLine("[Client] Sending Payload With Ack..."); transmitter.ControllerSendPayloadWithAck(offset, timeout); // // Send heartbeat // Console.WriteLine("[Client] Sending Heartbeat..."); transmitter.SendHearbeat(); // // Send Random Payload // myMessage = Encoding.UTF8.GetBytes("This should be a random payload"); payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset); Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length); offset += (UInt32)myMessage.Length; Console.WriteLine("[Client] Sending Random Payload..."); transmitter.ControllerSendRandomPayload(offset); // // Send Payload no ack // myMessage = Encoding.UTF8.GetBytes("This should be the first payload with no immediate ack"); payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset); Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length); offset += (UInt32)myMessage.Length; Console.WriteLine("[Client] Sending Payload No Ack..."); transmitter.ControllerSendPayloadNoAck(offset); // // Send Payload no ack // myMessage = Encoding.UTF8.GetBytes("This should be the second payload with no immediate ack"); payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset); Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length); offset += (UInt32)myMessage.Length; Console.WriteLine("[Client] Sending Payload No Ack..."); transmitter.ControllerSendPayloadNoAck(offset); // // Send and wait for ack // myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack"); payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset); Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length); offset += (UInt32)myMessage.Length; Console.WriteLine("[Client] Sending Payload With Ack..."); transmitter.ControllerSendPayloadWithAck(offset, timeout); // // Send Halt // Console.WriteLine("[Client] Sending Halt..."); transmitter.SendHaltNoPayload(); server.TestSucceeded(); Console.WriteLine("[Client] Done (Success)"); } }