// [TestCase(1000000, 100, 12349)] public void SendsAndReceivesViaTcpConnection(int length, int ConcurrentLevel, int port) { TcpClient client; TcpClient serverClient; IntegrationTestsHelper.CreateTwoConnectedTcpClients(port, out client, out serverClient); var sendChannel = new TcpChannel(client); var receiveChannel = new TcpChannel(serverClient); sendChannel.AllowReceive = true; receiveChannel.AllowReceive = true; var sendtransporter = new Transporter(sendChannel); var receiveTransporwe = new Transporter(receiveChannel); int doneThreads = 0; Exception inThreadsException = null; receiveTransporwe.OnReceive += (_, arg) => { var buffer = new byte[length]; arg.Position = 0; arg.Read(buffer, 0, length); byte lastValue = buffer.Last(); for (int i = 0; i < length; i++) { try { Assert.AreEqual(lastValue, buffer[i], "Value is not as expected sience index " + i); } catch (Exception e) { inThreadsException = e; } } doneThreads++; }; IntegrationTestsHelper.RunInParrallel <MemoryStream>(ConcurrentLevel, i => { byte[] array = IntegrationTestsHelper.CreateArray(length, (byte)i); var stream = sendtransporter.CreateStreamForSend(); stream.Write(array, 0, array.Length); return(stream); }, (i, stream) => { sendtransporter.Write(stream); }); IntegrationTestsHelper.WaitOrThrow(() => doneThreads != ConcurrentLevel - 1, () => inThreadsException); client.Dispose(); serverClient.Dispose(); }
// [TestCase(1000000, 100)] public void SendsAndReceivesViaMockConnection(int length, int ConcurrentLevel) { var pair = TNT.Testing.TntTestHelper.CreateChannelPair(); pair.ConnectAndStartReceiving(); var sendtransporter = new Transporter(pair.CahnnelA); var receiveTransporwe = new Transporter(pair.ChannelB); int doneThreads = 0; Exception inThreadsException = null; receiveTransporwe.OnReceive += (_, arg) => { var buffer = new byte[length]; arg.Position = 0; arg.Read(buffer, 0, length); byte lastValue = buffer.Last(); for (int i = 0; i < length; i++) { try { Assert.AreEqual(lastValue, buffer[i], "Value is not as expected sience index " + i); } catch (Exception e) { inThreadsException = e; } } doneThreads++; }; IntegrationTestsHelper.RunInParrallel <MemoryStream>(ConcurrentLevel, initializeAction: i => { byte[] array = IntegrationTestsHelper.CreateArray(length, (byte)i); var stream = sendtransporter.CreateStreamForSend(); stream.Write(array, 0, array.Length); return(stream); }, action: (i, stream) => { sendtransporter.Write(stream); }); IntegrationTestsHelper.WaitOrThrow(() => doneThreads != ConcurrentLevel - 1, () => inThreadsException); pair.Disconnect(); }
// [TestCase(400000, 100, 13348)] public void SendAndReceiveViaTcpTest(int length, int concurentLevel, int port) { TcpClient client; TcpClient serverClient; IntegrationTestsHelper.CreateTwoConnectedTcpClients(port, out client, out serverClient); var channelA = new TcpChannel(client); var channelB = new TcpChannel(serverClient); List <byte> recievedList = new List <byte>(length); int doneThreads = 0; Exception innerException = null; channelB.OnReceive += (_, msg) => { recievedList.AddRange(msg); if (recievedList.Count >= length) { byte lastValue = recievedList[0]; for (int i = 0; i < length; i++) { var val = recievedList[0]; recievedList.RemoveAt(0); try { Assert.AreEqual(lastValue, val, "Value is not as expected sience index " + i); } catch (Exception e) { innerException = e; } } doneThreads++; } }; channelB.AllowReceive = true; IntegrationTestsHelper.RunInParrallel <byte[]>(concurentLevel, (i) => { return(IntegrationTestsHelper.CreateArray(length, (byte)i)); }, (i, msg) => { channelA.Write(msg, 0, msg.Length); }); IntegrationTestsHelper.WaitOrThrow(() => (doneThreads >= concurentLevel), () => innerException); channelA.Disconnect(); channelB.Disconnect(); }
// [TestCase(400000, 100, 13348)] public void SendAndReceiveViaTcpTest(int length, int ConcurrentLevel, int port) { TcpClient client; TcpClient serverClient; IntegrationTestsHelper.CreateTwoConnectedTcpClients(port, out client, out serverClient); var receiveTask = ReciveAndCheck(serverClient, length, ConcurrentLevel); IntegrationTestsHelper.RunInParrallel <byte[]>(ConcurrentLevel, i => { return(IntegrationTestsHelper.CreateArray(length, (byte)i)); }, (i, msg) => { lock (client) { //var stream = client.GetStream(); //var size = client.SendBufferSize; //for (int m = 0; m < msg.Length; i += size) //{ // int len = Math.Min(size, msg.Length-m); // client.GetStream().Write(msg, m, msg.Length); //} client.GetStream().Write(msg, 0, msg.Length); } }); try { receiveTask.Wait(); } catch (AggregateException e) { throw e.InnerException; } }