From 3cac3204519bbdfe02beb9d863e9b873cdaf9d07 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Mon, 31 Jan 2022 18:04:35 +0100 Subject: THRIFT-5511 Full support for the new net6 "nullability" semantics Client: netstd Patch: Jens Geyer This closes #2516 --- test/netstd/Client/Client.csproj | 6 +- test/netstd/Client/Performance/TestDataFactory.cs | 24 ++-- test/netstd/Client/TestClient.cs | 13 +- test/netstd/Server/Server.csproj | 6 +- test/netstd/Server/TestServer.cs | 153 ++++++++++++---------- 5 files changed, 110 insertions(+), 92 deletions(-) (limited to 'test') diff --git a/test/netstd/Client/Client.csproj b/test/netstd/Client/Client.csproj index e312990c9..9d4ab48c9 100644 --- a/test/netstd/Client/Client.csproj +++ b/test/netstd/Client/Client.csproj @@ -49,8 +49,8 @@ - - - + + + diff --git a/test/netstd/Client/Performance/TestDataFactory.cs b/test/netstd/Client/Performance/TestDataFactory.cs index 833947c25..8dec3f303 100644 --- a/test/netstd/Client/Performance/TestDataFactory.cs +++ b/test/netstd/Client/Performance/TestDataFactory.cs @@ -40,9 +40,9 @@ namespace Client.Tests }; } - private static THashSet CreateSetField(int count) + private static HashSet CreateSetField(int count) { - var retval = new THashSet(); + var retval = new HashSet(); for (var i = 0; i < count; ++i) retval.Add(CreateInsanity(count)); return retval; @@ -90,41 +90,41 @@ namespace Client.Tests return retval; } - private static List, Dictionary>>>>> CreateListField(int count) + private static List, Dictionary>>>>> CreateListField(int count) { - var retval = new List, Dictionary>>>>>(); + var retval = new List, Dictionary>>>>>(); for (var i = 0; i < count; ++i) retval.Add(CreateListFieldData(count)); return retval; } - private static Dictionary, Dictionary>>>> CreateListFieldData(int count) + private static Dictionary, Dictionary>>>> CreateListFieldData(int count) { - var retval = new Dictionary, Dictionary>>>>(); + var retval = new Dictionary, Dictionary>>>>(); for (var i = 0; i < count; ++i) retval.Add( CreateIntHashSet(count), CreateListFieldDataDict(count)); return retval; } - private static THashSet CreateIntHashSet(int count) + private static HashSet CreateIntHashSet(int count) { - var retval = new THashSet(); + var retval = new HashSet(); for (var i = 0; i < count; ++i) retval.Add(i); return retval; } - private static Dictionary>>> CreateListFieldDataDict(int count) + private static Dictionary>>> CreateListFieldDataDict(int count) { - var retval = new Dictionary>>>(); + var retval = new Dictionary>>>(); for (var i = 0; i < count; ++i) retval.Add(i, CreateListFieldDataDictValue(count)); return retval; } - private static THashSet>> CreateListFieldDataDictValue(int count) + private static HashSet>> CreateListFieldDataDictValue(int count) { - var retval = new THashSet>>(); + var retval = new HashSet>>(); for (var i = 0; i < count; ++i) retval.Add( CreateListFieldDataDictValueList(count)); return retval; diff --git a/test/netstd/Client/TestClient.cs b/test/netstd/Client/TestClient.cs index 0a7fa003b..0c80b9c48 100644 --- a/test/netstd/Client/TestClient.cs +++ b/test/netstd/Client/TestClient.cs @@ -644,9 +644,14 @@ namespace ThriftTest Struct_thing = o, I32_thing = 5 }; - var i2 = await client.testNest(o2, MakeTimeoutToken()); + Xtruct2 i2 = await client.testNest(o2, MakeTimeoutToken()); i = i2.Struct_thing; - Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}"); + Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + + (i?.String_thing ?? "") + "\", " + + (i?.Byte_thing ?? 0) + ", " + + (i?.I32_thing ?? 0) + ", " + + (i?.I64_thing ?? 0) + "}, " + + i2.I32_thing + "}"); var mapout = new Dictionary(); for (var j = 0; j < 5; j++) @@ -681,7 +686,7 @@ namespace ThriftTest //set // TODO: Validate received message - var setout = new THashSet(); + var setout = new HashSet(); for (var j = -2; j < 3; j++) { setout.Add(j); @@ -937,7 +942,7 @@ namespace ThriftTest } catch (Xception2 ex) { - if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2") + if (ex.ErrorCode != 2002 || ex.Struct_thing?.String_thing != "This is an Xception2") { Console.WriteLine("*** FAILED ***"); returnCode |= ErrorExceptions; diff --git a/test/netstd/Server/Server.csproj b/test/netstd/Server/Server.csproj index 546d0e2b9..439e5c1e6 100644 --- a/test/netstd/Server/Server.csproj +++ b/test/netstd/Server/Server.csproj @@ -51,8 +51,8 @@ - - - + + + diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs index 515a299f8..86072b0a7 100644 --- a/test/netstd/Server/TestServer.cs +++ b/test/netstd/Server/TestServer.cs @@ -229,10 +229,10 @@ namespace ThriftTest return Task.CompletedTask; } - public Task testString(string thing, CancellationToken cancellationToken) + public Task testString(string? thing, CancellationToken cancellationToken) { - logger.Invoke("testString({0})", thing); - return Task.FromResult(thing); + logger.Invoke("testString({0})", thing ?? ""); + return Task.FromResult(thing ?? string.Empty); } public Task testBool(bool thing, CancellationToken cancellationToken) @@ -265,117 +265,129 @@ namespace ThriftTest return Task.FromResult(thing); } - public Task testBinary(byte[] thing, CancellationToken cancellationToken) + public Task testBinary(byte[]? thing, CancellationToken cancellationToken) { - logger.Invoke("testBinary({0} bytes)", thing.Length); - return Task.FromResult(thing); + logger.Invoke("testBinary({0} bytes)", thing?.Length ?? 0); + return Task.FromResult(thing ?? Array.Empty()); } - public Task testStruct(Xtruct thing, CancellationToken cancellationToken) + public Task testStruct(Xtruct? thing, CancellationToken cancellationToken) { - logger.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing.String_thing, thing.Byte_thing, thing.I32_thing, thing.I64_thing); - return Task.FromResult(thing); + logger.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing?.String_thing ?? "", thing?.Byte_thing ?? 0, thing?.I32_thing ?? 0, thing?.I64_thing ?? 0); + return Task.FromResult(thing ?? new Xtruct()); // null returns are not allowed in Thrift } - public Task testNest(Xtruct2 nest, CancellationToken cancellationToken) + public Task testNest(Xtruct2? nest, CancellationToken cancellationToken) { - var thing = nest.Struct_thing; + var thing = nest?.Struct_thing; logger.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})", - nest.Byte_thing, - thing.String_thing, - thing.Byte_thing, - thing.I32_thing, - thing.I64_thing, - nest.I32_thing); - return Task.FromResult(nest); + nest?.Byte_thing ?? 0, + thing?.String_thing ?? "", + thing?.Byte_thing ?? 0, + thing?.I32_thing ?? 0, + thing?.I64_thing ?? 0, + nest?.I32_thing ?? 0); + return Task.FromResult(nest ?? new Xtruct2()); // null returns are not allowed in Thrift } - public Task> testMap(Dictionary thing, CancellationToken cancellationToken) + public Task> testMap(Dictionary? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testMap({{"); - var first = true; - foreach (var key in thing.Keys) + if (thing != null) { - if (first) - { - first = false; - } - else + var first = true; + foreach (var key in thing.Keys) { - sb.Append(", "); + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0} => {1}", key, thing[key]); } - sb.AppendFormat("{0} => {1}", key, thing[key]); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new Dictionary()); // null returns are not allowed in Thrift } - public Task> testStringMap(Dictionary thing, CancellationToken cancellationToken) + public Task> testStringMap(Dictionary? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testStringMap({{"); - var first = true; - foreach (var key in thing.Keys) + if (thing != null) { - if (first) - { - first = false; - } - else + var first = true; + foreach (var key in thing.Keys) { - sb.Append(", "); + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0} => {1}", key, thing[key]); } - sb.AppendFormat("{0} => {1}", key, thing[key]); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new Dictionary()); // null returns are not allowed in Thrift } - public Task> testSet(THashSet thing, CancellationToken cancellationToken) + public Task> testSet(HashSet? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testSet({{"); - var first = true; - foreach (int elem in thing) + if (thing != null) { - if (first) - { - first = false; - } - else + var first = true; + foreach (int elem in thing) { - sb.Append(", "); + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0}", elem); } - sb.AppendFormat("{0}", elem); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new HashSet()); // null returns are not allowed in Thrift } - public Task> testList(List thing, CancellationToken cancellationToken) + public Task> testList(List? thing, CancellationToken cancellationToken) { sb.Clear(); sb.Append("testList({{"); - var first = true; - foreach (var elem in thing) + if (thing != null) { - if (first) + var first = true; + foreach (var elem in thing) { - first = false; + if (first) + { + first = false; + } + else + { + sb.Append(", "); + } + sb.AppendFormat("{0}", elem); } - else - { - sb.Append(", "); - } - sb.AppendFormat("{0}", elem); } sb.Append("}})"); logger.Invoke(sb.ToString()); - return Task.FromResult(thing); + return Task.FromResult(thing ?? new List()); // null returns are not allowed in Thrift } public Task testEnum(Numberz thing, CancellationToken cancellationToken) @@ -409,7 +421,7 @@ namespace ThriftTest return Task.FromResult(mapmap); } - public Task>> testInsanity(Insanity argument, CancellationToken cancellationToken) + public Task>> testInsanity(Insanity? argument, CancellationToken cancellationToken) { logger.Invoke("testInsanity()"); @@ -428,8 +440,9 @@ namespace ThriftTest var first_map = new Dictionary(); var second_map = new Dictionary(); ; - first_map[Numberz.TWO] = argument; - first_map[Numberz.THREE] = argument; + // null dict keys/values are not allowed in Thrift + first_map[Numberz.TWO] = argument ?? new Insanity(); + first_map[Numberz.THREE] = argument ?? new Insanity(); second_map[Numberz.SIX] = new Insanity(); @@ -442,7 +455,7 @@ namespace ThriftTest return Task.FromResult(insane); } - public Task testMulti(sbyte arg0, int arg1, long arg2, Dictionary arg3, Numberz arg4, long arg5, + public Task testMulti(sbyte arg0, int arg1, long arg2, Dictionary? arg3, Numberz arg4, long arg5, CancellationToken cancellationToken) { logger.Invoke("testMulti()"); @@ -455,9 +468,9 @@ namespace ThriftTest return Task.FromResult(hello); } - public Task testException(string arg, CancellationToken cancellationToken) + public Task testException(string? arg, CancellationToken cancellationToken) { - logger.Invoke("testException({0})", arg); + logger.Invoke("testException({0})", arg ?? ""); if (arg == "Xception") { var x = new Xception @@ -474,9 +487,9 @@ namespace ThriftTest return Task.CompletedTask; } - public Task testMultiException(string arg0, string arg1, CancellationToken cancellationToken) + public Task testMultiException(string? arg0, string? arg1, CancellationToken cancellationToken) { - logger.Invoke("testMultiException({0}, {1})", arg0, arg1); + logger.Invoke("testMultiException({0}, {1})", arg0 ?? "", arg1 ?? ""); if (arg0 == "Xception") { var x = new Xception -- cgit v1.2.1