You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2021/04/10 08:10:57 UTC
[thrift] branch master updated (6583f4e -> 2b2ea62)
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git.
from 6583f4e THRIFT-5369: Use MaxMessageSize to check container sizes
new 6228b90 THRIFT-5395 inconsistent treatment of methods ending in "Async" Client: netstd Patch: Jens Geyer
new 2b2ea62 THRIFT-5396 deprecate "Async" method postfix Client: netstd Patch: Jens Geyer
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../cpp/src/thrift/generate/t_netstd_generator.cc | 128 +++++++++++++++------
.../cpp/src/thrift/generate/t_netstd_generator.h | 7 +-
.../GlobalSuppressions.cs | 9 ++
.../Impl/Thrift5253/MyService.cs | 23 +++-
.../Thrift5253.thrift | 4 +
test/netstd/Client/GlobalSuppressions.cs | 26 -----
test/netstd/Client/TestClient.cs | 70 +++++------
test/netstd/Server/GlobalSuppressions.cs | 26 -----
test/netstd/Server/TestServer.cs | 47 ++++----
tutorial/netstd/Client/Program.cs | 44 ++++---
tutorial/netstd/Server/Program.cs | 95 ++++++---------
11 files changed, 246 insertions(+), 233 deletions(-)
create mode 100644 lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/GlobalSuppressions.cs
delete mode 100644 test/netstd/Client/GlobalSuppressions.cs
delete mode 100644 test/netstd/Server/GlobalSuppressions.cs
[thrift] 02/02: THRIFT-5396 deprecate "Async" method postfix
Client: netstd Patch: Jens Geyer
Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 2b2ea622b67c9b0be4e6baf09cc604fad887cae4
Author: Jens Geyer <je...@apache.org>
AuthorDate: Fri Apr 9 22:55:11 2021 +0200
THRIFT-5396 deprecate "Async" method postfix
Client: netstd
Patch: Jens Geyer
This closes #2374
---
.../cpp/src/thrift/generate/t_netstd_generator.cc | 105 ++++++++++++++++++---
.../cpp/src/thrift/generate/t_netstd_generator.h | 7 +-
.../GlobalSuppressions.cs | 9 ++
.../Impl/Thrift5253/MyService.cs | 17 ++--
test/netstd/Client/GlobalSuppressions.cs | 26 -----
test/netstd/Client/TestClient.cs | 70 +++++++-------
test/netstd/Server/GlobalSuppressions.cs | 26 -----
test/netstd/Server/TestServer.cs | 47 ++++-----
tutorial/netstd/Client/Program.cs | 44 ++++-----
tutorial/netstd/Server/Program.cs | 95 +++++++------------
10 files changed, 228 insertions(+), 218 deletions(-)
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
index 8b1c4c4..766d2b6 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
@@ -52,6 +52,7 @@ t_netstd_generator::t_netstd_generator(t_program* program, const map<string, str
{
(void)option_string;
suppress_deepcopy = false;
+ add_async_postfix = false;
use_pascal_case_properties = false;
union_ = false;
serialize_ = false;
@@ -80,6 +81,9 @@ t_netstd_generator::t_netstd_generator(t_program* program, const map<string, str
else if (iter->first.compare("no_deepcopy") == 0) {
suppress_deepcopy = true;
}
+ else if (iter->first.compare("async_postfix") == 0) {
+ add_async_postfix = true;
+ }
else {
throw "unknown option netstd:" + iter->first;
}
@@ -179,11 +183,12 @@ void t_netstd_generator::init_generator()
}
pverbose(".NET Standard options:\n");
- pverbose("- union ......... %s\n", (is_union_enabled() ? "ON" : "off"));
- pverbose("- serialize ..... %s\n", (is_serialize_enabled() ? "ON" : "off"));
- pverbose("- wcf ........... %s\n", (is_wcf_enabled() ? "ON" : "off"));
- pverbose("- pascal ........ %s\n", (use_pascal_case_properties ? "ON" : "off"));
- pverbose("- no_deepcopy ... %s\n", (suppress_deepcopy ? "ON" : "off"));
+ pverbose("- union ........... %s\n", (is_union_enabled() ? "ON" : "off"));
+ pverbose("- serialize ....... %s\n", (is_serialize_enabled() ? "ON" : "off"));
+ pverbose("- wcf ............. %s\n", (is_wcf_enabled() ? "ON" : "off"));
+ pverbose("- pascal .......... %s\n", (use_pascal_case_properties ? "ON" : "off"));
+ pverbose("- no_deepcopy ..... %s\n", (suppress_deepcopy ? "ON" : "off"));
+ pverbose("- async_postfix ... %s\n", (add_async_postfix ? "ON" : "off"));
}
string t_netstd_generator::normalize_name(string name)
@@ -1914,6 +1919,7 @@ void t_netstd_generator::generate_service_interface(ostream& out, t_service* tse
out << indent() << "[ServiceContract(Namespace=\"" << wcf_namespace_ << "\")]" << endl;
}
+ prepare_member_name_mapping(tservice);
out << indent() << "public interface IAsync" << extends_iface << endl
<< indent() << "{" << endl;
@@ -1941,6 +1947,7 @@ void t_netstd_generator::generate_service_interface(ostream& out, t_service* tse
}
indent_down();
out << indent() << "}" << endl << endl;
+ cleanup_member_name_mapping(tservice);
}
void t_netstd_generator::generate_service_helpers(ostream& out, t_service* tservice)
@@ -1948,6 +1955,7 @@ void t_netstd_generator::generate_service_helpers(ostream& out, t_service* tserv
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
+ prepare_member_name_mapping(tservice);
out << indent() << "public class InternalStructs" << endl;
out << indent() << "{" << endl;
indent_up();
@@ -1962,6 +1970,7 @@ void t_netstd_generator::generate_service_helpers(ostream& out, t_service* tserv
indent_down();
out << indent() << "}" << endl << endl;
+ cleanup_member_name_mapping(tservice);
}
void t_netstd_generator::generate_service_client(ostream& out, t_service* tservice)
@@ -1981,7 +1990,7 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
out << endl;
generate_netstd_doc(out, tservice);
-
+ prepare_member_name_mapping(tservice);
out << indent() << "public class Client : " << extends_client << "IAsync" << endl
<< indent() << "{" << endl;
indent_up();
@@ -2000,7 +2009,7 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
for (functions_iterator = functions.begin(); functions_iterator != functions.end(); ++functions_iterator)
{
string raw_func_name = (*functions_iterator)->get_name();
- string function_name = raw_func_name + "Async";
+ string function_name = raw_func_name + (add_async_postfix ? "Async" : "");
// async
out << indent() << "public async " << function_signature_async(*functions_iterator, "") << endl
@@ -2093,7 +2102,7 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
<< function_name << " failed: unknown result\");" << endl;
}
- cleanup_member_name_mapping((*functions_iterator)->get_xceptions());
+ cleanup_member_name_mapping(xs);
indent_down();
out << indent() << "}" << endl << endl;
}
@@ -2102,10 +2111,13 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
indent_down();
out << indent() << "}" << endl;
}
+
+ cleanup_member_name_mapping(arg_struct);
}
indent_down();
out << indent() << "}" << endl << endl;
+ cleanup_member_name_mapping(tservice);
}
void t_netstd_generator::generate_service_server(ostream& out, t_service* tservice)
@@ -2121,6 +2133,7 @@ void t_netstd_generator::generate_service_server(ostream& out, t_service* tservi
extends_processor = extends + ".AsyncProcessor, ";
}
+ prepare_member_name_mapping(tservice);
out << indent() << "public class AsyncProcessor : " << extends_processor << "ITAsyncProcessor" << endl
<< indent() << "{" << endl;
@@ -2232,6 +2245,7 @@ void t_netstd_generator::generate_service_server(ostream& out, t_service* tservi
indent_down();
out << indent() << "}" << endl << endl;
+ cleanup_member_name_mapping(tservice);
}
void t_netstd_generator::generate_function_helpers(ostream& out, t_function* tfunction)
@@ -2304,7 +2318,7 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service
out << "result.Success = ";
}
- out << "await _iAsync." << normalize_name(tfunction->get_name()) << "Async(";
+ out << "await _iAsync." << func_name(normalize_name(tfunction->get_name()) + (add_async_postfix ? "Async" : "")) << "(";
bool first = true;
collect_extensions_types(arg_struct);
@@ -2996,12 +3010,17 @@ string t_netstd_generator::get_mapped_member_name(string name)
return name;
}
+void t_netstd_generator::prepare_member_name_mapping(t_service* tservice)
+{
+ prepare_member_name_mapping(tservice, tservice->get_functions(), tservice->get_name());
+}
+
void t_netstd_generator::prepare_member_name_mapping(t_struct* tstruct)
{
prepare_member_name_mapping(tstruct, tstruct->get_members(), tstruct->get_name());
}
-void t_netstd_generator::prepare_member_name_mapping(void* scope, const vector<t_field*>& members, const string& structname)
+void t_netstd_generator::prepare_member_name_mapping(t_struct* scope, const vector<t_field*>& members, const string& structname)
{
// begin new scope
member_mapping_scopes.emplace_back();
@@ -3014,11 +3033,9 @@ void t_netstd_generator::prepare_member_name_mapping(void* scope, const vector<t
std::set<string> used_member_names;
vector<t_field*>::const_iterator iter;
- // prevent name conflicts with struct (CS0542 error)
+ // prevent name conflicts with struct (CS0542 error + THRIFT-2942)
used_member_names.insert(structname);
used_member_names.insert("Isset");
-
- // prevent name conflicts with known methods (THRIFT-2942)
used_member_names.insert("Read");
used_member_names.insert("Write");
@@ -3047,6 +3064,51 @@ void t_netstd_generator::prepare_member_name_mapping(void* scope, const vector<t
}
+void t_netstd_generator::prepare_member_name_mapping(t_service* scope, const vector<t_function*>& members, const string& structname)
+{
+ // begin new scope
+ member_mapping_scopes.emplace_back();
+ member_mapping_scope& active = member_mapping_scopes.back();
+ active.scope_member = scope;
+
+ // current C# generator policy:
+ // - prop names are always rendered with an Uppercase first letter
+ // - struct names are used as given
+ std::set<string> used_member_names;
+ vector<t_function*>::const_iterator iter;
+
+ // prevent name conflicts with service/intf
+ used_member_names.insert(structname);
+ used_member_names.insert("Client");
+ used_member_names.insert("IAsync");
+ used_member_names.insert("AsyncProcessor");
+ used_member_names.insert("InternalStructs");
+
+ for (iter = members.begin(); iter != members.end(); ++iter)
+ {
+ string oldname = (*iter)->get_name();
+ string newname = func_name(*iter, true);
+ while (true)
+ {
+ // new name conflicts with another method
+ if (used_member_names.find(newname) != used_member_names.end())
+ {
+ pverbose("service %s: method %s conflicts with another method\n", structname.c_str(), newname.c_str());
+ newname += '_';
+ continue;
+ }
+
+ // add always, this helps us to detect edge cases like
+ // different spellings ("foo" and "Foo") within the same service
+ pverbose("service %s: method mapping %s => %s\n", structname.c_str(), oldname.c_str(), newname.c_str());
+ active.mapping_table[oldname] = newname;
+ used_member_names.insert(newname);
+ break;
+ }
+ }
+}
+
+
string t_netstd_generator::convert_to_pascal_case(const string& str) {
string out;
bool must_capitalize = true;
@@ -3088,6 +3150,18 @@ string t_netstd_generator::prop_name(t_field* tfield, bool suppress_mapping) {
return name;
}
+string t_netstd_generator::func_name(t_function* tfunc, bool suppress_mapping) {
+ return func_name(tfunc->get_name(), suppress_mapping);
+}
+
+string t_netstd_generator::func_name(std::string fname, bool suppress_mapping) {
+ if (suppress_mapping) {
+ return fname;
+ }
+
+ return get_mapped_member_name(fname);
+}
+
string t_netstd_generator::type_name(t_type* ttype)
{
ttype = resolve_typedef(ttype);
@@ -3248,7 +3322,7 @@ string t_netstd_generator::declare_field(t_field* tfield, bool init, string pref
string t_netstd_generator::function_signature(t_function* tfunction, string prefix)
{
t_type* ttype = tfunction->get_returntype();
- return type_name(ttype) + " " + normalize_name(prefix + tfunction->get_name()) + "(" + argument_list(tfunction->get_arglist()) + ")";
+ return type_name(ttype) + " " + func_name(normalize_name(prefix + tfunction->get_name())) + "(" + argument_list(tfunction->get_arglist()) + ")";
}
string t_netstd_generator::function_signature_async(t_function* tfunction, string prefix)
@@ -3260,7 +3334,7 @@ string t_netstd_generator::function_signature_async(t_function* tfunction, strin
task += "<" + type_name(ttype) + ">";
}
- string result = task + " " + normalize_name(prefix + tfunction->get_name()) + "Async(";
+ string result = task + " " + func_name(normalize_name(prefix + tfunction->get_name()) + (add_async_postfix ? "Async" : "")) + "(";
string args = argument_list(tfunction->get_arglist());
result += args;
if (!args.empty())
@@ -3447,4 +3521,5 @@ THRIFT_REGISTER_GENERATOR(
" union: Use new union typing, which includes a static read function for union types.\n"
" pascal: Generate Pascal Case property names according to Microsoft naming convention.\n"
" no_deepcopy: Suppress generation of DeepCopy() method.\n"
+ " async_postfix: Append \"Async\" to all service methods (maintains compatibility with existing code).\n"
)
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.h b/compiler/cpp/src/thrift/generate/t_netstd_generator.h
index 1217cc8..8a812a3 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.h
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.h
@@ -139,6 +139,8 @@ public:
string argument_list(t_struct* tstruct);
string type_to_enum(t_type* ttype);
string prop_name(t_field* tfield, bool suppress_mapping = false);
+ string func_name(t_function* tfunc, bool suppress_mapping = false);
+ string func_name(std::string fname, bool suppress_mapping = false);
string convert_to_pascal_case(const string& str);
string get_enum_class_name(t_type* type);
@@ -152,6 +154,7 @@ private:
bool wcf_;
bool use_pascal_case_properties;
bool suppress_deepcopy;
+ bool add_async_postfix;
string wcf_namespace_;
map<string, int> netstd_keywords;
@@ -162,8 +165,10 @@ private:
void init_keywords();
string normalize_name(string name);
string make_valid_csharp_identifier(string const& fromName);
+ void prepare_member_name_mapping(t_service* tservice);
void prepare_member_name_mapping(t_struct* tstruct);
- void prepare_member_name_mapping(void* scope, const vector<t_field*>& members, const string& structname);
+ void prepare_member_name_mapping(t_struct* scope, const vector<t_field*>& members, const string& structname);
+ void prepare_member_name_mapping(t_service* scope, const vector<t_function*>& members, const string& structname);
void cleanup_member_name_mapping(void* scope);
string get_mapped_member_name(string oldname);
string get_isset_name(const string& str);
diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/GlobalSuppressions.cs b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/GlobalSuppressions.cs
new file mode 100644
index 0000000..77cd3fc
--- /dev/null
+++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/GlobalSuppressions.cs
@@ -0,0 +1,9 @@
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+using System.Diagnostics.CodeAnalysis;
+
+[assembly: SuppressMessage("Performance", "CA1822", Justification = "<Ausstehend>", Scope = "module")]
+[assembly: SuppressMessage("Style", "IDE0090", Justification = "<Ausstehend>", Scope = "module")]
diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs
index 1b8d99f..660b2b7 100644
--- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs
+++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs
@@ -26,42 +26,43 @@ namespace Thrift.PublicInterfaces.Compile.Tests.Impl.Thrift5253
{
class MyServiceImpl : MyService.IAsync
{
- public Task<AsyncProcessor> AsyncProcessorAsync(AsyncProcessor input, CancellationToken cancellationToken = default)
+ public Task<AsyncProcessor> AsyncProcessor_(AsyncProcessor input, CancellationToken cancellationToken = default)
{
return Task.FromResult(new AsyncProcessor() { Foo = input.Foo });
}
- public Task<BrokenResult> BrokenAsync(BrokenArgs input, CancellationToken cancellationToken = default)
+ public Task<BrokenResult> Broken(BrokenArgs input, CancellationToken cancellationToken = default)
{
return Task.FromResult(new BrokenResult() { Foo = input.Foo });
}
- public Task<Client> ClientAsync(Client input, CancellationToken cancellationToken = default)
+ public Task<Client> Client_(Client input, CancellationToken cancellationToken = default)
{
+ _ = cancellationToken;
return Task.FromResult(new Client() { Foo = input.Foo });
}
- public Task<IAsync> IAsyncAsync(IAsync input, CancellationToken cancellationToken = default)
+ public Task<IAsync> IAsync_(IAsync input, CancellationToken cancellationToken = default)
{
return Task.FromResult(new IAsync() { Foo = input.Foo });
}
- public Task<InternalStructs> InternalStructsAsync(InternalStructs input, CancellationToken cancellationToken = default)
+ public Task<InternalStructs> InternalStructs_(InternalStructs input, CancellationToken cancellationToken = default)
{
return Task.FromResult(new InternalStructs() { Foo = input.Foo });
}
- public Task TestAsyncAsync(CancellationToken cancellationToken = default)
+ public Task TestAsync(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
- public Task TestXsyncAsync(CancellationToken cancellationToken = default)
+ public Task TestXsync(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
- public Task<WorksRslt> WorksAsync(WorksArrrgs input, CancellationToken cancellationToken = default)
+ public Task<WorksRslt> Works(WorksArrrgs input, CancellationToken cancellationToken = default)
{
return Task.FromResult(new WorksRslt() { Foo = input.Foo });
}
diff --git a/test/netstd/Client/GlobalSuppressions.cs b/test/netstd/Client/GlobalSuppressions.cs
deleted file mode 100644
index 34fdc79..0000000
--- a/test/netstd/Client/GlobalSuppressions.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-// This file is used by Code Analysis to maintain SuppressMessage
-// attributes that are applied to this project.
-// Project-level suppressions either have no target or are given
-// a specific target and scoped to a namespace, type, member, etc.
-
-using System.Diagnostics.CodeAnalysis;
-
-[assembly: SuppressMessage("Performance", "CA1822", Justification = "<Ausstehend>", Scope = "module")]
-[assembly: SuppressMessage("Style", "IDE0083", Justification = "<Ausstehend>", Scope = "module")]
diff --git a/test/netstd/Client/TestClient.cs b/test/netstd/Client/TestClient.cs
index ec90250..70a21e1 100644
--- a/test/netstd/Client/TestClient.cs
+++ b/test/netstd/Client/TestClient.cs
@@ -353,7 +353,7 @@ namespace ThriftTest
try
{
- ReturnCode |= ExecuteClientTestAsync(client).GetAwaiter().GetResult(); ;
+ ReturnCode |= ExecuteClientTest(client).GetAwaiter().GetResult(); ;
}
catch (Exception ex)
{
@@ -469,7 +469,7 @@ namespace ThriftTest
amount = 15 * 1024 * 1024;
break;
default:
- throw new ArgumentException(nameof(testcase));
+ throw new ArgumentException("invalid argument",nameof(testcase));
}
var retval = new byte[amount];
@@ -499,16 +499,16 @@ namespace ThriftTest
return token.Token;
}
- public static async Task<int> ExecuteClientTestAsync(ThriftTest.Client client)
+ public static async Task<int> ExecuteClientTest(ThriftTest.Client client)
{
var returnCode = 0;
Console.Write("testVoid()");
- await client.testVoidAsync(MakeTimeoutToken());
+ await client.testVoid(MakeTimeoutToken());
Console.WriteLine(" = void");
Console.Write("testString(\"Test\")");
- var s = await client.testStringAsync("Test", MakeTimeoutToken());
+ var s = await client.testString("Test", MakeTimeoutToken());
Console.WriteLine(" = \"" + s + "\"");
if ("Test" != s)
{
@@ -517,7 +517,7 @@ namespace ThriftTest
}
Console.Write("testBool(true)");
- var t = await client.testBoolAsync((bool)true, MakeTimeoutToken());
+ var t = await client.testBool((bool)true, MakeTimeoutToken());
Console.WriteLine(" = " + t);
if (!t)
{
@@ -525,7 +525,7 @@ namespace ThriftTest
returnCode |= ErrorBaseTypes;
}
Console.Write("testBool(false)");
- var f = await client.testBoolAsync((bool)false, MakeTimeoutToken());
+ var f = await client.testBool((bool)false, MakeTimeoutToken());
Console.WriteLine(" = " + f);
if (f)
{
@@ -534,7 +534,7 @@ namespace ThriftTest
}
Console.Write("testByte(1)");
- var i8 = await client.testByteAsync((sbyte)1, MakeTimeoutToken());
+ var i8 = await client.testByte((sbyte)1, MakeTimeoutToken());
Console.WriteLine(" = " + i8);
if (1 != i8)
{
@@ -543,7 +543,7 @@ namespace ThriftTest
}
Console.Write("testI32(-1)");
- var i32 = await client.testI32Async(-1, MakeTimeoutToken());
+ var i32 = await client.testI32(-1, MakeTimeoutToken());
Console.WriteLine(" = " + i32);
if (-1 != i32)
{
@@ -552,7 +552,7 @@ namespace ThriftTest
}
Console.Write("testI64(-34359738368)");
- var i64 = await client.testI64Async(-34359738368, MakeTimeoutToken());
+ var i64 = await client.testI64(-34359738368, MakeTimeoutToken());
Console.WriteLine(" = " + i64);
if (-34359738368 != i64)
{
@@ -562,7 +562,7 @@ namespace ThriftTest
// TODO: Validate received message
Console.Write("testDouble(5.325098235)");
- var dub = await client.testDoubleAsync(5.325098235, MakeTimeoutToken());
+ var dub = await client.testDouble(5.325098235, MakeTimeoutToken());
Console.WriteLine(" = " + dub);
if (5.325098235 != dub)
{
@@ -570,7 +570,7 @@ namespace ThriftTest
returnCode |= ErrorBaseTypes;
}
Console.Write("testDouble(-0.000341012439638598279)");
- dub = await client.testDoubleAsync(-0.000341012439638598279, MakeTimeoutToken());
+ dub = await client.testDouble(-0.000341012439638598279, MakeTimeoutToken());
Console.WriteLine(" = " + dub);
if (-0.000341012439638598279 != dub)
{
@@ -586,7 +586,7 @@ namespace ThriftTest
Console.Write("testBinary({0} bytes)", binOut.Length);
try
{
- var binIn = await client.testBinaryAsync(binOut, MakeTimeoutToken());
+ var binIn = await client.testBinary(binOut, MakeTimeoutToken());
Console.WriteLine(" = {0} bytes", binIn.Length);
if (binIn.Length != binOut.Length)
{
@@ -636,7 +636,7 @@ namespace ThriftTest
I32_thing = -3,
I64_thing = -5
};
- var i = await client.testStructAsync(o, MakeTimeoutToken());
+ var i = await client.testStruct(o, MakeTimeoutToken());
Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");
// TODO: Validate received message
@@ -647,7 +647,7 @@ namespace ThriftTest
Struct_thing = o,
I32_thing = 5
};
- var i2 = await client.testNestAsync(o2, MakeTimeoutToken());
+ var 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 + "}");
@@ -672,7 +672,7 @@ namespace ThriftTest
}
Console.Write("})");
- var mapin = await client.testMapAsync(mapout, MakeTimeoutToken());
+ var mapin = await client.testMap(mapout, MakeTimeoutToken());
Console.Write(" = {");
first = true;
@@ -712,7 +712,7 @@ namespace ThriftTest
}
Console.Write("})");
- var listin = await client.testListAsync(listout, MakeTimeoutToken());
+ var listin = await client.testList(listout, MakeTimeoutToken());
Console.Write(" = {");
first = true;
@@ -753,7 +753,7 @@ namespace ThriftTest
}
Console.Write("})");
- var setin = await client.testSetAsync(setout, MakeTimeoutToken());
+ var setin = await client.testSet(setout, MakeTimeoutToken());
Console.Write(" = {");
first = true;
@@ -773,7 +773,7 @@ namespace ThriftTest
Console.Write("testEnum(ONE)");
- var ret = await client.testEnumAsync(Numberz.ONE, MakeTimeoutToken());
+ var ret = await client.testEnum(Numberz.ONE, MakeTimeoutToken());
Console.WriteLine(" = " + ret);
if (Numberz.ONE != ret)
{
@@ -782,7 +782,7 @@ namespace ThriftTest
}
Console.Write("testEnum(TWO)");
- ret = await client.testEnumAsync(Numberz.TWO, MakeTimeoutToken());
+ ret = await client.testEnum(Numberz.TWO, MakeTimeoutToken());
Console.WriteLine(" = " + ret);
if (Numberz.TWO != ret)
{
@@ -791,7 +791,7 @@ namespace ThriftTest
}
Console.Write("testEnum(THREE)");
- ret = await client.testEnumAsync(Numberz.THREE, MakeTimeoutToken());
+ ret = await client.testEnum(Numberz.THREE, MakeTimeoutToken());
Console.WriteLine(" = " + ret);
if (Numberz.THREE != ret)
{
@@ -800,7 +800,7 @@ namespace ThriftTest
}
Console.Write("testEnum(FIVE)");
- ret = await client.testEnumAsync(Numberz.FIVE, MakeTimeoutToken());
+ ret = await client.testEnum(Numberz.FIVE, MakeTimeoutToken());
Console.WriteLine(" = " + ret);
if (Numberz.FIVE != ret)
{
@@ -809,7 +809,7 @@ namespace ThriftTest
}
Console.Write("testEnum(EIGHT)");
- ret = await client.testEnumAsync(Numberz.EIGHT, MakeTimeoutToken());
+ ret = await client.testEnum(Numberz.EIGHT, MakeTimeoutToken());
Console.WriteLine(" = " + ret);
if (Numberz.EIGHT != ret)
{
@@ -818,7 +818,7 @@ namespace ThriftTest
}
Console.Write("testTypedef(309858235082523)");
- var uid = await client.testTypedefAsync(309858235082523L, MakeTimeoutToken());
+ var uid = await client.testTypedef(309858235082523L, MakeTimeoutToken());
Console.WriteLine(" = " + uid);
if (309858235082523L != uid)
{
@@ -828,7 +828,7 @@ namespace ThriftTest
// TODO: Validate received message
Console.Write("testMapMap(1)");
- var mm = await client.testMapMapAsync(1, MakeTimeoutToken());
+ var mm = await client.testMapMap(1, MakeTimeoutToken());
Console.Write(" = {");
foreach (var key in mm.Keys)
{
@@ -862,7 +862,7 @@ namespace ThriftTest
truck
};
Console.Write("testInsanity()");
- var whoa = await client.testInsanityAsync(insane, MakeTimeoutToken());
+ var whoa = await client.testInsanity(insane, MakeTimeoutToken());
Console.Write(" = {");
foreach (var key in whoa.Keys)
{
@@ -927,14 +927,14 @@ namespace ThriftTest
var arg4 = Numberz.FIVE;
long arg5 = 5000000;
Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + ",{" + string.Join(",", tmpMultiDict) + "}," + arg4 + "," + arg5 + ")");
- var multiResponse = await client.testMultiAsync(arg0, arg1, arg2, multiDict, arg4, arg5, MakeTimeoutToken());
+ var multiResponse = await client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5, MakeTimeoutToken());
Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
+ ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");
try
{
Console.WriteLine("testException(\"Xception\")");
- await client.testExceptionAsync("Xception", MakeTimeoutToken());
+ await client.testException("Xception", MakeTimeoutToken());
Console.WriteLine("*** FAILED ***");
returnCode |= ErrorExceptions;
}
@@ -955,7 +955,7 @@ namespace ThriftTest
try
{
Console.WriteLine("testException(\"TException\")");
- await client.testExceptionAsync("TException", MakeTimeoutToken());
+ await client.testException("TException", MakeTimeoutToken());
Console.WriteLine("*** FAILED ***");
returnCode |= ErrorExceptions;
}
@@ -972,7 +972,7 @@ namespace ThriftTest
try
{
Console.WriteLine("testException(\"ok\")");
- await client.testExceptionAsync("ok", MakeTimeoutToken());
+ await client.testException("ok", MakeTimeoutToken());
// OK
}
catch (Exception ex)
@@ -985,7 +985,7 @@ namespace ThriftTest
try
{
Console.WriteLine("testMultiException(\"Xception\", ...)");
- await client.testMultiExceptionAsync("Xception", "ignore", MakeTimeoutToken());
+ await client.testMultiException("Xception", "ignore", MakeTimeoutToken());
Console.WriteLine("*** FAILED ***");
returnCode |= ErrorExceptions;
}
@@ -1006,7 +1006,7 @@ namespace ThriftTest
try
{
Console.WriteLine("testMultiException(\"Xception2\", ...)");
- await client.testMultiExceptionAsync("Xception2", "ignore", MakeTimeoutToken());
+ await client.testMultiException("Xception2", "ignore", MakeTimeoutToken());
Console.WriteLine("*** FAILED ***");
returnCode |= ErrorExceptions;
}
@@ -1027,7 +1027,7 @@ namespace ThriftTest
try
{
Console.WriteLine("testMultiException(\"success\", \"OK\")");
- if ("OK" != (await client.testMultiExceptionAsync("success", "OK", MakeTimeoutToken())).String_thing)
+ if ("OK" != (await client.testMultiException("success", "OK", MakeTimeoutToken())).String_thing)
{
Console.WriteLine("*** FAILED ***");
returnCode |= ErrorExceptions;
@@ -1043,7 +1043,7 @@ namespace ThriftTest
Console.WriteLine("Test Oneway(1)");
var sw = new Stopwatch();
sw.Start();
- await client.testOnewayAsync(1, MakeTimeoutToken());
+ await client.testOneway(1, MakeTimeoutToken());
sw.Stop();
if (sw.ElapsedMilliseconds > 1000)
{
@@ -1057,7 +1057,7 @@ namespace ThriftTest
sw.Start();
var token = MakeTimeoutToken(20000);
for (var k = 0; k < times; ++k)
- await client.testVoidAsync(token);
+ await client.testVoid(token);
sw.Stop();
Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times);
return returnCode;
diff --git a/test/netstd/Server/GlobalSuppressions.cs b/test/netstd/Server/GlobalSuppressions.cs
deleted file mode 100644
index 34fdc79..0000000
--- a/test/netstd/Server/GlobalSuppressions.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-// This file is used by Code Analysis to maintain SuppressMessage
-// attributes that are applied to this project.
-// Project-level suppressions either have no target or are given
-// a specific target and scoped to a namespace, type, member, etc.
-
-using System.Diagnostics.CodeAnalysis;
-
-[assembly: SuppressMessage("Performance", "CA1822", Justification = "<Ausstehend>", Scope = "module")]
-[assembly: SuppressMessage("Style", "IDE0083", Justification = "<Ausstehend>", Scope = "module")]
diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs
index bec9fae..895c3ff 100644
--- a/test/netstd/Server/TestServer.cs
+++ b/test/netstd/Server/TestServer.cs
@@ -35,6 +35,7 @@ using Thrift.Transport;
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
namespace ThriftTest
{
@@ -190,7 +191,7 @@ namespace ThriftTest
{
public TServer Server { get; set; }
private readonly int handlerID;
- private readonly StringBuilder sb = new StringBuilder();
+ private readonly StringBuilder sb = new();
private readonly TestLogDelegate logger;
public TestHandlerAsync()
@@ -209,61 +210,61 @@ namespace ThriftTest
Console.Write(sb.ToString());
}
- public Task testVoidAsync(CancellationToken cancellationToken)
+ public Task testVoid(CancellationToken cancellationToken)
{
logger.Invoke("testVoid()");
return Task.CompletedTask;
}
- public Task<string> testStringAsync(string thing, CancellationToken cancellationToken)
+ public Task<string> testString(string thing, CancellationToken cancellationToken)
{
logger.Invoke("testString({0})", thing);
return Task.FromResult(thing);
}
- public Task<bool> testBoolAsync(bool thing, CancellationToken cancellationToken)
+ public Task<bool> testBool(bool thing, CancellationToken cancellationToken)
{
logger.Invoke("testBool({0})", thing);
return Task.FromResult(thing);
}
- public Task<sbyte> testByteAsync(sbyte thing, CancellationToken cancellationToken)
+ public Task<sbyte> testByte(sbyte thing, CancellationToken cancellationToken)
{
logger.Invoke("testByte({0})", thing);
return Task.FromResult(thing);
}
- public Task<int> testI32Async(int thing, CancellationToken cancellationToken)
+ public Task<int> testI32(int thing, CancellationToken cancellationToken)
{
logger.Invoke("testI32({0})", thing);
return Task.FromResult(thing);
}
- public Task<long> testI64Async(long thing, CancellationToken cancellationToken)
+ public Task<long> testI64(long thing, CancellationToken cancellationToken)
{
logger.Invoke("testI64({0})", thing);
return Task.FromResult(thing);
}
- public Task<double> testDoubleAsync(double thing, CancellationToken cancellationToken)
+ public Task<double> testDouble(double thing, CancellationToken cancellationToken)
{
logger.Invoke("testDouble({0})", thing);
return Task.FromResult(thing);
}
- public Task<byte[]> testBinaryAsync(byte[] thing, CancellationToken cancellationToken)
+ public Task<byte[]> testBinary(byte[] thing, CancellationToken cancellationToken)
{
logger.Invoke("testBinary({0} bytes)", thing.Length);
return Task.FromResult(thing);
}
- public Task<Xtruct> testStructAsync(Xtruct thing, CancellationToken cancellationToken)
+ public Task<Xtruct> 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);
}
- public Task<Xtruct2> testNestAsync(Xtruct2 nest, CancellationToken cancellationToken)
+ public Task<Xtruct2> testNest(Xtruct2 nest, CancellationToken cancellationToken)
{
var thing = nest.Struct_thing;
logger.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})",
@@ -276,7 +277,7 @@ namespace ThriftTest
return Task.FromResult(nest);
}
- public Task<Dictionary<int, int>> testMapAsync(Dictionary<int, int> thing, CancellationToken cancellationToken)
+ public Task<Dictionary<int, int>> testMap(Dictionary<int, int> thing, CancellationToken cancellationToken)
{
sb.Clear();
sb.Append("testMap({{");
@@ -298,7 +299,7 @@ namespace ThriftTest
return Task.FromResult(thing);
}
- public Task<Dictionary<string, string>> testStringMapAsync(Dictionary<string, string> thing, CancellationToken cancellationToken)
+ public Task<Dictionary<string, string>> testStringMap(Dictionary<string, string> thing, CancellationToken cancellationToken)
{
sb.Clear();
sb.Append("testStringMap({{");
@@ -320,7 +321,7 @@ namespace ThriftTest
return Task.FromResult(thing);
}
- public Task<THashSet<int>> testSetAsync(THashSet<int> thing, CancellationToken cancellationToken)
+ public Task<THashSet<int>> testSet(THashSet<int> thing, CancellationToken cancellationToken)
{
sb.Clear();
sb.Append("testSet({{");
@@ -342,7 +343,7 @@ namespace ThriftTest
return Task.FromResult(thing);
}
- public Task<List<int>> testListAsync(List<int> thing, CancellationToken cancellationToken)
+ public Task<List<int>> testList(List<int> thing, CancellationToken cancellationToken)
{
sb.Clear();
sb.Append("testList({{");
@@ -364,19 +365,19 @@ namespace ThriftTest
return Task.FromResult(thing);
}
- public Task<Numberz> testEnumAsync(Numberz thing, CancellationToken cancellationToken)
+ public Task<Numberz> testEnum(Numberz thing, CancellationToken cancellationToken)
{
logger.Invoke("testEnum({0})", thing);
return Task.FromResult(thing);
}
- public Task<long> testTypedefAsync(long thing, CancellationToken cancellationToken)
+ public Task<long> testTypedef(long thing, CancellationToken cancellationToken)
{
logger.Invoke("testTypedef({0})", thing);
return Task.FromResult(thing);
}
- public Task<Dictionary<int, Dictionary<int, int>>> testMapMapAsync(int hello, CancellationToken cancellationToken)
+ public Task<Dictionary<int, Dictionary<int, int>>> testMapMap(int hello, CancellationToken cancellationToken)
{
logger.Invoke("testMapMap({0})", hello);
var mapmap = new Dictionary<int, Dictionary<int, int>>();
@@ -395,7 +396,7 @@ namespace ThriftTest
return Task.FromResult(mapmap);
}
- public Task<Dictionary<long, Dictionary<Numberz, Insanity>>> testInsanityAsync(Insanity argument, CancellationToken cancellationToken)
+ public Task<Dictionary<long, Dictionary<Numberz, Insanity>>> testInsanity(Insanity argument, CancellationToken cancellationToken)
{
logger.Invoke("testInsanity()");
@@ -428,7 +429,7 @@ namespace ThriftTest
return Task.FromResult(insane);
}
- public Task<Xtruct> testMultiAsync(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5,
+ public Task<Xtruct> testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5,
CancellationToken cancellationToken)
{
logger.Invoke("testMulti()");
@@ -441,7 +442,7 @@ namespace ThriftTest
return Task.FromResult(hello);
}
- public Task testExceptionAsync(string arg, CancellationToken cancellationToken)
+ public Task testException(string arg, CancellationToken cancellationToken)
{
logger.Invoke("testException({0})", arg);
if (arg == "Xception")
@@ -460,7 +461,7 @@ namespace ThriftTest
return Task.CompletedTask;
}
- public Task<Xtruct> testMultiExceptionAsync(string arg0, string arg1, CancellationToken cancellationToken)
+ public Task<Xtruct> testMultiException(string arg0, string arg1, CancellationToken cancellationToken)
{
logger.Invoke("testMultiException({0}, {1})", arg0, arg1);
if (arg0 == "Xception")
@@ -487,7 +488,7 @@ namespace ThriftTest
return Task.FromResult(result);
}
- public Task testOnewayAsync(int secondsToSleep, CancellationToken cancellationToken)
+ public Task testOneway(int secondsToSleep, CancellationToken cancellationToken)
{
logger.Invoke("testOneway({0}), sleeping...", secondsToSleep);
Task.Delay(secondsToSleep * 1000, cancellationToken).GetAwaiter().GetResult();
diff --git a/tutorial/netstd/Client/Program.cs b/tutorial/netstd/Client/Program.cs
index f3e93ce..9c47450 100644
--- a/tutorial/netstd/Client/Program.cs
+++ b/tutorial/netstd/Client/Program.cs
@@ -41,7 +41,7 @@ namespace Client
{
public class Program
{
- private static readonly ServiceCollection ServiceCollection = new ServiceCollection();
+ private static readonly ServiceCollection ServiceCollection = new();
private static ILogger Logger;
private static readonly TConfiguration Configuration = null; // new TConfiguration() if needed
@@ -287,17 +287,13 @@ Sample:
private static TProtocol MakeProtocol(string[] args, TTransport transport)
{
Protocol selectedProtocol = GetProtocol(args);
- switch (selectedProtocol)
+ return selectedProtocol switch
{
- case Protocol.Binary:
- return new TBinaryProtocol(transport);
- case Protocol.Compact:
- return new TCompactProtocol(transport);
- case Protocol.Json:
- return new TJsonProtocol(transport);
- default:
- throw new Exception("unhandled protocol");
- }
+ Protocol.Binary => new TBinaryProtocol(transport),
+ Protocol.Compact => new TCompactProtocol(transport),
+ Protocol.Json => new TJsonProtocol(transport),
+ _ => throw new Exception("unhandled protocol"),
+ };
}
private static async Task RunClientAsync(TProtocol protocol, bool multiplex, CancellationToken cancellationToken)
@@ -333,12 +329,12 @@ Sample:
// Async version
- Logger.LogInformation($"{client.ClientId} PingAsync()");
- await client.pingAsync(cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Ping()");
+ await client.ping(cancellationToken);
- Logger.LogInformation($"{client.ClientId} AddAsync(1,1)");
- var sum = await client.addAsync(1, 1, cancellationToken);
- Logger.LogInformation($"{client.ClientId} AddAsync(1,1)={sum}");
+ Logger.LogInformation($"{client.ClientId} Add(1,1)");
+ var sum = await client.add(1, 1, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Add(1,1)={sum}");
var work = new Work
{
@@ -349,8 +345,8 @@ Sample:
try
{
- Logger.LogInformation($"{client.ClientId} CalculateAsync(1)");
- await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Calculate(1)");
+ await client.calculate(1, work, cancellationToken);
Logger.LogInformation($"{client.ClientId} Whoa we can divide by 0");
}
catch (InvalidOperation io)
@@ -364,8 +360,8 @@ Sample:
try
{
- Logger.LogInformation($"{client.ClientId} CalculateAsync(1)");
- var diff = await client.calculateAsync(1, work, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Calculate(1)");
+ var diff = await client.calculate(1, work, cancellationToken);
Logger.LogInformation($"{client.ClientId} 15-10={diff}");
}
catch (InvalidOperation io)
@@ -373,12 +369,12 @@ Sample:
Logger.LogInformation($"{client.ClientId} Invalid operation: " + io);
}
- Logger.LogInformation($"{client.ClientId} GetStructAsync(1)");
- var log = await client.getStructAsync(1, cancellationToken);
+ Logger.LogInformation($"{client.ClientId} GetStruct(1)");
+ var log = await client.getStruct(1, cancellationToken);
Logger.LogInformation($"{client.ClientId} Check log: {log.Value}");
- Logger.LogInformation($"{client.ClientId} ZipAsync() with delay 100mc on server side");
- await client.zipAsync(cancellationToken);
+ Logger.LogInformation($"{client.ClientId} Zip() with delay 100mc on server side");
+ await client.zip(cancellationToken);
}
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
index df8f390..80205d5 100644
--- a/tutorial/netstd/Server/Program.cs
+++ b/tutorial/netstd/Server/Program.cs
@@ -45,7 +45,7 @@ namespace Server
{
public class Program
{
- private static readonly ServiceCollection ServiceCollection = new ServiceCollection();
+ private static readonly ServiceCollection ServiceCollection = new();
private static ILogger Logger;
private static readonly TConfiguration Configuration = null; // new TConfiguration() if needed
@@ -186,55 +186,30 @@ Sample:
private static async Task RunSelectedConfigurationAsync(Transport transport, Buffering buffering, Protocol protocol, bool multiplex, CancellationToken cancellationToken)
{
- TServerTransport serverTransport = null;
- switch (transport)
+ TServerTransport serverTransport = transport switch
{
- case Transport.Tcp:
- serverTransport = new TServerSocketTransport(9090, Configuration);
- break;
- case Transport.NamedPipe:
- serverTransport = new TNamedPipeServerTransport(".test", Configuration);
- break;
- case Transport.TcpTls:
- serverTransport = new TTlsServerSocketTransport(9090, Configuration,
- GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback);
- break;
- }
+ Transport.Tcp => new TServerSocketTransport(9090, Configuration),
+ Transport.NamedPipe => new TNamedPipeServerTransport(".test", Configuration, NamedPipeClientFlags.None),
+ Transport.TcpTls => new TTlsServerSocketTransport(9090, Configuration, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback),
+ _ => throw new ArgumentException("unsupported value $transport", nameof(transport)),
+ };
- TTransportFactory transportFactory = null;
- switch (buffering)
+ TTransportFactory transportFactory = buffering switch
{
- case Buffering.Buffered:
- transportFactory = new TBufferedTransport.Factory();
- break;
-
- case Buffering.Framed:
- transportFactory = new TFramedTransport.Factory();
- break;
-
- default: // layered transport(s) are optional
- Debug.Assert(buffering == Buffering.None, "unhandled case");
- break;
- }
-
- TProtocolFactory protocolFactory = null;
- switch (protocol)
+ Buffering.Buffered => new TBufferedTransport.Factory(),
+ Buffering.Framed => new TFramedTransport.Factory(),
+ // layered transport(s) are optional
+ Buffering.None => null,
+ _ => throw new ArgumentException("unsupported value $buffering", nameof(buffering)),
+ };
+
+ TProtocolFactory protocolFactory = protocol switch
{
- case Protocol.Binary:
- protocolFactory = new TBinaryProtocol.Factory();
- break;
-
- case Protocol.Compact:
- protocolFactory = new TCompactProtocol.Factory();
- break;
-
- case Protocol.Json:
- protocolFactory = new TJsonProtocol.Factory();
- break;
-
- default:
- throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null);
- }
+ Protocol.Binary => new TBinaryProtocol.Factory(),
+ Protocol.Compact => new TCompactProtocol.Factory(),
+ Protocol.Json => new TJsonProtocol.Factory(),
+ _ => throw new ArgumentException("unsupported value $protocol", nameof(protocol)),
+ };
var handler = new CalculatorAsyncHandler();
ITAsyncProcessor processor = new Calculator.AsyncProcessor(handler);
@@ -395,34 +370,34 @@ Sample:
public class CalculatorAsyncHandler : Calculator.IAsync
{
- private readonly Dictionary<int, SharedStruct> _log = new Dictionary<int, SharedStruct>();
+ private readonly Dictionary<int, SharedStruct> _log = new();
public CalculatorAsyncHandler()
{
}
- public async Task<SharedStruct> getStructAsync(int key,
+ public async Task<SharedStruct> getStruct(int key,
CancellationToken cancellationToken)
{
- Logger.LogInformation("GetStructAsync({0})", key);
+ Logger.LogInformation("GetStruct({0})", key);
return await Task.FromResult(_log[key]);
}
- public async Task pingAsync(CancellationToken cancellationToken)
+ public async Task ping(CancellationToken cancellationToken)
{
- Logger.LogInformation("PingAsync()");
+ Logger.LogInformation("Ping()");
await Task.CompletedTask;
}
- public async Task<int> addAsync(int num1, int num2, CancellationToken cancellationToken)
+ public async Task<int> add(int num1, int num2, CancellationToken cancellationToken)
{
- Logger.LogInformation($"AddAsync({num1},{num2})");
+ Logger.LogInformation($"Add({num1},{num2})");
return await Task.FromResult(num1 + num2);
}
- public async Task<int> calculateAsync(int logid, Work w, CancellationToken cancellationToken)
+ public async Task<int> calculate(int logid, Work w, CancellationToken cancellationToken)
{
- Logger.LogInformation($"CalculateAsync({logid}, [{w.Op},{w.Num1},{w.Num2}])");
+ Logger.LogInformation($"Calculate({logid}, [{w.Op},{w.Num1},{w.Num2}])");
int val;
switch (w.Op)
@@ -476,22 +451,22 @@ Sample:
return await Task.FromResult(val);
}
- public async Task zipAsync(CancellationToken cancellationToken)
+ public async Task zip(CancellationToken cancellationToken)
{
- Logger.LogInformation("ZipAsync() with delay 100mc");
+ Logger.LogInformation("Zip() with delay 100mc");
await Task.Delay(100, CancellationToken.None);
}
}
public class SharedServiceAsyncHandler : SharedService.IAsync
{
- public async Task<SharedStruct> getStructAsync(int key, CancellationToken cancellationToken)
+ public async Task<SharedStruct> getStruct(int key, CancellationToken cancellationToken)
{
- Logger.LogInformation("GetStructAsync({0})", key);
+ Logger.LogInformation("GetStruct({0})", key);
return await Task.FromResult(new SharedStruct()
{
Key = key,
- Value = "GetStructAsync"
+ Value = "GetStruct"
});
}
}
[thrift] 01/02: THRIFT-5395 inconsistent treatment of methods
ending in "Async" Client: netstd Patch: Jens Geyer
Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 6228b907e0a01659515e8e4715c70f540fe07589
Author: Jens Geyer <je...@apache.org>
AuthorDate: Fri Apr 9 22:55:11 2021 +0200
THRIFT-5395 inconsistent treatment of methods ending in "Async"
Client: netstd
Patch: Jens Geyer
This closes #2372
---
.../cpp/src/thrift/generate/t_netstd_generator.cc | 25 ++++++----------------
.../Impl/Thrift5253/MyService.cs | 10 +++++++++
.../Thrift5253.thrift | 4 ++++
3 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
index ed766ee..8b1c4c4 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
@@ -88,18 +88,6 @@ t_netstd_generator::t_netstd_generator(t_program* program, const map<string, str
out_dir_base_ = "gen-netstd";
}
-static string correct_function_name_for_async(string const& function_name)
-{
- string const async_end = "Async";
- size_t i = function_name.find(async_end);
- if (i != string::npos)
- {
- return function_name + async_end;
- }
-
- return function_name;
-}
-
/**
* \brief Search and replace "_args" substring in struct name if exist (for C# class naming)
* \param struct_name
@@ -2011,7 +1999,8 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
for (functions_iterator = functions.begin(); functions_iterator != functions.end(); ++functions_iterator)
{
- string function_name = correct_function_name_for_async((*functions_iterator)->get_name());
+ string raw_func_name = (*functions_iterator)->get_name();
+ string function_name = raw_func_name + "Async";
// async
out << indent() << "public async " << function_signature_async(*functions_iterator, "") << endl
@@ -2020,7 +2009,7 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
string argsname = (*functions_iterator)->get_name() + "Args";
- out << indent() << "await OutputProtocol.WriteMessageBeginAsync(new TMessage(\"" << function_name
+ out << indent() << "await OutputProtocol.WriteMessageBeginAsync(new TMessage(\"" << raw_func_name
<< "\", TMessageType." << ((*functions_iterator)->is_oneway() ? "Oneway" : "Call")
<< ", SeqId), cancellationToken);" << endl
<< indent() << endl
@@ -2155,8 +2144,8 @@ void t_netstd_generator::generate_service_server(ostream& out, t_service* tservi
out << indent() << "_logger = logger;" << endl;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter)
{
- string function_name = (*f_iter)->get_name();
- out << indent() << "processMap_[\"" << correct_function_name_for_async(function_name) << "\"] = " << function_name << "_ProcessAsync;" << endl;
+ string raw_func_name = (*f_iter)->get_name();
+ out << indent() << "processMap_[\"" << raw_func_name << "\"] = " << raw_func_name << "_ProcessAsync;" << endl;
}
indent_down();
@@ -2370,7 +2359,7 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service
if (!tfunction->is_oneway())
{
out << indent() << "await oprot.WriteMessageBeginAsync(new TMessage(\""
- << correct_function_name_for_async(tfunction->get_name()) << "\", TMessageType.Reply, seqid), cancellationToken); " << endl
+ << tfunction->get_name() << "\", TMessageType.Reply, seqid), cancellationToken); " << endl
<< indent() << "await result.WriteAsync(oprot, cancellationToken);" << endl;
}
indent_down();
@@ -2404,7 +2393,7 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service
else
{
out << indent() << "var x = new TApplicationException(TApplicationException.ExceptionType.InternalError,\" Internal error.\");" << endl
- << indent() << "await oprot.WriteMessageBeginAsync(new TMessage(\"" << correct_function_name_for_async(tfunction->get_name())
+ << indent() << "await oprot.WriteMessageBeginAsync(new TMessage(\"" << tfunction->get_name()
<< "\", TMessageType.Exception, seqid), cancellationToken);" << endl
<< indent() << "await x.WriteAsync(oprot, cancellationToken);" << endl;
indent_down();
diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs
index 342dd4a..1b8d99f 100644
--- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs
+++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs
@@ -51,6 +51,16 @@ namespace Thrift.PublicInterfaces.Compile.Tests.Impl.Thrift5253
return Task.FromResult(new InternalStructs() { Foo = input.Foo });
}
+ public Task TestAsyncAsync(CancellationToken cancellationToken = default)
+ {
+ return Task.CompletedTask;
+ }
+
+ public Task TestXsyncAsync(CancellationToken cancellationToken = default)
+ {
+ return Task.CompletedTask;
+ }
+
public Task<WorksRslt> WorksAsync(WorksArrrgs input, CancellationToken cancellationToken = default)
{
return Task.FromResult(new WorksRslt() { Foo = input.Foo });
diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift
index ee3df9b..224ac85 100644
--- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift
+++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift
@@ -42,5 +42,9 @@ service MyService{
AsyncProcessor AsyncProcessor ( 1: AsyncProcessor foo)
Client Client ( 1: Client foo)
IAsync IAsync ( 1: IAsync foo)
+
+ // inconsistent treatment of methods ending in "Async"
+ void TestXsync()
+ void TestAsync()
}