diff options
author | Jens Geyer <jensg@apache.org> | 2022-01-09 16:50:52 +0100 |
---|---|---|
committer | Jens Geyer <Jens-G@users.noreply.github.com> | 2022-01-09 21:57:30 +0100 |
commit | 98a232577fa56bb703ea96b88cc6c5b9391178f0 (patch) | |
tree | 916efb58623cd23042ed192961ac4df9387c221c /test/netstd | |
parent | 39d7278ddffce27d45380c483a84d013f6db4d7b (diff) | |
download | thrift-98a232577fa56bb703ea96b88cc6c5b9391178f0.tar.gz |
THRIFT-5479 Add net 6 support
Diffstat (limited to 'test/netstd')
-rw-r--r-- | test/netstd/Client/Client.csproj | 1 | ||||
-rw-r--r-- | test/netstd/Client/Performance/PerformanceTests.cs | 52 | ||||
-rw-r--r-- | test/netstd/Client/Performance/TestDataFactory.cs | 25 | ||||
-rw-r--r-- | test/netstd/Client/TestClient.cs | 11 | ||||
-rw-r--r-- | test/netstd/Server/Server.csproj | 1 | ||||
-rw-r--r-- | test/netstd/Server/TestServer.cs | 15 |
6 files changed, 55 insertions, 50 deletions
diff --git a/test/netstd/Client/Client.csproj b/test/netstd/Client/Client.csproj index c7d53493e..859297f97 100644 --- a/test/netstd/Client/Client.csproj +++ b/test/netstd/Client/Client.csproj @@ -31,6 +31,7 @@ <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> + <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> diff --git a/test/netstd/Client/Performance/PerformanceTests.cs b/test/netstd/Client/Performance/PerformanceTests.cs index f9eb9e4e4..c1f00ddf8 100644 --- a/test/netstd/Client/Performance/PerformanceTests.cs +++ b/test/netstd/Client/Performance/PerformanceTests.cs @@ -34,10 +34,10 @@ namespace Client.Tests { public class PerformanceTests { - private CancellationTokenSource Cancel; - private CrazyNesting Testdata; - private TMemoryBufferTransport MemBuffer; - private TTransport Transport; + private CancellationTokenSource Cancel = new(); + private CrazyNesting? Testdata; + private TMemoryBufferTransport? MemBuffer; + private TTransport? Transport; private LayeredChoice Layered; private readonly TConfiguration Configuration = new(); @@ -76,52 +76,49 @@ namespace Client.Tests } } - private Task<TProtocol> GenericProtocolFactory<T>(bool forWrite) + private async Task<TProtocol> GenericProtocolFactory<T>(bool forWrite) where T : TProtocol { var oldTrans = Transport; try { + Transport = null; + // read happens after write here, so let's take over the written bytes if (forWrite) MemBuffer = new TMemoryBufferTransport(Configuration); else - MemBuffer = new TMemoryBufferTransport(MemBuffer.GetBuffer(), Configuration); + MemBuffer = new TMemoryBufferTransport(MemBuffer?.GetBuffer(), Configuration); // layered transports anyone? - switch (Layered) + Transport = Layered switch { - case LayeredChoice.None: - Transport = MemBuffer; - break; - case LayeredChoice.Framed: - Transport = new TFramedTransport(MemBuffer); - break; - case LayeredChoice.Buffered: - Transport = new TBufferedTransport(MemBuffer); - break; - default: - Debug.Assert(false); - break; - } + LayeredChoice.None => MemBuffer, + LayeredChoice.Framed => new TFramedTransport(MemBuffer), + LayeredChoice.Buffered => new TBufferedTransport(MemBuffer), + _ => throw new Exception("Unhandled case " + Layered.ToString()), + }; + ; if (!Transport.IsOpen) Transport.OpenAsync().Wait(); - var instance = (T)Activator.CreateInstance(typeof(T), Transport); - return Task.FromResult<TProtocol>(instance); + if (Activator.CreateInstance(typeof(T), Transport) is T instance) + return instance; + + throw new Exception("Unexpected."); } finally { - if (oldTrans is IDisposable) - (oldTrans as IDisposable).Dispose(); + oldTrans?.Dispose(); } } private string GetProtocolTransportName(TProtocol proto) { - var name = Transport.GetType().Name; - if (name.Equals(MemBuffer.GetType().Name)) + var name = Transport?.GetType().Name; + var bufnm = MemBuffer?.GetType().Name; + if ((name is null) || name.Equals(bufnm)) name = string.Empty; else name = " + " + name; @@ -135,6 +132,9 @@ namespace Client.Tests { var stop = new Stopwatch(); + if ((Testdata is null) || (Transport is null)) + throw new Exception("unexpected internal state"); + var proto = await factory(true); stop.Start(); await Testdata.WriteAsync(proto, Cancel.Token); diff --git a/test/netstd/Client/Performance/TestDataFactory.cs b/test/netstd/Client/Performance/TestDataFactory.cs index 98962857c..833947c25 100644 --- a/test/netstd/Client/Performance/TestDataFactory.cs +++ b/test/netstd/Client/Performance/TestDataFactory.cs @@ -26,7 +26,7 @@ namespace Client.Tests static class TestDataFactory { - public static CrazyNesting CreateCrazyNesting(int count = 10) + public static CrazyNesting? CreateCrazyNesting(int count = 10) { if (count <= 0) return null; @@ -78,13 +78,15 @@ namespace Client.Tests private static Dictionary<Numberz, long> CreateUserMap(int count) { - var retval = new Dictionary<Numberz, long>(); - retval.Add(Numberz.ONE, count); - retval.Add(Numberz.TWO, count); - retval.Add(Numberz.THREE, count); - retval.Add(Numberz.FIVE, count); - retval.Add(Numberz.SIX, count); - retval.Add(Numberz.EIGHT, count); + var retval = new Dictionary<Numberz, long> + { + { Numberz.ONE, count }, + { Numberz.TWO, count }, + { Numberz.THREE, count }, + { Numberz.FIVE, count }, + { Numberz.SIX, count }, + { Numberz.EIGHT, count } + }; return retval; } @@ -138,9 +140,10 @@ namespace Client.Tests private static Dictionary<Insanity, string> CreateListFieldDataDictValueListDict(int count) { - var retval = new Dictionary<Insanity, string>(); - retval.Add(CreateInsanity(count), string.Format("data level {0}", count)); - return retval; + return new Dictionary<Insanity, string> + { + { CreateInsanity(count), string.Format("data level {0}", count) } + }; } private static byte[] CreateBytesArray(int count) diff --git a/test/netstd/Client/TestClient.cs b/test/netstd/Client/TestClient.cs index 38bccf1f5..0a7fa003b 100644 --- a/test/netstd/Client/TestClient.cs +++ b/test/netstd/Client/TestClient.cs @@ -71,12 +71,12 @@ namespace ThriftTest public string host = "localhost"; public int port = 9090; public int numThreads = 1; - public string url; - public string pipe; + public string url = string.Empty; + public string pipe = string.Empty; public LayeredChoice layered = LayeredChoice.None; public ProtocolChoice protocol = ProtocolChoice.Binary; public TransportChoice transport = TransportChoice.Socket; - private readonly TConfiguration Configuration = null; // or new TConfiguration() if needed + private readonly TConfiguration Configuration = new(); internal void Parse(List<string> args) { @@ -210,7 +210,7 @@ namespace ThriftTest "keys/", }; - string existingPath = null; + var existingPath = string.Empty; foreach (var possiblePath in possiblePaths) { var path = Path.GetFullPath(possiblePath + clientCertName); @@ -234,8 +234,7 @@ namespace ThriftTest public TTransport CreateTransport() { // endpoint transport - TTransport trans = null; - + TTransport trans; switch (transport) { case TransportChoice.Http: diff --git a/test/netstd/Server/Server.csproj b/test/netstd/Server/Server.csproj index 7d5eb1742..cda1dff9f 100644 --- a/test/netstd/Server/Server.csproj +++ b/test/netstd/Server/Server.csproj @@ -31,6 +31,7 @@ <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> + <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs index 65458d60a..515a299f8 100644 --- a/test/netstd/Server/TestServer.cs +++ b/test/netstd/Server/TestServer.cs @@ -36,6 +36,7 @@ using Thrift.Transport.Server; #pragma warning disable IDE0063 // using can be simplified, we don't #pragma warning disable IDE0057 // substr can be simplified, we don't +#pragma warning disable CS1998 // await missing namespace ThriftTest { @@ -74,7 +75,7 @@ namespace ThriftTest internal TransportChoice transport = TransportChoice.Socket; internal ServerChoice server = ServerChoice.Simple; internal int port = 9090; - internal string pipe = null; + internal string pipe = string.Empty; internal void Parse(List<string> args) { @@ -166,7 +167,7 @@ namespace ThriftTest public static int _clientID = -1; // use with Interlocked only! #pragma warning restore CA2211 - private static readonly TConfiguration Configuration = null; // or new TConfiguration() if needed + private static readonly TConfiguration Configuration = new(); public delegate void TestLogDelegate(string msg, params object[] values); @@ -180,10 +181,10 @@ namespace ThriftTest return Task.CompletedTask; } - public Task<object> CreateContextAsync(TProtocol input, TProtocol output, CancellationToken cancellationToken) + public async Task<object?> CreateContextAsync(TProtocol input, TProtocol output, CancellationToken cancellationToken) { callCount++; - return Task.FromResult<object>(null); + return null; } public Task DeleteContextAsync(object serverContext, TProtocol input, TProtocol output, CancellationToken cancellationToken) @@ -201,7 +202,7 @@ namespace ThriftTest public class TestHandlerAsync : ThriftTest.IAsync { - public TServer Server { get; set; } + //public TServer Server { get; set; } private readonly int handlerID; private readonly StringBuilder sb = new(); private readonly TestLogDelegate logger; @@ -520,7 +521,7 @@ namespace ThriftTest "keys/", }; - string existingPath = null; + var existingPath = string.Empty; foreach (var possiblePath in possiblePaths) { var path = Path.GetFullPath(possiblePath + serverCertName); @@ -595,7 +596,7 @@ namespace ThriftTest } // Layered transport (mandatory) - TTransportFactory transFactory = null; + TTransportFactory? transFactory; switch (param.buffering) { case BufferChoice.Framed: |