summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests
parentInitial commit. (diff)
downloadceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz
ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests')
-rw-r--r--src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/.gitignore2
-rw-r--r--src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs502
-rw-r--r--src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj29
3 files changed, 533 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/.gitignore b/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/.gitignore
new file mode 100644
index 000000000..7254c313a
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/.gitignore
@@ -0,0 +1,2 @@
+# ignore for autogenerated files
+/Apache
diff --git a/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs b/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs
new file mode 100644
index 000000000..bc4afa156
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs
@@ -0,0 +1,502 @@
+// Licensed to the Apache Software Foundation(ASF) under one
+// or more contributor license agreements.See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+using System;
+using System.IO;
+using System.Text;
+using System.Threading.Tasks;
+using KellermanSoftware.CompareNetObjects;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Thrift.Protocols;
+using Thrift.Protocols.Entities;
+using Thrift.Transports.Client;
+
+namespace Thrift.IntegrationTests.Protocols
+{
+ [TestClass]
+ public class ProtocolsOperationsTests
+ {
+ private readonly CompareLogic _compareLogic = new CompareLogic();
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol), TMessageType.Call)]
+ [DataRow(typeof(TBinaryProtocol), TMessageType.Exception)]
+ [DataRow(typeof(TBinaryProtocol), TMessageType.Oneway)]
+ [DataRow(typeof(TBinaryProtocol), TMessageType.Reply)]
+ [DataRow(typeof(TCompactProtocol), TMessageType.Call)]
+ [DataRow(typeof(TCompactProtocol), TMessageType.Exception)]
+ [DataRow(typeof(TCompactProtocol), TMessageType.Oneway)]
+ [DataRow(typeof(TCompactProtocol), TMessageType.Reply)]
+ [DataRow(typeof(TJsonProtocol), TMessageType.Call)]
+ [DataRow(typeof(TJsonProtocol), TMessageType.Exception)]
+ [DataRow(typeof(TJsonProtocol), TMessageType.Oneway)]
+ [DataRow(typeof(TJsonProtocol), TMessageType.Reply)]
+ public async Task WriteReadMessage_Test(Type protocolType, TMessageType messageType)
+ {
+ var expected = new TMessage(nameof(TMessage), messageType, 1);
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteMessageBeginAsync(expected);
+ await protocol.WriteMessageEndAsync();
+
+ stream.Seek(0, SeekOrigin.Begin);
+
+ var actualMessage = await protocol.ReadMessageBeginAsync();
+ await protocol.ReadMessageEndAsync();
+
+ var result = _compareLogic.Compare(expected, actualMessage);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ [ExpectedException(typeof(Exception))]
+ public async Task WriteReadStruct_Test(Type protocolType)
+ {
+ var expected = new TStruct(nameof(TStruct));
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteStructBeginAsync(expected);
+ await protocol.WriteStructEndAsync();
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadStructBeginAsync();
+ await protocol.ReadStructEndAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ [ExpectedException(typeof(Exception))]
+ public async Task WriteReadField_Test(Type protocolType)
+ {
+ var expected = new TField(nameof(TField), TType.String, 1);
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteFieldBeginAsync(expected);
+ await protocol.WriteFieldEndAsync();
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadFieldBeginAsync();
+ await protocol.ReadFieldEndAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadMap_Test(Type protocolType)
+ {
+ var expected = new TMap(TType.String, TType.String, 1);
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteMapBeginAsync(expected);
+ await protocol.WriteMapEndAsync();
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadMapBeginAsync();
+ await protocol.ReadMapEndAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadList_Test(Type protocolType)
+ {
+ var expected = new TList(TType.String, 1);
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteListBeginAsync(expected);
+ await protocol.WriteListEndAsync();
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadListBeginAsync();
+ await protocol.ReadListEndAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadSet_Test(Type protocolType)
+ {
+ var expected = new TSet(TType.String, 1);
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteSetBeginAsync(expected);
+ await protocol.WriteSetEndAsync();
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadSetBeginAsync();
+ await protocol.ReadSetEndAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadBool_Test(Type protocolType)
+ {
+ var expected = true;
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteBoolAsync(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadBoolAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadByte_Test(Type protocolType)
+ {
+ var expected = sbyte.MaxValue;
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteByteAsync(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadByteAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadI16_Test(Type protocolType)
+ {
+ var expected = short.MaxValue;
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteI16Async(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadI16Async();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadI32_Test(Type protocolType)
+ {
+ var expected = int.MaxValue;
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteI32Async(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadI32Async();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadI64_Test(Type protocolType)
+ {
+ var expected = long.MaxValue;
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteI64Async(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadI64Async();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadDouble_Test(Type protocolType)
+ {
+ var expected = double.MaxValue;
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteDoubleAsync(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadDoubleAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadString_Test(Type protocolType)
+ {
+ var expected = nameof(String);
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteStringAsync(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadStringAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadBinary_Test(Type protocolType)
+ {
+ var expected = Encoding.UTF8.GetBytes(nameof(String));
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Item1)
+ {
+ var protocol = tuple.Item2;
+
+ await protocol.WriteBinaryAsync(expected);
+
+ stream?.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadBinaryAsync();
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ private static Tuple<Stream, TProtocol> GetProtocolInstance(Type protocolType)
+ {
+ var memoryStream = new MemoryStream();
+ var streamClientTransport = new TStreamClientTransport(memoryStream, memoryStream);
+ var protocol = (TProtocol) Activator.CreateInstance(protocolType, streamClientTransport);
+ return new Tuple<Stream, TProtocol>(memoryStream, protocol);
+ }
+ }
+}
diff --git a/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj b/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj
new file mode 100644
index 000000000..f25dac536
--- /dev/null
+++ b/src/jaegertracing/thrift/lib/netcore/Tests/Thrift.IntegrationTests/Thrift.IntegrationTests.csproj
@@ -0,0 +1,29 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <TargetFramework>netcoreapp2.0</TargetFramework>
+ <AssemblyName>Thrift.IntegrationTests</AssemblyName>
+ <PackageId>Thrift.IntegrationTests</PackageId>
+ <OutputType>Exe</OutputType>
+ <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
+ <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
+ <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
+ <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
+ <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
+ <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="CompareNETObjects" Version="4.3.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
+ <PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
+ <PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
+ <PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\Thrift\Thrift.csproj" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
+ </ItemGroup>
+
+</Project> \ No newline at end of file