http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs b/lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs index bc36bb3..16754b2 100644 --- a/lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs +++ b/lib/netcore/Thrift/Transports/Client/THttpClientTransport.cs @@ -16,11 +16,9 @@ // under the License. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Security.Cryptography.X509Certificates; @@ -198,7 +196,7 @@ namespace Thrift.Transports.Client { throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString()); } - catch (WebException wx) + catch (HttpRequestException wx) { throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Client/TSocketClientTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Client/TSocketClientTransport.cs b/lib/netcore/Thrift/Transports/Client/TSocketClientTransport.cs index a44efe6..e769d14 100644 --- a/lib/netcore/Thrift/Transports/Client/TSocketClientTransport.cs +++ b/lib/netcore/Thrift/Transports/Client/TSocketClientTransport.cs @@ -30,12 +30,7 @@ namespace Thrift.Transports.Client public TSocketClientTransport(TcpClient client) { - if (client == null) - { - throw new ArgumentNullException(nameof(client)); - } - - TcpClient = client; + TcpClient = client ?? throw new ArgumentNullException(nameof(client)); if (IsOpen) { http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Client/TTlsSocketClientTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Client/TTlsSocketClientTransport.cs b/lib/netcore/Thrift/Transports/Client/TTlsSocketClientTransport.cs index a21977b..c8be4ed 100644 --- a/lib/netcore/Thrift/Transports/Client/TTlsSocketClientTransport.cs +++ b/lib/netcore/Thrift/Transports/Client/TTlsSocketClientTransport.cs @@ -1,4 +1,4 @@ -// Licensed to the Apache Software Foundation(ASF) under one +// 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 @@ -57,7 +57,7 @@ namespace Thrift.Transports.Client if (isServer && certificate == null) { throw new ArgumentException("TTlsSocketClientTransport needs certificate to be used for server", - "certificate"); + nameof(certificate)); } if (IsOpen) @@ -204,7 +204,8 @@ namespace Thrift.Transports.Client ? new X509CertificateCollection {_certificate} : new X509CertificateCollection(); - await _secureStream.AuthenticateAsClientAsync(_host.ToString(), certs, _sslProtocols, true); + var targetHost = _host.ToString(); + await _secureStream.AuthenticateAsClientAsync(targetHost, certs, _sslProtocols, true); } } catch (Exception) http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Server/THttpServerTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Server/THttpServerTransport.cs b/lib/netcore/Thrift/Transports/Server/THttpServerTransport.cs index 6073741..032063a 100644 --- a/lib/netcore/Thrift/Transports/Server/THttpServerTransport.cs +++ b/lib/netcore/Thrift/Transports/Server/THttpServerTransport.cs @@ -53,29 +53,14 @@ namespace Thrift.Transports.Server public THttpServerTransport(ITAsyncProcessor processor, ITProtocolFactory inputProtocolFactory, ITProtocolFactory outputProtocolFactory, RequestDelegate next, ILoggerFactory loggerFactory) { - if (processor == null) - { - throw new ArgumentNullException(nameof(processor)); - } - - if (inputProtocolFactory == null) - { - throw new ArgumentNullException(nameof(inputProtocolFactory)); - } - - if (outputProtocolFactory == null) - { - throw new ArgumentNullException(nameof(outputProtocolFactory)); - } - if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } - Processor = processor; - InputProtocolFactory = inputProtocolFactory; - OutputProtocolFactory = outputProtocolFactory; + Processor = processor ?? throw new ArgumentNullException(nameof(processor)); + InputProtocolFactory = inputProtocolFactory ?? throw new ArgumentNullException(nameof(inputProtocolFactory)); + OutputProtocolFactory = outputProtocolFactory ?? throw new ArgumentNullException(nameof(outputProtocolFactory)); _next = next; _logger = loggerFactory.CreateLogger<THttpServerTransport>(); http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Server/TNamedPipeServerTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Server/TNamedPipeServerTransport.cs b/lib/netcore/Thrift/Transports/Server/TNamedPipeServerTransport.cs index 01195d4..186786e 100644 --- a/lib/netcore/Thrift/Transports/Server/TNamedPipeServerTransport.cs +++ b/lib/netcore/Thrift/Transports/Server/TNamedPipeServerTransport.cs @@ -1,4 +1,4 @@ -// Licensed to the Apache Software Foundation(ASF) under one +// 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 http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Server/TServerSocketTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Server/TServerSocketTransport.cs b/lib/netcore/Thrift/Transports/Server/TServerSocketTransport.cs index af154ef..3a9d8a1 100644 --- a/lib/netcore/Thrift/Transports/Server/TServerSocketTransport.cs +++ b/lib/netcore/Thrift/Transports/Server/TServerSocketTransport.cs @@ -30,6 +30,7 @@ namespace Thrift.Transports.Server private readonly int _clientTimeout; private readonly int _port; private readonly bool _useBufferedSockets; + private readonly bool _useFramedTransport; private TcpListener _server; public TServerSocketTransport(TcpListener listener) @@ -53,11 +54,17 @@ namespace Thrift.Transports.Server { } - public TServerSocketTransport(int port, int clientTimeout, bool useBufferedSockets) + public TServerSocketTransport(int port, int clientTimeout, bool useBufferedSockets): + this(port, clientTimeout, useBufferedSockets, false) + { + } + + public TServerSocketTransport(int port, int clientTimeout, bool useBufferedSockets, bool useFramedTransport) { _port = port; _clientTimeout = clientTimeout; _useBufferedSockets = useBufferedSockets; + _useFramedTransport = useFramedTransport; try { // Make server socket @@ -106,7 +113,7 @@ namespace Thrift.Transports.Server try { - TSocketClientTransport tSocketTransport = null; + TClientTransport tSocketTransport = null; var tcpClient = await _server.AcceptTcpClientAsync(); try @@ -118,7 +125,12 @@ namespace Thrift.Transports.Server if (_useBufferedSockets) { - return new TBufferedClientTransport(tSocketTransport); + tSocketTransport = new TBufferedClientTransport(tSocketTransport); + } + + if (_useFramedTransport) + { + tSocketTransport = new TFramedClientTransport(tSocketTransport); } return tSocketTransport; http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/Server/TTlsServerSocketTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/Server/TTlsServerSocketTransport.cs b/lib/netcore/Thrift/Transports/Server/TTlsServerSocketTransport.cs index 49abdac..759feed 100644 --- a/lib/netcore/Thrift/Transports/Server/TTlsServerSocketTransport.cs +++ b/lib/netcore/Thrift/Transports/Server/TTlsServerSocketTransport.cs @@ -37,6 +37,7 @@ namespace Thrift.Transports.Server private readonly X509Certificate2 _serverCertificate; private readonly SslProtocols _sslProtocols; private readonly bool _useBufferedSockets; + private readonly bool _useFramedTransport; private TcpListener _server; public TTlsServerSocketTransport(int port, X509Certificate2 certificate) @@ -50,6 +51,19 @@ namespace Thrift.Transports.Server X509Certificate2 certificate, RemoteCertificateValidationCallback clientCertValidator = null, LocalCertificateSelectionCallback localCertificateSelectionCallback = null, + SslProtocols sslProtocols = SslProtocols.Tls12) + : this(port, useBufferedSockets, false, certificate, + clientCertValidator, localCertificateSelectionCallback, sslProtocols) + { + } + + public TTlsServerSocketTransport( + int port, + bool useBufferedSockets, + bool useFramedTransport, + X509Certificate2 certificate, + RemoteCertificateValidationCallback clientCertValidator = null, + LocalCertificateSelectionCallback localCertificateSelectionCallback = null, SslProtocols sslProtocols = SslProtocols.Tls12) { if (!certificate.HasPrivateKey) @@ -61,6 +75,7 @@ namespace Thrift.Transports.Server _port = port; _serverCertificate = certificate; _useBufferedSockets = useBufferedSockets; + _useFramedTransport = useFramedTransport; _clientCertValidator = clientCertValidator; _localCertificateSelectionCallback = localCertificateSelectionCallback; _sslProtocols = sslProtocols; @@ -122,13 +137,19 @@ namespace Thrift.Transports.Server await tTlsSocket.SetupTlsAsync(); + TClientTransport trans = tTlsSocket; + if (_useBufferedSockets) { - var trans = new TBufferedClientTransport(tTlsSocket); - return trans; + trans = new TBufferedClientTransport(trans); } - return tTlsSocket; + if (_useFramedTransport) + { + trans = new TFramedClientTransport(trans); + } + + return trans; } catch (Exception ex) { http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/TClientTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/TClientTransport.cs b/lib/netcore/Thrift/Transports/TClientTransport.cs index cee0a00..0dd96cb 100644 --- a/lib/netcore/Thrift/Transports/TClientTransport.cs +++ b/lib/netcore/Thrift/Transports/TClientTransport.cs @@ -1,4 +1,4 @@ -// Licensed to the Apache Software Foundation(ASF) under one +// 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 @@ -26,6 +26,7 @@ namespace Thrift.Transports // ReSharper disable once InconsistentNaming public abstract class TClientTransport : IDisposable { + //TODO: think how to avoid peek byte private readonly byte[] _peekBuffer = new byte[1]; private bool _hasPeekByte; public abstract bool IsOpen { get; } http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/Thrift/Transports/TServerTransport.cs ---------------------------------------------------------------------- diff --git a/lib/netcore/Thrift/Transports/TServerTransport.cs b/lib/netcore/Thrift/Transports/TServerTransport.cs index d49feb6..0d45a55 100644 --- a/lib/netcore/Thrift/Transports/TServerTransport.cs +++ b/lib/netcore/Thrift/Transports/TServerTransport.cs @@ -45,7 +45,7 @@ namespace Thrift.Transports if (transport == null) { - throw new TTransportException("AcceptAsync() should not return null"); + throw new TTransportException($"{nameof(AcceptImplementationAsync)} should not return null"); } return transport; http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/build.cmd ---------------------------------------------------------------------- diff --git a/lib/netcore/build.cmd b/lib/netcore/build.cmd new file mode 100644 index 0000000..863c4b4 --- /dev/null +++ b/lib/netcore/build.cmd @@ -0,0 +1,27 @@ +@echo off +rem /* +rem * Licensed to the Apache Software Foundation (ASF) under one +rem * or more contributor license agreements. See the NOTICE file +rem * distributed with this work for additional information +rem * regarding copyright ownership. The ASF licenses this file +rem * to you under the Apache License, Version 2.0 (the +rem * "License"); you may not use this file except in compliance +rem * with the License. You may obtain a copy of the License at +rem * +rem * http://www.apache.org/licenses/LICENSE-2.0 +rem * +rem * Unless required by applicable law or agreed to in writing, +rem * software distributed under the License is distributed on an +rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +rem * KIND, either express or implied. See the License for the +rem * specific language governing permissions and limitations +rem * under the License. +rem */ + +setlocal + +thrift -version +dotnet --info +dotnet build + +:eof http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/build.sh ---------------------------------------------------------------------- diff --git a/lib/netcore/build.sh b/lib/netcore/build.sh new file mode 100644 index 0000000..ae18bce --- /dev/null +++ b/lib/netcore/build.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# +# 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. +# + +#exit if any command fails +#set -e + +thrift --version +dotnet --info +dotnet build + +#revision=${TRAVIS_JOB_ID:=1} +#revision=$(printf "%04d" $revision) + +#dotnet pack ./src/PROJECT_NAME -c Release -o ./artifacts --version-suffix=$revision http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/runtests.cmd ---------------------------------------------------------------------- diff --git a/lib/netcore/runtests.cmd b/lib/netcore/runtests.cmd new file mode 100644 index 0000000..5114bc5 --- /dev/null +++ b/lib/netcore/runtests.cmd @@ -0,0 +1,28 @@ +@echo off +rem /* +rem * Licensed to the Apache Software Foundation (ASF) under one +rem * or more contributor license agreements. See the NOTICE file +rem * distributed with this work for additional information +rem * regarding copyright ownership. The ASF licenses this file +rem * to you under the Apache License, Version 2.0 (the +rem * "License"); you may not use this file except in compliance +rem * with the License. You may obtain a copy of the License at +rem * +rem * http://www.apache.org/licenses/LICENSE-2.0 +rem * +rem * Unless required by applicable law or agreed to in writing, +rem * software distributed under the License is distributed on an +rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +rem * KIND, either express or implied. See the License for the +rem * specific language governing permissions and limitations +rem * under the License. +rem */ +setlocal + +thrift -version +dotnet --info + +dotnet test Tests\Thrift.IntegrationTests\Thrift.IntegrationTests.csproj +dotnet test Tests\Thrift.Tests\Thrift.Tests.csproj + +:eof http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/lib/netcore/runtests.sh ---------------------------------------------------------------------- diff --git a/lib/netcore/runtests.sh b/lib/netcore/runtests.sh new file mode 100644 index 0000000..a26cc36 --- /dev/null +++ b/lib/netcore/runtests.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# +# 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. +# + +thrift -version +dotnet --info + +dotnet test Tests\Thrift.IntegrationTests\Thrift.IntegrationTests.csproj +dotnet test Tests\Thrift.Tests\Thrift.Tests.csproj \ No newline at end of file http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/ThriftTest.thrift ---------------------------------------------------------------------- diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift index 24dcbb9..bff4e52 100644 --- a/test/ThriftTest.thrift +++ b/test/ThriftTest.thrift @@ -37,7 +37,7 @@ namespace delphi Thrift.Test namespace cocoa ThriftTest namespace lua ThriftTest namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest') -namespace netcore ThriftAsync.Test +namespace netcore ThriftTest // Presence of namespaces and sub-namespaces for which there is // no generator should compile with warnings only http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/csharp/TestClient.cs ---------------------------------------------------------------------- diff --git a/test/csharp/TestClient.cs b/test/csharp/TestClient.cs index 17e5978..949c06e 100644 --- a/test/csharp/TestClient.cs +++ b/test/csharp/TestClient.cs @@ -62,7 +62,9 @@ namespace Test { string certPath = "../keys/client.p12"; X509Certificate cert = new X509Certificate2(certPath, "thrift"); - trans = new TTLSSocket(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls); + trans = new TTLSSocket(host, port, 0, cert, + (o, c, chain, errors) => true, + null, SslProtocols.Tls); } else { http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/csharp/TestServer.cs ---------------------------------------------------------------------- diff --git a/test/csharp/TestServer.cs b/test/csharp/TestServer.cs index e9c7168..bf645c2 100644 --- a/test/csharp/TestServer.cs +++ b/test/csharp/TestServer.cs @@ -455,7 +455,9 @@ namespace Test if (useEncryption) { string certPath = "../keys/server.p12"; - trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift"), null, null, SslProtocols.Tls); + trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift"), + null, + null, SslProtocols.Tls); } else { http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/features/known_failures_Linux.json ---------------------------------------------------------------------- diff --git a/test/features/known_failures_Linux.json b/test/features/known_failures_Linux.json index f96356d..6d1ed1f 100644 --- a/test/features/known_failures_Linux.json +++ b/test/features/known_failures_Linux.json @@ -1,46 +1,48 @@ [ - "c_glib-limit_container_length_binary_buffered-ip", - "c_glib-limit_string_length_binary_buffered-ip", - "cpp-theader_framed_binary_multih-header_buffered-ip", - "cpp-theader_framed_compact_multih-header_buffered-ip", - "cpp-theader_unframed_binary_multih-header_buffered-ip", - "cpp-theader_unframed_compact_multih-header_buffered-ip", - "csharp-limit_container_length_binary_buffered-ip", - "csharp-limit_container_length_compact_buffered-ip", - "csharp-limit_string_length_binary_buffered-ip", - "csharp-limit_string_length_compact_buffered-ip", - "d-limit_container_length_binary_buffered-ip", - "d-limit_container_length_compact_buffered-ip", - "d-limit_string_length_binary_buffered-ip", - "d-limit_string_length_compact_buffered-ip", - "erl-limit_container_length_binary_buffered-ip", - "erl-limit_container_length_compact_buffered-ip", - "erl-limit_string_length_binary_buffered-ip", - "erl-limit_string_length_compact_buffered-ip", - "go-limit_container_length_binary_buffered-ip", - "go-limit_container_length_compact_buffered-ip", - "go-limit_string_length_binary_buffered-ip", - "go-limit_string_length_compact_buffered-ip", - "hs-limit_container_length_binary_buffered-ip", - "hs-limit_container_length_compact_buffered-ip", - "hs-limit_string_length_binary_buffered-ip", - "hs-limit_string_length_compact_buffered-ip", - "nodejs-limit_container_length_binary_buffered-ip", - "nodejs-limit_container_length_compact_buffered-ip", - "nodejs-limit_string_length_binary_buffered-ip", - "nodejs-limit_string_length_compact_buffered-ip", - "perl-limit_container_length_binary_buffered-ip", - "perl-limit_string_length_binary_buffered-ip", - "rb-limit_container_length_accel-binary_buffered-ip", - "rb-limit_container_length_binary_buffered-ip", - "rb-limit_container_length_compact_buffered-ip", - "rb-limit_string_length_accel-binary_buffered-ip", - "rb-limit_string_length_binary_buffered-ip", - "rb-limit_string_length_compact_buffered-ip", - "rs-limit_container_length_binary_buffered-ip", - "rs-limit_container_length_compact_buffered-ip", - "rs-limit_container_length_multic-compact_buffered-ip", - "rs-limit_string_length_binary_buffered-ip", - "rs-limit_string_length_compact_buffered-ip", - "rs-limit_string_length_multic-compact_buffered-ip" + "c_glib-limit_container_length_binary_buffered-ip", + "c_glib-limit_string_length_binary_buffered-ip", + "cpp-theader_framed_binary_multih-header_buffered-ip", + "cpp-theader_framed_compact_multih-header_buffered-ip", + "cpp-theader_unframed_binary_multih-header_buffered-ip", + "cpp-theader_unframed_compact_multih-header_buffered-ip", + "csharp-limit_container_length_binary_buffered-ip", + "csharp-limit_container_length_compact_buffered-ip", + "csharp-limit_string_length_binary_buffered-ip", + "csharp-limit_string_length_compact_buffered-ip", + "d-limit_container_length_binary_buffered-ip", + "d-limit_container_length_compact_buffered-ip", + "d-limit_string_length_binary_buffered-ip", + "d-limit_string_length_compact_buffered-ip", + "erl-limit_container_length_binary_buffered-ip", + "erl-limit_container_length_compact_buffered-ip", + "erl-limit_string_length_binary_buffered-ip", + "erl-limit_string_length_compact_buffered-ip", + "go-limit_container_length_binary_buffered-ip", + "go-limit_container_length_compact_buffered-ip", + "go-limit_string_length_binary_buffered-ip", + "go-limit_string_length_compact_buffered-ip", + "hs-limit_container_length_binary_buffered-ip", + "hs-limit_container_length_compact_buffered-ip", + "hs-limit_string_length_binary_buffered-ip", + "hs-limit_string_length_compact_buffered-ip", + "nodejs-limit_container_length_binary_buffered-ip", + "nodejs-limit_container_length_compact_buffered-ip", + "nodejs-limit_string_length_binary_buffered-ip", + "nodejs-limit_string_length_compact_buffered-ip", + "perl-limit_container_length_binary_buffered-ip", + "perl-limit_string_length_binary_buffered-ip", + "rb-limit_container_length_accel-binary_buffered-ip", + "rb-limit_container_length_binary_buffered-ip", + "rb-limit_container_length_compact_buffered-ip", + "rb-limit_string_length_accel-binary_buffered-ip", + "rb-limit_string_length_binary_buffered-ip", + "rb-limit_string_length_compact_buffered-ip", + "rs-limit_container_length_binary_buffered-ip", + "rs-limit_container_length_compact_buffered-ip", + "rs-limit_container_length_multic-compact_buffered-ip", + "rs-limit_string_length_binary_buffered-ip", + "rs-limit_string_length_compact_buffered-ip", + "rs-limit_string_length_multic-compact_buffered-ip", + "netcore-limit_string_length_compact_buffered-ip", + "netcore-limit_container_length_compact_buffered-ip" ] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/known_failures_Linux.json ---------------------------------------------------------------------- diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json index 658577d..a142796 100644 --- a/test/known_failures_Linux.json +++ b/test/known_failures_Linux.json @@ -215,6 +215,12 @@ "java-d_compact_buffered-ip", "java-d_compact_buffered-ip-ssl", "java-d_compact_framed-ip", + "netcore-csharp_binary_buffered-ip-ssl", + "netcore-csharp_binary_framed-ip-ssl", + "netcore-csharp_json_framed-ip-ssl", + "netcore-csharp_json_buffered-ip-ssl", + "netcore-csharp_compact_buffered-ip-ssl", + "netcore-csharp_compact_framed-ip-ssl", "nodejs-cpp_binary_http-ip", "nodejs-cpp_binary_http-ip-ssl", "nodejs-cpp_compact_http-ip", http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Client/.gitignore ---------------------------------------------------------------------- diff --git a/test/netcore/Client/.gitignore b/test/netcore/Client/.gitignore new file mode 100644 index 0000000..67d5510 --- /dev/null +++ b/test/netcore/Client/.gitignore @@ -0,0 +1,2 @@ +# ignore for autogenerated files +/ThriftTest http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Client/Client.csproj ---------------------------------------------------------------------- diff --git a/test/netcore/Client/Client.csproj b/test/netcore/Client/Client.csproj new file mode 100644 index 0000000..4b31a7d --- /dev/null +++ b/test/netcore/Client/Client.csproj @@ -0,0 +1,31 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>netcoreapp2.0</TargetFramework> + <AssemblyName>Client</AssemblyName> + <PackageId>Client</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="System.Net.Http.WinHttpHandler" Version="[4.4,)" /> + <PackageReference Include="System.Runtime.Serialization.Primitives" Version="[4.3,)" /> + <PackageReference Include="System.ServiceModel.Primitives" Version="[4.4,)" /> + <PackageReference Include="System.Threading" Version="[4.3,)" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\lib\netcore\Thrift\Thrift.csproj" /> + </ItemGroup> + <Target Name="PreBuild" BeforeTargets="_GenerateRestoreProjectSpec;Restore;Compile"> + <Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true"> + <Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" /> + </Exec> + <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r ./../../ThriftTest.thrift" /> + <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r ./../../ThriftTest.thrift" /> + <Exec Condition="Exists('$(ProjectDir)/../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../compiler/cpp/thrift -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r ./../../ThriftTest.thrift" /> + </Target> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Client/Program.cs ---------------------------------------------------------------------- diff --git a/test/netcore/Client/Program.cs b/test/netcore/Client/Program.cs new file mode 100644 index 0000000..72139d9 --- /dev/null +++ b/test/netcore/Client/Program.cs @@ -0,0 +1,72 @@ +// 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.Collections.Generic; +using ThriftTest; + +namespace Client +{ + public class Program + { + public static int Main(string[] args) + { + try + { + Console.SetBufferSize(Console.BufferWidth, 4096); + } + catch (Exception) + { + Console.WriteLine("Failed to grow scroll-back buffer"); + } + + // split mode and options + var subArgs = new List<string>(args); + var firstArg = string.Empty; + if (subArgs.Count > 0) + { + firstArg = subArgs[0]; + subArgs.RemoveAt(0); + } + + // run whatever mode is choosen + switch(firstArg) + { + case "client": + return TestClient.Execute(subArgs); + case "--help": + PrintHelp(); + return 0; + default: + PrintHelp(); + return -1; + } + } + + private static void PrintHelp() + { + Console.WriteLine("Usage:"); + Console.WriteLine(" Client client [options]'"); + Console.WriteLine(" Client --help"); + Console.WriteLine(""); + + TestClient.PrintOptionsHelp(); + } + } +} + + http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Client/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/test/netcore/Client/Properties/AssemblyInfo.cs b/test/netcore/Client/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..157152b --- /dev/null +++ b/test/netcore/Client/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// 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.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("The Apache Software Foundation")] +[assembly: AssemblyProduct("Thrift")] +[assembly: AssemblyCopyright("The Apache Software Foundation")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("B0C13DA0-3117-4844-8AE8-B1775E46223D")] + http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Client/TestClient.cs ---------------------------------------------------------------------- diff --git a/test/netcore/Client/TestClient.cs b/test/netcore/Client/TestClient.cs new file mode 100644 index 0000000..8be198c --- /dev/null +++ b/test/netcore/Client/TestClient.cs @@ -0,0 +1,943 @@ +// 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.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using System.ServiceModel; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Thrift.Collections; +using Thrift.Protocols; +using Thrift.Transports; +using Thrift.Transports.Client; + +namespace ThriftTest +{ + public class TestClient + { + private class TestParams + { + public int numIterations = 1; + public IPAddress host = IPAddress.Any; + public int port = 9090; + public int numThreads = 1; + public string url; + public string pipe; + public bool buffered; + public bool framed; + public string protocol; + public bool encrypted = false; + + internal void Parse( List<string> args) + { + for (var i = 0; i < args.Count; ++i) + { + if (args[i] == "-u") + { + url = args[++i]; + } + else if (args[i] == "-n") + { + numIterations = Convert.ToInt32(args[++i]); + } + else if (args[i].StartsWith("--pipe=")) + { + pipe = args[i].Substring(args[i].IndexOf("=") + 1); + Console.WriteLine("Using named pipes transport"); + } + else if (args[i].StartsWith("--host=")) + { + // check there for ipaddress + host = new IPAddress(Encoding.Unicode.GetBytes(args[i].Substring(args[i].IndexOf("=") + 1))); + } + else if (args[i].StartsWith("--port=")) + { + port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1)); + } + else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") + { + buffered = true; + Console.WriteLine("Using buffered sockets"); + } + else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") + { + framed = true; + Console.WriteLine("Using framed transport"); + } + else if (args[i] == "-t") + { + numThreads = Convert.ToInt32(args[++i]); + } + else if (args[i] == "--binary" || args[i] == "--protocol=binary") + { + protocol = "binary"; + Console.WriteLine("Using binary protocol"); + } + else if (args[i] == "--compact" || args[i] == "--protocol=compact") + { + protocol = "compact"; + Console.WriteLine("Using compact protocol"); + } + else if (args[i] == "--json" || args[i] == "--protocol=json") + { + protocol = "json"; + Console.WriteLine("Using JSON protocol"); + } + else if (args[i] == "--ssl") + { + encrypted = true; + Console.WriteLine("Using encrypted transport"); + } + else + { + //throw new ArgumentException(args[i]); + } + } + } + + private static X509Certificate2 GetClientCert() + { + var clientCertName = "client.p12"; + var possiblePaths = new List<string> + { + "../../../keys/", + "../../keys/", + "../keys/", + "keys/", + }; + + string existingPath = null; + foreach (var possiblePath in possiblePaths) + { + var path = Path.GetFullPath(possiblePath + clientCertName); + if (File.Exists(path)) + { + existingPath = path; + break; + } + } + + if (string.IsNullOrEmpty(existingPath)) + { + throw new FileNotFoundException($"Cannot find file: {clientCertName}"); + } + + var cert = new X509Certificate2(existingPath, "thrift"); + + return cert; + } + + public TClientTransport CreateTransport() + { + if (url == null) + { + // endpoint transport + TClientTransport trans = null; + + if (pipe != null) + { + trans = new TNamedPipeClientTransport(pipe); + } + else + { + if (encrypted) + { + var cert = GetClientCert(); + + if (cert == null || !cert.HasPrivateKey) + { + throw new InvalidOperationException("Certificate doesn't contain private key"); + } + + trans = new TTlsSocketClientTransport(host, port, 0, cert, + (sender, certificate, chain, errors) => true, + null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12); + } + else + { + trans = new TSocketClientTransport(host, port); + } + } + + // layered transport + if (buffered) + { + trans = new TBufferedClientTransport(trans); + } + + if (framed) + { + trans = new TFramedClientTransport(trans); + } + + return trans; + } + + return new THttpClientTransport(new Uri(url), null); + } + + public TProtocol CreateProtocol(TClientTransport transport) + { + if (protocol == "compact") + { + return new TCompactProtocol(transport); + } + + if (protocol == "json") + { + return new TJsonProtocol(transport); + } + + return new TBinaryProtocol(transport); + } + } + + + private const int ErrorBaseTypes = 1; + private const int ErrorStructs = 2; + private const int ErrorContainers = 4; + private const int ErrorExceptions = 8; + private const int ErrorUnknown = 64; + + private class ClientTest + { + private readonly TClientTransport transport; + private readonly ThriftTest.Client client; + private readonly int numIterations; + private bool done; + + public int ReturnCode { get; set; } + + public ClientTest(TestParams param) + { + transport = param.CreateTransport(); + client = new ThriftTest.Client(param.CreateProtocol(transport)); + numIterations = param.numIterations; + } + + public void Execute() + { + var token = CancellationToken.None; + + if (done) + { + Console.WriteLine("Execute called more than once"); + throw new InvalidOperationException(); + } + + for (var i = 0; i < numIterations; i++) + { + try + { + if (!transport.IsOpen) + { + transport.OpenAsync(token).GetAwaiter().GetResult(); + } + } + catch (TTransportException ex) + { + Console.WriteLine("*** FAILED ***"); + Console.WriteLine("Connect failed: " + ex.Message); + ReturnCode |= ErrorUnknown; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + continue; + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + Console.WriteLine("Connect failed: " + ex.Message); + ReturnCode |= ErrorUnknown; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + continue; + } + + try + { + ReturnCode |= ExecuteClientTestAsync(client).GetAwaiter().GetResult(); ; + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + ReturnCode |= ErrorUnknown; + } + } + try + { + transport.Close(); + } + catch (Exception ex) + { + Console.WriteLine("Error while closing transport"); + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + done = true; + } + } + + internal static void PrintOptionsHelp() + { + Console.WriteLine("Client options:"); + Console.WriteLine(" -u <URL>"); + Console.WriteLine(" -t <# of threads to run> default = 1"); + Console.WriteLine(" -n <# of iterations> per thread"); + Console.WriteLine(" --pipe=<pipe name>"); + Console.WriteLine(" --host=<IP address>"); + Console.WriteLine(" --port=<port number>"); + Console.WriteLine(" --transport=<transport name> one of buffered,framed (defaults to none)"); + Console.WriteLine(" --protocol=<protocol name> one of compact,json (defaults to binary)"); + Console.WriteLine(" --ssl"); + Console.WriteLine(); + } + + public static int Execute(List<string> args) + { + try + { + var param = new TestParams(); + + try + { + param.Parse(args); + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + Console.WriteLine("Error while parsing arguments"); + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + return ErrorUnknown; + } + + var tests = Enumerable.Range(0, param.numThreads).Select(_ => new ClientTest(param)).ToArray(); + + //issue tests on separate threads simultaneously + var threads = tests.Select(test => new Task(test.Execute)).ToArray(); + var start = DateTime.Now; + foreach (var t in threads) + { + t.Start(); + } + + Task.WaitAll(threads); + + Console.WriteLine("Total time: " + (DateTime.Now - start)); + Console.WriteLine(); + return tests.Select(t => t.ReturnCode).Aggregate((r1, r2) => r1 | r2); + } + catch (Exception outerEx) + { + Console.WriteLine("*** FAILED ***"); + Console.WriteLine("Unexpected error"); + Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace); + return ErrorUnknown; + } + } + + public static string BytesToHex(byte[] data) + { + return BitConverter.ToString(data).Replace("-", string.Empty); + } + + public static byte[] PrepareTestData(bool randomDist) + { + var retval = new byte[0x100]; + var initLen = Math.Min(0x100, retval.Length); + + // linear distribution, unless random is requested + if (!randomDist) + { + for (var i = 0; i < initLen; ++i) + { + retval[i] = (byte)i; + } + return retval; + } + + // random distribution + for (var i = 0; i < initLen; ++i) + { + retval[i] = (byte)0; + } + var rnd = new Random(); + for (var i = 1; i < initLen; ++i) + { + while (true) + { + var nextPos = rnd.Next() % initLen; + if (retval[nextPos] == 0) + { + retval[nextPos] = (byte)i; + break; + } + } + } + return retval; + } + + public static async Task<int> ExecuteClientTestAsync(ThriftTest.Client client) + { + var token = CancellationToken.None; + var returnCode = 0; + + Console.Write("testVoid()"); + await client.testVoidAsync(token); + Console.WriteLine(" = void"); + + Console.Write("testString(\"Test\")"); + var s = await client.testStringAsync("Test", token); + Console.WriteLine(" = \"" + s + "\""); + if ("Test" != s) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + Console.Write("testBool(true)"); + var t = await client.testBoolAsync((bool)true, token); + Console.WriteLine(" = " + t); + if (!t) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + Console.Write("testBool(false)"); + var f = await client.testBoolAsync((bool)false, token); + Console.WriteLine(" = " + f); + if (f) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + Console.Write("testByte(1)"); + var i8 = await client.testByteAsync((sbyte)1, token); + Console.WriteLine(" = " + i8); + if (1 != i8) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + Console.Write("testI32(-1)"); + var i32 = await client.testI32Async(-1, token); + Console.WriteLine(" = " + i32); + if (-1 != i32) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + Console.Write("testI64(-34359738368)"); + var i64 = await client.testI64Async(-34359738368, token); + Console.WriteLine(" = " + i64); + if (-34359738368 != i64) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + // TODO: Validate received message + Console.Write("testDouble(5.325098235)"); + var dub = await client.testDoubleAsync(5.325098235, token); + Console.WriteLine(" = " + dub); + if (5.325098235 != dub) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + Console.Write("testDouble(-0.000341012439638598279)"); + dub = await client.testDoubleAsync(-0.000341012439638598279, token); + Console.WriteLine(" = " + dub); + if (-0.000341012439638598279 != dub) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + var binOut = PrepareTestData(true); + Console.Write("testBinary(" + BytesToHex(binOut) + ")"); + try + { + var binIn = await client.testBinaryAsync(binOut, token); + Console.WriteLine(" = " + BytesToHex(binIn)); + if (binIn.Length != binOut.Length) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + for (var ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs) + if (binIn[ofs] != binOut[ofs]) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + } + catch (Thrift.TApplicationException ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + + // binary equals? only with hashcode option enabled ... + Console.WriteLine("Test CrazyNesting"); + var one = new CrazyNesting(); + var two = new CrazyNesting(); + one.String_field = "crazy"; + two.String_field = "crazy"; + one.Binary_field = new byte[] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; + two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF }; + if (typeof(CrazyNesting).GetMethod("Equals")?.DeclaringType == typeof(CrazyNesting)) + { + if (!one.Equals(two)) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorContainers; + throw new Exception("CrazyNesting.Equals failed"); + } + } + + // TODO: Validate received message + Console.Write("testStruct({\"Zero\", 1, -3, -5})"); + var o = new Xtruct(); + o.String_thing = "Zero"; + o.Byte_thing = (sbyte)1; + o.I32_thing = -3; + o.I64_thing = -5; + var i = await client.testStructAsync(o, token); + Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}"); + + // TODO: Validate received message + Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})"); + var o2 = new Xtruct2(); + o2.Byte_thing = (sbyte)1; + o2.Struct_thing = o; + o2.I32_thing = 5; + var i2 = await client.testNestAsync(o2, token); + i = i2.Struct_thing; + Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}"); + + var mapout = new Dictionary<int, int>(); + for (var j = 0; j < 5; j++) + { + mapout[j] = j - 10; + } + Console.Write("testMap({"); + var first = true; + foreach (var key in mapout.Keys) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(key + " => " + mapout[key]); + } + Console.Write("})"); + + var mapin = await client.testMapAsync(mapout, token); + + Console.Write(" = {"); + first = true; + foreach (var key in mapin.Keys) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(key + " => " + mapin[key]); + } + Console.WriteLine("}"); + + // TODO: Validate received message + var listout = new List<int>(); + for (var j = -2; j < 3; j++) + { + listout.Add(j); + } + Console.Write("testList({"); + first = true; + foreach (var j in listout) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.Write("})"); + + var listin = await client.testListAsync(listout, token); + + Console.Write(" = {"); + first = true; + foreach (var j in listin) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.WriteLine("}"); + + //set + // TODO: Validate received message + var setout = new THashSet<int>(); + for (var j = -2; j < 3; j++) + { + setout.Add(j); + } + Console.Write("testSet({"); + first = true; + foreach (int j in setout) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.Write("})"); + + var setin = await client.testSetAsync(setout, token); + + Console.Write(" = {"); + first = true; + foreach (int j in setin) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.WriteLine("}"); + + + Console.Write("testEnum(ONE)"); + var ret = await client.testEnumAsync(Numberz.ONE, token); + Console.WriteLine(" = " + ret); + if (Numberz.ONE != ret) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorStructs; + } + + Console.Write("testEnum(TWO)"); + ret = await client.testEnumAsync(Numberz.TWO, token); + Console.WriteLine(" = " + ret); + if (Numberz.TWO != ret) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorStructs; + } + + Console.Write("testEnum(THREE)"); + ret = await client.testEnumAsync(Numberz.THREE, token); + Console.WriteLine(" = " + ret); + if (Numberz.THREE != ret) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorStructs; + } + + Console.Write("testEnum(FIVE)"); + ret = await client.testEnumAsync(Numberz.FIVE, token); + Console.WriteLine(" = " + ret); + if (Numberz.FIVE != ret) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorStructs; + } + + Console.Write("testEnum(EIGHT)"); + ret = await client.testEnumAsync(Numberz.EIGHT, token); + Console.WriteLine(" = " + ret); + if (Numberz.EIGHT != ret) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorStructs; + } + + Console.Write("testTypedef(309858235082523)"); + var uid = await client.testTypedefAsync(309858235082523L, token); + Console.WriteLine(" = " + uid); + if (309858235082523L != uid) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorStructs; + } + + // TODO: Validate received message + Console.Write("testMapMap(1)"); + var mm = await client.testMapMapAsync(1, token); + Console.Write(" = {"); + foreach (var key in mm.Keys) + { + Console.Write(key + " => {"); + var m2 = mm[key]; + foreach (var k2 in m2.Keys) + { + Console.Write(k2 + " => " + m2[k2] + ", "); + } + Console.Write("}, "); + } + Console.WriteLine("}"); + + // TODO: Validate received message + var insane = new Insanity(); + insane.UserMap = new Dictionary<Numberz, long>(); + insane.UserMap[Numberz.FIVE] = 5000L; + var truck = new Xtruct(); + truck.String_thing = "Truck"; + truck.Byte_thing = (sbyte)8; + truck.I32_thing = 8; + truck.I64_thing = 8; + insane.Xtructs = new List<Xtruct>(); + insane.Xtructs.Add(truck); + Console.Write("testInsanity()"); + var whoa = await client.testInsanityAsync(insane, token); + Console.Write(" = {"); + foreach (var key in whoa.Keys) + { + var val = whoa[key]; + Console.Write(key + " => {"); + + foreach (var k2 in val.Keys) + { + var v2 = val[k2]; + + Console.Write(k2 + " => {"); + var userMap = v2.UserMap; + + Console.Write("{"); + if (userMap != null) + { + foreach (var k3 in userMap.Keys) + { + Console.Write(k3 + " => " + userMap[k3] + ", "); + } + } + else + { + Console.Write("null"); + } + Console.Write("}, "); + + var xtructs = v2.Xtructs; + + Console.Write("{"); + if (xtructs != null) + { + foreach (var x in xtructs) + { + Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, "); + } + } + else + { + Console.Write("null"); + } + Console.Write("}"); + + Console.Write("}, "); + } + Console.Write("}, "); + } + Console.WriteLine("}"); + + sbyte arg0 = 1; + var arg1 = 2; + var arg2 = long.MaxValue; + var multiDict = new Dictionary<short, string>(); + multiDict[1] = "one"; + + var tmpMultiDict = new List<string>(); + foreach (var pair in multiDict) + tmpMultiDict.Add(pair.Key +" => "+ pair.Value); + + 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, token); + 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", token); + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + catch (Xception ex) + { + if (ex.ErrorCode != 1001 || ex.Message != "Xception") + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + try + { + Console.WriteLine("testException(\"TException\")"); + await client.testExceptionAsync("TException", token); + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + catch (Thrift.TException) + { + // OK + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + try + { + Console.WriteLine("testException(\"ok\")"); + await client.testExceptionAsync("ok", token); + // OK + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + + try + { + Console.WriteLine("testMultiException(\"Xception\", ...)"); + await client.testMultiExceptionAsync("Xception", "ignore", token); + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + catch (Xception ex) + { + if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception") + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + try + { + Console.WriteLine("testMultiException(\"Xception2\", ...)"); + await client.testMultiExceptionAsync("Xception2", "ignore", token); + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + catch (Xception2 ex) + { + if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2") + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + try + { + Console.WriteLine("testMultiException(\"success\", \"OK\")"); + if ("OK" != (await client.testMultiExceptionAsync("success", "OK", token)).String_thing) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + } + } + catch (Exception ex) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorExceptions; + Console.WriteLine(ex.Message + " ST: " + ex.StackTrace); + } + + var sw = new Stopwatch(); + sw.Start(); + Console.WriteLine("Test Oneway(1)"); + await client.testOnewayAsync(1, token); + sw.Stop(); + if (sw.ElapsedMilliseconds > 1000) + { + Console.WriteLine("*** FAILED ***"); + returnCode |= ErrorBaseTypes; + } + + Console.Write("Test Calltime()"); + var times = 50; + sw.Reset(); + sw.Start(); + for (var k = 0; k < times; ++k) + await client.testVoidAsync(token); + sw.Stop(); + Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times); + return returnCode; + } + } +} http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Makefile.am ---------------------------------------------------------------------- diff --git a/test/netcore/Makefile.am b/test/netcore/Makefile.am index e029a24..65833b9 100644 --- a/test/netcore/Makefile.am +++ b/test/netcore/Makefile.am @@ -19,41 +19,28 @@ SUBDIRS = . -THRIFT = $(top_builddir)/compiler/cpp/thrift - -GENDIR = ThriftTest/gen-netcore - THRIFTCODE = \ - ThriftTest/TestClient.cs \ - ThriftTest/TestServer.cs \ - ThriftTest/Properties/AssemblyInfo.cs \ - ThriftTest/Program.cs + ThriftTest.sln all-local: \ - ThriftTest/stage/ThriftTest.dll + ThriftTest/stage/binaries -ThriftTest/stage/ThriftTest.dll: $(THRIFTCODE) - $(MKDIR_P) $(GENDIR) - $(THRIFT) -gen netcore:wcf -r -out $(GENDIR) $(top_srcdir)/test/ThriftTest.thrift - $(DOTNETCORE) --info - $(DOTNETCORE) restore +ThriftTest/stage/binaries: $(THRIFTCODE) $(DOTNETCORE) build precross: \ - ThriftTest/stage/ThriftTest.dll + ThriftTest/stage/binaries clean-local: - $(RM) ThriftTest.exe - $(RM) -r $(GENDIR) - $(RM) -r ThriftTest/bin - $(RM) -r ThriftTest/obj + $(RM) -r Client/bin + $(RM) -r Server/bin + $(RM) -r Client/obj + $(RM) -r Server/obj + $(RM) -r ThriftTest/ThriftTest EXTRA_DIST = \ - $(THRIFTCODE) \ ThriftTest.sln \ - ThriftTest/ThriftTest.csproj \ - ThriftTest/Properties/launchSettings.json \ - build.cmd \ - build.sh \ + Server \ + Client \ README.md http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/README.md ---------------------------------------------------------------------- diff --git a/test/netcore/README.md b/test/netcore/README.md index 05eb0e2..ed728d1 100644 --- a/test/netcore/README.md +++ b/test/netcore/README.md @@ -9,7 +9,10 @@ Tests for Thrift client library ported to Microsoft .Net Core - NET Core Standard 1.6 (SDK 2.0.0) # How to build on Windows +- Get Thrift IDL compiler executable, add to some folder and add path to this folder into PATH variable - Open ThriftTest.sln in Visual Studio and build +or +- Build with scripts # How to build on Unix - Ensure you have .NET Core 2.0.0 SDK installed or use the Ubuntu Xenial docker image http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Server/.gitignore ---------------------------------------------------------------------- diff --git a/test/netcore/Server/.gitignore b/test/netcore/Server/.gitignore new file mode 100644 index 0000000..67d5510 --- /dev/null +++ b/test/netcore/Server/.gitignore @@ -0,0 +1,2 @@ +# ignore for autogenerated files +/ThriftTest http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Server/Program.cs ---------------------------------------------------------------------- diff --git a/test/netcore/Server/Program.cs b/test/netcore/Server/Program.cs new file mode 100644 index 0000000..e647e5b --- /dev/null +++ b/test/netcore/Server/Program.cs @@ -0,0 +1,72 @@ +// 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.Collections.Generic; +using ThriftTest; + +namespace Server +{ + public class Program + { + public static int Main(string[] args) + { + try + { + Console.SetBufferSize(Console.BufferWidth, 4096); + } + catch (Exception) + { + Console.WriteLine("Failed to grow scroll-back buffer"); + } + + // split mode and options + var subArgs = new List<string>(args); + var firstArg = string.Empty; + if (subArgs.Count > 0) + { + firstArg = subArgs[0]; + subArgs.RemoveAt(0); + } + + // run whatever mode is choosen + switch(firstArg) + { + case "server": + return TestServer.Execute(subArgs); + case "--help": + PrintHelp(); + return 0; + default: + PrintHelp(); + return -1; + } + } + + private static void PrintHelp() + { + Console.WriteLine("Usage:"); + Console.WriteLine(" Server server [options]'"); + Console.WriteLine(" Server --help"); + Console.WriteLine(""); + + TestServer.PrintOptionsHelp(); + } + } +} + + http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Server/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/test/netcore/Server/Properties/AssemblyInfo.cs b/test/netcore/Server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..265495c --- /dev/null +++ b/test/netcore/Server/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// 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.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("The Apache Software Foundation")] +[assembly: AssemblyProduct("Thrift")] +[assembly: AssemblyCopyright("The Apache Software Foundation")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("B0C13DA0-3117-4844-8AE8-B1775E46223D")] + http://git-wip-us.apache.org/repos/asf/thrift/blob/54993296/test/netcore/Server/Server.csproj ---------------------------------------------------------------------- diff --git a/test/netcore/Server/Server.csproj b/test/netcore/Server/Server.csproj new file mode 100644 index 0000000..ad2fb7c --- /dev/null +++ b/test/netcore/Server/Server.csproj @@ -0,0 +1,31 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>netcoreapp2.0</TargetFramework> + <AssemblyName>Server</AssemblyName> + <PackageId>Server</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="System.Net.Http.WinHttpHandler" Version="[4.4,)" /> + <PackageReference Include="System.Runtime.Serialization.Primitives" Version="[4.3,)" /> + <PackageReference Include="System.ServiceModel.Primitives" Version="[4.4,)" /> + <PackageReference Include="System.Threading" Version="[4.3,)" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\lib\netcore\Thrift\Thrift.csproj" /> + </ItemGroup> + <Target Name="PreBuild" BeforeTargets="_GenerateRestoreProjectSpec;Restore;Compile"> + <Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true"> + <Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" /> + </Exec> + <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r ./../../ThriftTest.thrift" /> + <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r ./../../ThriftTest.thrift" /> + <Exec Condition="Exists('$(ProjectDir)/../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../compiler/cpp/thrift -out $(ProjectDir) -gen netcore:wcf,union,serial,hashcode -r ./../../ThriftTest.thrift" /> + </Target> +</Project> \ No newline at end of file