public async Task SingleSendReceiveComposePrimitiveTypeTest() { var tcpClient = GetClient <long, RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > >, RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(); var request = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <int> > > .Create( RecursiveMock <RecursiveMock <int> > .Create( RecursiveMock <int> .Create( int.MaxValue ) ) ) ) ); await tcpClient.SendAsync(request); var batch = await tcpClient.ReceiveAsync(1337L); var response = batch.First(); Assert.NotNull(response); Assert.NotNull(response.Data); Assert.NotNull(response.Data.Data); Assert.NotNull(response.Data.Data.Data); Assert.NotNull(response.Data.Data.Data.Data); Assert.AreEqual(response.Data.Data.Data.Data.Data, int.MaxValue); await tcpClient.DisposeAsync(); }
public void DeserializeFromBytesSpeedTest() { var binarySerializer = new BinarySerializer(new StandartBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <int> > > .Create( RecursiveMock <RecursiveMock <int> > .Create( RecursiveMock <int> .Create(int.MaxValue ) ) ) ) ); var serialize = binarySerializer.Serialize(mock); var sw = Stopwatch.StartNew(); for (var i = 0; i < 10000; i++) { var sequence = new ReadOnlySequence <byte>(serialize.Result); sw.Start(); var data = binarySerializer.Deserialize <long, RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(sequence); sw.Stop(); Assert.NotNull(data); } Assert.Less(sw.ElapsedMilliseconds, 300); TestContext.WriteLine($"Deserialize: {sw.Elapsed.ToString()}"); }
public async Task DeserializeFromPipeSpeedTest() { var binarySerializer = new BinarySerializer(new StandartBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <int> > > .Create( RecursiveMock <RecursiveMock <int> > .Create( RecursiveMock <int> .Create(int.MaxValue ) ) ) ) ); var serialize = binarySerializer.Serialize(mock); var sw = Stopwatch.StartNew(); for (var i = 0; i < 10000; i++) { var pipe = PipeReader.Create(new MemoryStream(serialize.Result.ToArray())); sw.Start(); var data = await binarySerializer.DeserializeAsync <long, RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(pipe, CancellationToken.None); sw.Stop(); Assert.NotNull(data); } Assert.Less(sw.ElapsedMilliseconds, 300); TestContext.WriteLine($"Deserialize: {sw.Elapsed.ToString()}"); }
public void SerializeStandartSpeedTest() { var binarySerializer = new BinarySerializer(new StandartBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <int> > > .Create( RecursiveMock <RecursiveMock <int> > .Create( RecursiveMock <int> .Create(int.MaxValue ) ) ) ) ); var sw = Stopwatch.StartNew(); for (var i = 0; i < 10000; i++) { _ = binarySerializer.Serialize(mock); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 300); TestContext.WriteLine($"Serialize: {sw.Elapsed.ToString()}"); }
public async Task SerializeWithPoolDeserializeFromPipeRecursiveComposeValueTypeTest() { var binarySerializer = new BinarySerializer(new ArrayPoolBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <int> .Create(1337); var serialize = binarySerializer.Serialize(mock); var pipe = PipeReader.Create(new MemoryStream(serialize.Result.ToArray())); var data = await binarySerializer.DeserializeAsync <long, RecursiveMock <int> >(pipe, CancellationToken.None); Assert.NotNull(data); }
public void SerializeStandartDeserializeRecursiveComposeValueTypeTest() { var binarySerializer = new BinarySerializer(new StandartBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <int> .Create(1337); var serialize = binarySerializer.Serialize(mock); var data = binarySerializer.Deserialize <long, RecursiveMock <int> >(new ReadOnlySequence <byte>(serialize.Result)); Assert.NotNull(data); Assert.AreEqual(mock.Id, data.Identifier); Assert.AreEqual(mock.Id, data.Result.Id); Assert.AreEqual(mock.Size, data.Result.Size); Assert.AreEqual(mock.Data, data.Result.Data); }
public async Task SerializeDeserializeRecursiveComposeValueTypeTest() { var pool = ArrayPool <byte> .Create(); var serializer = new TcpSerializer <RecursiveMock <int> >(_bitConverterHelper, i => pool.Rent(i)); var deserializer = new TcpDeserializer <long, RecursiveMock <int> >(_bitConverterHelper); var mock = RecursiveMock <int> .Create(1337); var serialize = serializer.Serialize(mock); var pipe = PipeReader.Create(new MemoryStream(serialize.Request.ToArray())); var(id, data) = await deserializer.DeserializeAsync(pipe, CancellationToken.None); Assert.NotNull(id); Assert.NotNull(data); }
public void SerializeStandartDeserializeRecursiveComposeTypeTest() { var binarySerializer = new BinarySerializer(new StandartBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > .Create( RecursiveMock <RecursiveMock <MockOnlyMetaData> > .Create( RecursiveMock <MockOnlyMetaData> .Create( new MockOnlyMetaData() ) ) ); var serialize = binarySerializer.Serialize(mock); var data = binarySerializer.Deserialize <long, RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > >(new ReadOnlySequence <byte>(serialize.Result)); Assert.NotNull(data); }
public async Task SerializeDeserializeSpeedTest() { var pool = ArrayPool <byte> .Create(); var serializer = new TcpSerializer <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(_bitConverterHelper, i => pool.Rent(i)); var deserializer = new TcpDeserializer <long, RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > >(_bitConverterHelper); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <int> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <int> > > .Create( RecursiveMock <RecursiveMock <int> > .Create( RecursiveMock <int> .Create(int.MaxValue ) ) ) ) ); var sw = Stopwatch.StartNew(); SerializedRequest serialize = null; for (var i = 0; i < 10000; i++) { serialize = serializer.Serialize(mock); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 1000); TestContext.WriteLine($"Serialize: {sw.Elapsed.ToString()}"); sw.Reset(); for (var i = 0; i < 10000; i++) { var pipe = PipeReader.Create(new MemoryStream(serialize.Request.ToArray())); sw.Start(); var(id, data) = await deserializer.DeserializeAsync(pipe, CancellationToken.None); sw.Stop(); Assert.NotNull(id); Assert.NotNull(data); } Assert.Less(sw.ElapsedMilliseconds, 1000); TestContext.WriteLine($"Deserialize: {sw.Elapsed.ToString()}"); }
public void SerializeStandartRecursiveComposeTypeTest() { var binarySerializer = new BinarySerializer(new StandartBinarySerializer(), new StandartBinaryDeserializer(), BinarySerializerStuffTest.Converters); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > .Create( RecursiveMock <RecursiveMock <MockOnlyMetaData> > .Create( RecursiveMock <MockOnlyMetaData> .Create( new MockOnlyMetaData() ) ) ) ); var result = binarySerializer.Serialize(mock); result.Dispose(); }
public void SerializeRecursiveComposeTypeTest() { var pool = ArrayPool <byte> .Create(); var serializer = new TcpSerializer <RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > > >(_bitConverterHelper, i => pool.Rent(i)); var mock = RecursiveMock <RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > > .Create( RecursiveMock <RecursiveMock <RecursiveMock <MockOnlyMetaData> > > .Create( RecursiveMock <RecursiveMock <MockOnlyMetaData> > .Create( RecursiveMock <MockOnlyMetaData> .Create( new MockOnlyMetaData() ) ) ) ); var serializedRequest = serializer.Serialize(mock); serializedRequest.ReturnRentedArrays(pool, false); }
public void TestEnumerateRecursively() { const int MAX = 10; var root = new RecursiveMock() { Id = 0 }; for (var n = 1; n < MAX; ++n) { var child = new RecursiveMock { Id = n, Child = root }; root = child; } var children = root.EnumerateRecursively(r => new[] { r.Child }); Assert.NotNull(children); var array = children.ToArray(); Assert.Equal(MAX, array.Length); for (var n = 0; n < MAX; ++n) { Assert.Equal(MAX - 1 - n, array[n].Id); } children = root.EnumerateRecursively(r => null); Assert.NotNull(children); Assert.Single(children); }