aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp')
-rw-r--r--src/csharp/.nuget/packages.config4
-rw-r--r--src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs2
-rw-r--r--src/csharp/Grpc.Auth/Grpc.Auth.csproj51
-rw-r--r--src/csharp/Grpc.Auth/Grpc.Auth.nuspec2
-rw-r--r--src/csharp/Grpc.Auth/app.config19
-rw-r--r--src/csharp/Grpc.Auth/packages.config8
-rw-r--r--src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj1
-rw-r--r--src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs2
-rw-r--r--src/csharp/Grpc.Core.Tests/HalfcloseTest.cs97
-rw-r--r--src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs2
-rw-r--r--src/csharp/Grpc.Core.Tests/PInvokeTest.cs8
-rw-r--r--src/csharp/Grpc.Core/AsyncAuthInterceptor.cs4
-rw-r--r--src/csharp/Grpc.Core/CallCredentials.cs4
-rw-r--r--src/csharp/Grpc.Core/CallInvocationDetails.cs8
-rw-r--r--src/csharp/Grpc.Core/CallInvoker.cs84
-rw-r--r--src/csharp/Grpc.Core/CallOptions.cs4
-rw-r--r--src/csharp/Grpc.Core/Channel.cs8
-rw-r--r--src/csharp/Grpc.Core/ChannelCredentials.cs6
-rw-r--r--src/csharp/Grpc.Core/ChannelOptions.cs10
-rw-r--r--src/csharp/Grpc.Core/ClientBase.cs161
-rw-r--r--src/csharp/Grpc.Core/ContextPropagationToken.cs2
-rw-r--r--src/csharp/Grpc.Core/DefaultCallInvoker.cs112
-rw-r--r--src/csharp/Grpc.Core/Grpc.Core.csproj10
-rw-r--r--src/csharp/Grpc.Core/GrpcEnvironment.cs6
-rw-r--r--src/csharp/Grpc.Core/Internal/AsyncCall.cs32
-rw-r--r--src/csharp/Grpc.Core/Internal/AsyncCallBase.cs66
-rw-r--r--src/csharp/Grpc.Core/Internal/AsyncCallServer.cs36
-rw-r--r--src/csharp/Grpc.Core/Internal/AsyncCompletion.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/CStringSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/CallCredentialsSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/CallSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/ChannelArgsSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/CompletionQueueEvent.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs4
-rw-r--r--src/csharp/Grpc.Core/Internal/CompletionRegistry.cs4
-rw-r--r--src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs4
-rw-r--r--src/csharp/Grpc.Core/Internal/Enums.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs134
-rw-r--r--src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/NativeExtension.cs25
-rw-r--r--src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs4
-rw-r--r--src/csharp/Grpc.Core/Internal/NativeMethods.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/PlatformApis.cs8
-rw-r--r--src/csharp/Grpc.Core/Internal/ServerCallHandler.cs8
-rw-r--r--src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs4
-rw-r--r--src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs2
-rw-r--r--src/csharp/Grpc.Core/Internal/Timespec.cs8
-rw-r--r--src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs75
-rw-r--r--src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs4
-rw-r--r--src/csharp/Grpc.Core/KeyCertificatePair.cs4
-rw-r--r--src/csharp/Grpc.Core/Logging/ConsoleLogger.cs6
-rw-r--r--src/csharp/Grpc.Core/Logging/NullLogger.cs122
-rw-r--r--src/csharp/Grpc.Core/Marshaller.cs4
-rw-r--r--src/csharp/Grpc.Core/Metadata.cs16
-rw-r--r--src/csharp/Grpc.Core/Method.cs8
-rw-r--r--src/csharp/Grpc.Core/Profiling/Profilers.cs2
-rw-r--r--src/csharp/Grpc.Core/Server.cs18
-rw-r--r--src/csharp/Grpc.Core/ServerCredentials.cs4
-rw-r--r--src/csharp/Grpc.Core/ServerPort.cs4
-rw-r--r--src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs (renamed from src/csharp/Grpc.Core/Utils/Preconditions.cs)2
-rw-r--r--src/csharp/Grpc.Core/Version.cs2
-rw-r--r--src/csharp/Grpc.Core/VersionInfo.cs9
-rw-r--r--src/csharp/Grpc.Examples.MathClient/MathClient.cs4
-rw-r--r--src/csharp/Grpc.Examples/MathExamples.cs14
-rw-r--r--src/csharp/Grpc.Examples/MathGrpc.cs105
-rw-r--r--src/csharp/Grpc.Examples/MathServiceImpl.cs12
-rw-r--r--src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs16
-rw-r--r--src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs46
-rw-r--r--src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec2
-rw-r--r--src/csharp/Grpc.HealthCheck/Health.cs72
-rw-r--r--src/csharp/Grpc.HealthCheck/HealthGrpc.cs79
-rw-r--r--src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs48
-rw-r--r--src/csharp/Grpc.IntegrationTesting.Client/Grpc.IntegrationTesting.Client.csproj39
-rw-r--r--src/csharp/Grpc.IntegrationTesting.Client/app.config19
-rw-r--r--src/csharp/Grpc.IntegrationTesting.Client/packages.config8
-rw-r--r--src/csharp/Grpc.IntegrationTesting.QpsWorker/app.config4
-rw-r--r--src/csharp/Grpc.IntegrationTesting.Server/Grpc.IntegrationTesting.Server.csproj39
-rw-r--r--src/csharp/Grpc.IntegrationTesting.Server/app.config19
-rw-r--r--src/csharp/Grpc.IntegrationTesting.Server/packages.config8
-rw-r--r--src/csharp/Grpc.IntegrationTesting/BenchmarkServiceImpl.cs17
-rw-r--r--src/csharp/Grpc.IntegrationTesting/ClientRunners.cs258
-rw-r--r--src/csharp/Grpc.IntegrationTesting/Control.cs419
-rw-r--r--src/csharp/Grpc.IntegrationTesting/GeneratedClientTest.cs106
-rw-r--r--src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs116
-rw-r--r--src/csharp/Grpc.IntegrationTesting/GenericService.cs71
-rw-r--r--src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj54
-rw-r--r--src/csharp/Grpc.IntegrationTesting/Histogram.cs4
-rw-r--r--src/csharp/Grpc.IntegrationTesting/InterarrivalTimers.cs148
-rw-r--r--src/csharp/Grpc.IntegrationTesting/InteropClient.cs26
-rw-r--r--src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs4
-rw-r--r--src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs8
-rw-r--r--src/csharp/Grpc.IntegrationTesting/QpsWorker.cs13
-rw-r--r--src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs16
-rw-r--r--src/csharp/Grpc.IntegrationTesting/ServerRunners.cs69
-rw-r--r--src/csharp/Grpc.IntegrationTesting/Services.cs7
-rw-r--r--src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs211
-rw-r--r--src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs4
-rw-r--r--src/csharp/Grpc.IntegrationTesting/TestGrpc.cs287
-rw-r--r--src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs16
-rw-r--r--src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs28
-rw-r--r--src/csharp/Grpc.IntegrationTesting/app.config19
-rw-r--r--src/csharp/Grpc.IntegrationTesting/packages.config8
-rw-r--r--src/csharp/Grpc.Tools.nuspec17
-rw-r--r--src/csharp/README.md125
-rw-r--r--src/csharp/build_packages.bat19
-rw-r--r--src/csharp/ext/grpc_csharp_ext.c4
-rwxr-xr-xsrc/csharp/generate_proto_csharp.sh4
-rw-r--r--src/csharp/grpc.native.csharp/grpc.native.csharp.nuspec2
-rw-r--r--src/csharp/tests.json4
113 files changed, 2849 insertions, 1029 deletions
diff --git a/src/csharp/.nuget/packages.config b/src/csharp/.nuget/packages.config
index 89a310ac56..acb43ae4b3 100644
--- a/src/csharp/.nuget/packages.config
+++ b/src/csharp/.nuget/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.4" />
- <package id="OpenCover" version="4.6.166" />
- <package id="ReportGenerator" version="2.3.2.0" />
+ <package id="OpenCover" version="4.6.519" />
+ <package id="ReportGenerator" version="2.4.4.0" />
</packages> \ No newline at end of file
diff --git a/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
index f77e9c6573..96d6ee87ae 100644
--- a/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
+++ b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
@@ -71,7 +71,7 @@ namespace Grpc.Auth
/// <returns>The interceptor.</returns>
public static AsyncAuthInterceptor FromAccessToken(string accessToken)
{
- Preconditions.CheckNotNull(accessToken);
+ GrpcPreconditions.CheckNotNull(accessToken);
return new AsyncAuthInterceptor(async (context, metadata) =>
{
metadata.Add(CreateBearerTokenHeader(accessToken));
diff --git a/src/csharp/Grpc.Auth/Grpc.Auth.csproj b/src/csharp/Grpc.Auth/Grpc.Auth.csproj
index 8dd12b50ef..3acea7d2f8 100644
--- a/src/csharp/Grpc.Auth/Grpc.Auth.csproj
+++ b/src/csharp/Grpc.Auth/Grpc.Auth.csproj
@@ -9,7 +9,7 @@
<AssemblyName>Grpc.Auth</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\Grpc.Auth.Xml</DocumentationFile>
- <NuGetPackageImportStamp>4f8487a9</NuGetPackageImportStamp>
+ <NuGetPackageImportStamp>455903a2</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -39,43 +39,30 @@
<AssemblyOriginatorKeyFile>..\keys\Grpc.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Google.Apis.Auth, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="BouncyCastle.Crypto, Version=1.7.4137.9688, Culture=neutral, PublicKeyToken=a4292a325f69b123, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.dll</HintPath>
+ <HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
+ </Reference>
+ <Reference Include="Google.Apis.Auth, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.dll</HintPath>
+ </Reference>
+ <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.PlatformServices.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Core, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.PlatformServices.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Core.1.11.1\lib\net45\Google.Apis.Core.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Core, Version=1.10.0.25331, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Core.1.10.0\lib\portable-net40+sl50+win+wpa81+wp80\Google.Apis.Core.dll</HintPath>
+ <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
- <Reference Include="BouncyCastle.Crypto">
- <HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
- </Reference>
- <Reference Include="Newtonsoft.Json">
- <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http.Extensions">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http.Primitives">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
- </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Grpc.Core\Version.cs">
@@ -93,15 +80,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
<None Include="Grpc.Auth.nuspec" />
<None Include="packages.config" />
</ItemGroup>
- <Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
- <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
- <PropertyGroup>
- <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
- </PropertyGroup>
- <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
- </Target>
</Project> \ No newline at end of file
diff --git a/src/csharp/Grpc.Auth/Grpc.Auth.nuspec b/src/csharp/Grpc.Auth/Grpc.Auth.nuspec
index f1f8f7c709..4baed3704c 100644
--- a/src/csharp/Grpc.Auth/Grpc.Auth.nuspec
+++ b/src/csharp/Grpc.Auth/Grpc.Auth.nuspec
@@ -15,7 +15,7 @@
<copyright>Copyright 2015, Google Inc.</copyright>
<tags>gRPC RPC Protocol HTTP/2 Auth OAuth2</tags>
<dependencies>
- <dependency id="Google.Apis.Auth" version="1.9.3" />
+ <dependency id="Google.Apis.Auth" version="1.11.1" />
<dependency id="Grpc.Core" version="$version$" />
</dependencies>
</metadata>
diff --git a/src/csharp/Grpc.Auth/app.config b/src/csharp/Grpc.Auth/app.config
deleted file mode 100644
index 84d7534d65..0000000000
--- a/src/csharp/Grpc.Auth/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.0.0.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.9.2.38523" newVersion="1.9.2.38523" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
-</configuration> \ No newline at end of file
diff --git a/src/csharp/Grpc.Auth/packages.config b/src/csharp/Grpc.Auth/packages.config
index 5fe8ca616c..c20d9ceed6 100644
--- a/src/csharp/Grpc.Auth/packages.config
+++ b/src/csharp/Grpc.Auth/packages.config
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.7.0" targetFramework="net45" />
- <package id="Google.Apis.Auth" version="1.10.0" targetFramework="net45" />
- <package id="Google.Apis.Core" version="1.10.0" targetFramework="net45" />
- <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
- <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
- <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
- <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />
+ <package id="Google.Apis.Auth" version="1.11.1" targetFramework="net45" />
+ <package id="Google.Apis.Core" version="1.11.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages> \ No newline at end of file
diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
index 7e73c4f181..3bfd49b10f 100644
--- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
+++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
@@ -93,6 +93,7 @@
<Compile Include="MetadataTest.cs" />
<Compile Include="PerformanceTest.cs" />
<Compile Include="SanityTest.cs" />
+ <Compile Include="HalfcloseTest.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs b/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
index 78295cf6d4..ab12c120cb 100644
--- a/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
+++ b/src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
@@ -84,7 +84,7 @@ namespace Grpc.Core.Tests
{
var coreVersion = GrpcEnvironment.GetCoreVersionString();
var parts = coreVersion.Split('.');
- Assert.AreEqual(4, parts.Length);
+ Assert.AreEqual(3, parts.Length);
}
}
}
diff --git a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
new file mode 100644
index 0000000000..fe6edb858b
--- /dev/null
+++ b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
@@ -0,0 +1,97 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Grpc.Core;
+using Grpc.Core.Internal;
+using Grpc.Core.Utils;
+
+using NUnit.Framework;
+
+namespace Grpc.Core.Tests
+{
+ public class HalfcloseTest
+ {
+ MockServiceHelper helper;
+ Server server;
+ Channel channel;
+
+ [SetUp]
+ public void Init()
+ {
+ helper = new MockServiceHelper();
+
+ server = helper.GetServer();
+ server.Start();
+ channel = helper.GetChannel();
+ }
+
+ [TearDown]
+ public void Cleanup()
+ {
+ channel.ShutdownAsync().Wait();
+ server.ShutdownAsync().Wait();
+ }
+
+ /// <summary>
+ /// For client streaming and duplex streaming calls, if server does a full close
+ /// before we halfclose the request stream, an attempt to halfclose
+ /// (complete the request stream) shouldn't be treated as an error.
+ /// </summary>
+ [Test]
+ public async Task HalfcloseAfterFullclose_ClientStreamingCall()
+ {
+ helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) =>
+ {
+ return "PASS";
+ });
+
+ var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall());
+ // make sure server has fullclosed on us
+ Assert.AreEqual("PASS", await call.ResponseAsync);
+
+ // sending close from client should be still fine because server can finish
+ // the call anytime and we cannot do anything about it on the client side.
+ await call.RequestStream.CompleteAsync();
+
+ // Second attempt to close from client is not allowed.
+ Assert.Throws(typeof(InvalidOperationException), async () => await call.RequestStream.CompleteAsync());
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
index d5a1eeb0fb..543f6375df 100644
--- a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
+++ b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core.Tests/PInvokeTest.cs b/src/csharp/Grpc.Core.Tests/PInvokeTest.cs
index da0ea2e6dc..d2b2fc6a66 100644
--- a/src/csharp/Grpc.Core.Tests/PInvokeTest.cs
+++ b/src/csharp/Grpc.Core.Tests/PInvokeTest.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -74,6 +74,8 @@ namespace Grpc.Core.Tests
/// (~110ns .NET Windows)
/// </summary>
[Test]
+ [Category("Performance")]
+ [Ignore("Prevent running on Jenkins")]
public void NativeCallbackBenchmark()
{
OpCompletionDelegate handler = Handler;
@@ -95,6 +97,8 @@ namespace Grpc.Core.Tests
/// (~1.1us on .NET Windows)
/// </summary>
[Test]
+ [Category("Performance")]
+ [Ignore("Prevent running on Jenkins")]
public void NewNativeCallbackBenchmark()
{
counter = 0;
@@ -112,6 +116,8 @@ namespace Grpc.Core.Tests
/// (~46ns .NET Windows)
/// </summary>
[Test]
+ [Category("Performance")]
+ [Ignore("Prevent running on Jenkins")]
public void NopPInvokeBenchmark()
{
BenchmarkUtil.RunBenchmark(
diff --git a/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs b/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs
index 5c9ab04812..1ad2290928 100644
--- a/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs
+++ b/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs
@@ -61,8 +61,8 @@ namespace Grpc.Core
/// </summary>
public AuthInterceptorContext(string serviceUrl, string methodName)
{
- this.serviceUrl = Preconditions.CheckNotNull(serviceUrl);
- this.methodName = Preconditions.CheckNotNull(methodName);
+ this.serviceUrl = GrpcPreconditions.CheckNotNull(serviceUrl);
+ this.methodName = GrpcPreconditions.CheckNotNull(methodName);
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/CallCredentials.cs b/src/csharp/Grpc.Core/CallCredentials.cs
index a71c8904fe..7476b0ca16 100644
--- a/src/csharp/Grpc.Core/CallCredentials.cs
+++ b/src/csharp/Grpc.Core/CallCredentials.cs
@@ -87,7 +87,7 @@ namespace Grpc.Core
/// <param name="interceptor">authentication interceptor</param>
public MetadataCredentials(AsyncAuthInterceptor interceptor)
{
- this.interceptor = Preconditions.CheckNotNull(interceptor);
+ this.interceptor = GrpcPreconditions.CheckNotNull(interceptor);
}
internal override CallCredentialsSafeHandle ToNativeCredentials()
@@ -111,7 +111,7 @@ namespace Grpc.Core
/// <param name="credentials">credentials to compose</param>
public CompositeCallCredentials(params CallCredentials[] credentials)
{
- Preconditions.CheckArgument(credentials.Length >= 2, "Composite credentials object can only be created from 2 or more credentials.");
+ GrpcPreconditions.CheckArgument(credentials.Length >= 2, "Composite credentials object can only be created from 2 or more credentials.");
this.credentials = new List<CallCredentials>(credentials);
}
diff --git a/src/csharp/Grpc.Core/CallInvocationDetails.cs b/src/csharp/Grpc.Core/CallInvocationDetails.cs
index 8228b8f317..98db854614 100644
--- a/src/csharp/Grpc.Core/CallInvocationDetails.cs
+++ b/src/csharp/Grpc.Core/CallInvocationDetails.cs
@@ -85,11 +85,11 @@ namespace Grpc.Core
/// <param name="options">Call options.</param>
public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options)
{
- this.channel = Preconditions.CheckNotNull(channel, "channel");
- this.method = Preconditions.CheckNotNull(method, "method");
+ this.channel = GrpcPreconditions.CheckNotNull(channel, "channel");
+ this.method = GrpcPreconditions.CheckNotNull(method, "method");
this.host = host;
- this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
- this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
+ this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
+ this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
this.options = options;
}
diff --git a/src/csharp/Grpc.Core/CallInvoker.cs b/src/csharp/Grpc.Core/CallInvoker.cs
new file mode 100644
index 0000000000..39199b1fd5
--- /dev/null
+++ b/src/csharp/Grpc.Core/CallInvoker.cs
@@ -0,0 +1,84 @@
+#region Copyright notice and license
+
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System.Threading.Tasks;
+using Grpc.Core.Internal;
+
+namespace Grpc.Core
+{
+ /// <summary>
+ /// Abstraction of client-side RPC invocation.
+ /// </summary>
+ /// <seealso cref="Calls"/>
+ public abstract class CallInvoker
+ {
+ /// <summary>
+ /// Invokes a simple remote call in a blocking fashion.
+ /// </summary>
+ public abstract TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ where TRequest : class
+ where TResponse : class;
+
+ /// <summary>
+ /// Invokes a simple remote call asynchronously.
+ /// </summary>
+ public abstract AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ where TRequest : class
+ where TResponse : class;
+
+ /// <summary>
+ /// Invokes a server streaming call asynchronously.
+ /// In server streaming scenario, client sends on request and server responds with a stream of responses.
+ /// </summary>
+ public abstract AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ where TRequest : class
+ where TResponse : class;
+
+ /// <summary>
+ /// Invokes a client streaming call asynchronously.
+ /// In client streaming scenario, client sends a stream of requests and server responds with a single response.
+ /// </summary>
+ public abstract AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ where TRequest : class
+ where TResponse : class;
+
+ /// <summary>
+ /// Invokes a duplex streaming call asynchronously.
+ /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses.
+ /// The response stream is completely independent and both side can be sending messages at the same time.
+ /// </summary>
+ public abstract AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ where TRequest : class
+ where TResponse : class;
+ }
+}
diff --git a/src/csharp/Grpc.Core/CallOptions.cs b/src/csharp/Grpc.Core/CallOptions.cs
index 10e073aff1..9ca88849ee 100644
--- a/src/csharp/Grpc.Core/CallOptions.cs
+++ b/src/csharp/Grpc.Core/CallOptions.cs
@@ -203,13 +203,13 @@ namespace Grpc.Core
{
if (propagationToken.Options.IsPropagateDeadline)
{
- Preconditions.CheckArgument(!newOptions.deadline.HasValue,
+ GrpcPreconditions.CheckArgument(!newOptions.deadline.HasValue,
"Cannot propagate deadline from parent call. The deadline has already been set explicitly.");
newOptions.deadline = propagationToken.ParentDeadline;
}
if (propagationToken.Options.IsPropagateCancellation)
{
- Preconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled,
+ GrpcPreconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled,
"Cannot propagate cancellation token from parent call. The cancellation token has already been set to a non-default value.");
newOptions.cancellationToken = propagationToken.ParentCancellationToken;
}
diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs
index d8d43c7998..89981b1849 100644
--- a/src/csharp/Grpc.Core/Channel.cs
+++ b/src/csharp/Grpc.Core/Channel.cs
@@ -68,7 +68,7 @@ namespace Grpc.Core
/// <param name="options">Channel options.</param>
public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options = null)
{
- this.target = Preconditions.CheckNotNull(target, "target");
+ this.target = GrpcPreconditions.CheckNotNull(target, "target");
this.options = CreateOptionsDictionary(options);
EnsureUserAgentChannelOption(this.options);
this.environment = GrpcEnvironment.AddRef();
@@ -117,7 +117,7 @@ namespace Grpc.Core
/// </summary>
public Task WaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = null)
{
- Preconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure,
+ GrpcPreconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure,
"FatalFailure is a terminal state. No further state changes can occur.");
var tcs = new TaskCompletionSource<object>();
var deadlineTimespec = deadline.HasValue ? Timespec.FromDateTime(deadline.Value) : Timespec.InfFuture;
@@ -184,7 +184,7 @@ namespace Grpc.Core
{
lock (myLock)
{
- Preconditions.CheckState(!shutdownRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
shutdownRequested = true;
}
@@ -221,7 +221,7 @@ namespace Grpc.Core
bool success = false;
handle.DangerousAddRef(ref success);
- Preconditions.CheckState(success);
+ GrpcPreconditions.CheckState(success);
}
internal void RemoveCallReference(object call)
diff --git a/src/csharp/Grpc.Core/ChannelCredentials.cs b/src/csharp/Grpc.Core/ChannelCredentials.cs
index 5d96958e7c..db0cefef8b 100644
--- a/src/csharp/Grpc.Core/ChannelCredentials.cs
+++ b/src/csharp/Grpc.Core/ChannelCredentials.cs
@@ -183,9 +183,9 @@ namespace Grpc.Core
/// <param name="callCredentials">channelCredentials to compose</param>
public CompositeChannelCredentials(ChannelCredentials channelCredentials, CallCredentials callCredentials)
{
- this.channelCredentials = Preconditions.CheckNotNull(channelCredentials);
- this.callCredentials = Preconditions.CheckNotNull(callCredentials);
- Preconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition.");
+ this.channelCredentials = GrpcPreconditions.CheckNotNull(channelCredentials);
+ this.callCredentials = GrpcPreconditions.CheckNotNull(callCredentials);
+ GrpcPreconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition.");
}
internal override ChannelCredentialsSafeHandle ToNativeCredentials()
diff --git a/src/csharp/Grpc.Core/ChannelOptions.cs b/src/csharp/Grpc.Core/ChannelOptions.cs
index d70673cf78..b6eeceabc4 100644
--- a/src/csharp/Grpc.Core/ChannelOptions.cs
+++ b/src/csharp/Grpc.Core/ChannelOptions.cs
@@ -73,8 +73,8 @@ namespace Grpc.Core
public ChannelOption(string name, string stringValue)
{
this.type = OptionType.String;
- this.name = Preconditions.CheckNotNull(name, "name");
- this.stringValue = Preconditions.CheckNotNull(stringValue, "stringValue");
+ this.name = GrpcPreconditions.CheckNotNull(name, "name");
+ this.stringValue = GrpcPreconditions.CheckNotNull(stringValue, "stringValue");
}
/// <summary>
@@ -85,7 +85,7 @@ namespace Grpc.Core
public ChannelOption(string name, int intValue)
{
this.type = OptionType.Integer;
- this.name = Preconditions.CheckNotNull(name, "name");
+ this.name = GrpcPreconditions.CheckNotNull(name, "name");
this.intValue = intValue;
}
@@ -118,7 +118,7 @@ namespace Grpc.Core
{
get
{
- Preconditions.CheckState(type == OptionType.Integer);
+ GrpcPreconditions.CheckState(type == OptionType.Integer);
return intValue;
}
}
@@ -130,7 +130,7 @@ namespace Grpc.Core
{
get
{
- Preconditions.CheckState(type == OptionType.String);
+ GrpcPreconditions.CheckState(type == OptionType.String);
return stringValue;
}
}
diff --git a/src/csharp/Grpc.Core/ClientBase.cs b/src/csharp/Grpc.Core/ClientBase.cs
index e5b398062b..5517233e3c 100644
--- a/src/csharp/Grpc.Core/ClientBase.cs
+++ b/src/csharp/Grpc.Core/ClientBase.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -31,93 +31,156 @@
#endregion
-using System;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
+using Grpc.Core.Internal;
+using Grpc.Core.Utils;
namespace Grpc.Core
{
/// <summary>
- /// Interceptor for call headers.
+ /// Generic base class for client-side stubs.
/// </summary>
- /// <remarks>Header interceptor is no longer to recommented way to perform authentication.
- /// For header (initial metadata) based auth such as OAuth2 or JWT access token, use <see cref="MetadataCredentials"/>.
- /// </remarks>
- public delegate void HeaderInterceptor(IMethod method, Metadata metadata);
+ public abstract class ClientBase<T> : ClientBase
+ where T : ClientBase<T>
+ {
+ /// <summary>
+ /// Initializes a new instance of <c>ClientBase</c> class that
+ /// throws <c>NotImplementedException</c> upon invocation of any RPC.
+ /// This constructor is only provided to allow creation of test doubles
+ /// for client classes (e.g. mocking requires a parameterless constructor).
+ /// </summary>
+ protected ClientBase() : base()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of <c>ClientBase</c> class.
+ /// </summary>
+ /// <param name="configuration">The configuration.</param>
+ protected ClientBase(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of <c>ClientBase</c> class.
+ /// </summary>
+ /// <param name="channel">The channel to use for remote call invocation.</param>
+ public ClientBase(Channel channel) : base(channel)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of <c>ClientBase</c> class.
+ /// </summary>
+ /// <param name="callInvoker">The <c>CallInvoker</c> for remote call invocation.</param>
+ public ClientBase(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new client that sets host field for calls explicitly.
+ /// gRPC supports multiple "hosts" being served by a single server.
+ /// By default (if a client was not created by calling this method),
+ /// host <c>null</c> with the meaning "use default host" is used.
+ /// </summary>
+ public T WithHost(string host)
+ {
+ var newConfiguration = this.Configuration.WithHost(host);
+ return NewInstance(newConfiguration);
+ }
+
+ /// <summary>
+ /// Creates a new instance of client from given <c>ClientBaseConfiguration</c>.
+ /// </summary>
+ protected abstract T NewInstance(ClientBaseConfiguration configuration);
+ }
/// <summary>
/// Base class for client-side stubs.
/// </summary>
public abstract class ClientBase
{
- readonly Channel channel;
+ readonly ClientBaseConfiguration configuration;
+ readonly CallInvoker callInvoker;
+
+ /// <summary>
+ /// Initializes a new instance of <c>ClientBase</c> class that
+ /// throws <c>NotImplementedException</c> upon invocation of any RPC.
+ /// This constructor is only provided to allow creation of test doubles
+ /// for client classes (e.g. mocking requires a parameterless constructor).
+ /// </summary>
+ protected ClientBase() : this(new UnimplementedCallInvoker())
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of <c>ClientBase</c> class.
+ /// </summary>
+ /// <param name="configuration">The configuration.</param>
+ protected ClientBase(ClientBaseConfiguration configuration)
+ {
+ this.configuration = GrpcPreconditions.CheckNotNull(configuration, "configuration");
+ this.callInvoker = configuration.CreateDecoratedCallInvoker();
+ }
/// <summary>
/// Initializes a new instance of <c>ClientBase</c> class.
/// </summary>
/// <param name="channel">The channel to use for remote call invocation.</param>
- public ClientBase(Channel channel)
+ public ClientBase(Channel channel) : this(new DefaultCallInvoker(channel))
{
- this.channel = channel;
}
/// <summary>
- /// Can be used to register a custom header interceptor.
- /// The interceptor is invoked each time a new call on this client is started.
- /// It is not recommented to use header interceptor to add auth headers to RPC calls.
+ /// Initializes a new instance of <c>ClientBase</c> class.
/// </summary>
- /// <seealso cref="HeaderInterceptor"/>
- public HeaderInterceptor HeaderInterceptor
+ /// <param name="callInvoker">The <c>CallInvoker</c> for remote call invocation.</param>
+ public ClientBase(CallInvoker callInvoker) : this(new ClientBaseConfiguration(callInvoker, null))
{
- get;
- set;
}
/// <summary>
- /// gRPC supports multiple "hosts" being served by a single server.
- /// This property can be used to set the target host explicitly.
- /// By default, this will be set to <c>null</c> with the meaning
- /// "use default host".
+ /// Gets the call invoker.
/// </summary>
- public string Host
+ protected CallInvoker CallInvoker
{
- get;
- set;
+ get { return this.callInvoker; }
}
/// <summary>
- /// Channel associated with this client.
+ /// Gets the configuration.
/// </summary>
- public Channel Channel
+ internal ClientBaseConfiguration Configuration
{
- get
- {
- return this.channel;
- }
+ get { return this.configuration; }
}
/// <summary>
- /// Creates a new call to given method.
+ /// Represents configuration of ClientBase. The class itself is visible to
+ /// subclasses, but contents are marked as internal to make the instances opaque.
+ /// The verbose name of this class was chosen to make name clash in generated code
+ /// less likely.
/// </summary>
- /// <param name="method">The method to invoke.</param>
- /// <param name="options">The call options.</param>
- /// <typeparam name="TRequest">Request message type.</typeparam>
- /// <typeparam name="TResponse">Response message type.</typeparam>
- /// <returns>The call invocation details.</returns>
- protected CallInvocationDetails<TRequest, TResponse> CreateCall<TRequest, TResponse>(Method<TRequest, TResponse> method, CallOptions options)
- where TRequest : class
- where TResponse : class
+ protected internal class ClientBaseConfiguration
{
- var interceptor = HeaderInterceptor;
- if (interceptor != null)
+ readonly CallInvoker undecoratedCallInvoker;
+ readonly string host;
+
+ internal ClientBaseConfiguration(CallInvoker undecoratedCallInvoker, string host)
+ {
+ this.undecoratedCallInvoker = GrpcPreconditions.CheckNotNull(undecoratedCallInvoker);
+ this.host = host;
+ }
+
+ internal CallInvoker CreateDecoratedCallInvoker()
+ {
+ return new InterceptingCallInvoker(undecoratedCallInvoker, hostInterceptor: (h) => host);
+ }
+
+ internal ClientBaseConfiguration WithHost(string host)
{
- if (options.Headers == null)
- {
- options = options.WithHeaders(new Metadata());
- }
- interceptor(method, options.Headers);
+ GrpcPreconditions.CheckNotNull(host, "host");
+ return new ClientBaseConfiguration(this.undecoratedCallInvoker, host);
}
- return new CallInvocationDetails<TRequest, TResponse>(channel, method, Host, options);
}
}
}
diff --git a/src/csharp/Grpc.Core/ContextPropagationToken.cs b/src/csharp/Grpc.Core/ContextPropagationToken.cs
index 1d899b97fd..935498246a 100644
--- a/src/csharp/Grpc.Core/ContextPropagationToken.cs
+++ b/src/csharp/Grpc.Core/ContextPropagationToken.cs
@@ -68,7 +68,7 @@ namespace Grpc.Core
internal ContextPropagationToken(CallSafeHandle parentCall, DateTime deadline, CancellationToken cancellationToken, ContextPropagationOptions options)
{
- this.parentCall = Preconditions.CheckNotNull(parentCall);
+ this.parentCall = GrpcPreconditions.CheckNotNull(parentCall);
this.deadline = deadline;
this.cancellationToken = cancellationToken;
this.options = options ?? ContextPropagationOptions.Default;
diff --git a/src/csharp/Grpc.Core/DefaultCallInvoker.cs b/src/csharp/Grpc.Core/DefaultCallInvoker.cs
new file mode 100644
index 0000000000..1a99e41153
--- /dev/null
+++ b/src/csharp/Grpc.Core/DefaultCallInvoker.cs
@@ -0,0 +1,112 @@
+#region Copyright notice and license
+
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System.Threading.Tasks;
+using Grpc.Core.Internal;
+using Grpc.Core.Utils;
+
+namespace Grpc.Core
+{
+ /// <summary>
+ /// Invokes client RPCs using <see cref="Calls"/>.
+ /// </summary>
+ public class DefaultCallInvoker : CallInvoker
+ {
+ readonly Channel channel;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Grpc.Core.DefaultCallInvoker"/> class.
+ /// </summary>
+ /// <param name="channel">Channel to use.</param>
+ public DefaultCallInvoker(Channel channel)
+ {
+ this.channel = GrpcPreconditions.CheckNotNull(channel);
+ }
+
+ /// <summary>
+ /// Invokes a simple remote call in a blocking fashion.
+ /// </summary>
+ public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ var call = CreateCall(method, host, options);
+ return Calls.BlockingUnaryCall(call, request);
+ }
+
+ /// <summary>
+ /// Invokes a simple remote call asynchronously.
+ /// </summary>
+ public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ var call = CreateCall(method, host, options);
+ return Calls.AsyncUnaryCall(call, request);
+ }
+
+ /// <summary>
+ /// Invokes a server streaming call asynchronously.
+ /// In server streaming scenario, client sends on request and server responds with a stream of responses.
+ /// </summary>
+ public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ var call = CreateCall(method, host, options);
+ return Calls.AsyncServerStreamingCall(call, request);
+ }
+
+ /// <summary>
+ /// Invokes a client streaming call asynchronously.
+ /// In client streaming scenario, client sends a stream of requests and server responds with a single response.
+ /// </summary>
+ public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ {
+ var call = CreateCall(method, host, options);
+ return Calls.AsyncClientStreamingCall(call);
+ }
+
+ /// <summary>
+ /// Invokes a duplex streaming call asynchronously.
+ /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses.
+ /// The response stream is completely independent and both side can be sending messages at the same time.
+ /// </summary>
+ public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ {
+ var call = CreateCall(method, host, options);
+ return Calls.AsyncDuplexStreamingCall(call);
+ }
+
+ protected virtual CallInvocationDetails<TRequest, TResponse> CreateCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ where TRequest : class
+ where TResponse : class
+ {
+ return new CallInvocationDetails<TRequest, TResponse>(channel, method, host, options);
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj
index 9587503e4b..251a688946 100644
--- a/src/csharp/Grpc.Core/Grpc.Core.csproj
+++ b/src/csharp/Grpc.Core/Grpc.Core.csproj
@@ -39,8 +39,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Interactive.Async">
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
</ItemGroup>
@@ -59,6 +58,7 @@
<Compile Include="IServerStreamWriter.cs" />
<Compile Include="IAsyncStreamWriter.cs" />
<Compile Include="IAsyncStreamReader.cs" />
+ <Compile Include="Logging\NullLogger.cs" />
<Compile Include="ServerPort.cs" />
<Compile Include="Version.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -90,7 +90,6 @@
<Compile Include="Internal\AsyncCallBase.cs" />
<Compile Include="Internal\AsyncCallServer.cs" />
<Compile Include="Internal\AsyncCall.cs" />
- <Compile Include="Utils\Preconditions.cs" />
<Compile Include="Internal\ServerCredentialsSafeHandle.cs" />
<Compile Include="ServerCredentials.cs" />
<Compile Include="Metadata.cs" />
@@ -129,6 +128,11 @@
<Compile Include="Profiling\IProfiler.cs" />
<Compile Include="Profiling\Profilers.cs" />
<Compile Include="Internal\DefaultSslRootsOverride.cs" />
+ <Compile Include="Utils\GrpcPreconditions.cs" />
+ <Compile Include="CallInvoker.cs" />
+ <Compile Include="DefaultCallInvoker.cs" />
+ <Compile Include="Internal\UnimplementedCallInvoker.cs" />
+ <Compile Include="Internal\InterceptingCallInvoker.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Grpc.Core.nuspec" />
diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs
index f3aa3d79de..a5c78cc9d7 100644
--- a/src/csharp/Grpc.Core/GrpcEnvironment.cs
+++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -83,7 +83,7 @@ namespace Grpc.Core
{
lock (staticLock)
{
- Preconditions.CheckState(refCount > 0);
+ GrpcPreconditions.CheckState(refCount > 0);
refCount--;
if (refCount == 0)
{
@@ -118,7 +118,7 @@ namespace Grpc.Core
/// </summary>
public static void SetLogger(ILogger customLogger)
{
- Preconditions.CheckNotNull(customLogger, "customLogger");
+ GrpcPreconditions.CheckNotNull(customLogger, "customLogger");
logger = customLogger;
}
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCall.cs b/src/csharp/Grpc.Core/Internal/AsyncCall.cs
index 7dc4490281..016e1b8587 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCall.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCall.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -99,7 +99,7 @@ namespace Grpc.Core.Internal
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(cq);
@@ -141,7 +141,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -168,7 +168,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -192,7 +192,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -217,7 +217,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -257,10 +257,20 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
- CheckSendingAllowed();
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ CheckSendingAllowed(allowFinished: true);
- call.StartSendCloseFromClient(HandleHalfclosed);
+ if (!disposed && !finished)
+ {
+ call.StartSendCloseFromClient(HandleSendCloseFromClientFinished);
+ }
+ else
+ {
+ // In case the call has already been finished by the serverside,
+ // the halfclose has already been done implicitly, so we only
+ // emit the notification for the completion delegate.
+ Task.Run(() => HandleSendCloseFromClientFinished(true));
+ }
halfcloseRequested = true;
sendCompletionDelegate = completionDelegate;
@@ -297,7 +307,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(finishedStatus.HasValue, "Status can only be accessed once the call has finished.");
+ GrpcPreconditions.CheckState(finishedStatus.HasValue, "Status can only be accessed once the call has finished.");
return finishedStatus.Value.Status;
}
}
@@ -310,7 +320,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(finishedStatus.HasValue, "Trailers can only be accessed once the call has finished.");
+ GrpcPreconditions.CheckState(finishedStatus.HasValue, "Trailers can only be accessed once the call has finished.");
return finishedStatus.Value.Trailers;
}
}
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
index 81a9a40fcc..ccd047f469 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -79,9 +79,9 @@ namespace Grpc.Core.Internal
public AsyncCallBase(Func<TWrite, byte[]> serializer, Func<byte[], TRead> deserializer, GrpcEnvironment environment)
{
- this.serializer = Preconditions.CheckNotNull(serializer);
- this.deserializer = Preconditions.CheckNotNull(deserializer);
- this.environment = Preconditions.CheckNotNull(environment);
+ this.serializer = GrpcPreconditions.CheckNotNull(serializer);
+ this.deserializer = GrpcPreconditions.CheckNotNull(deserializer);
+ this.environment = GrpcPreconditions.CheckNotNull(environment);
}
/// <summary>
@@ -91,7 +91,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckState(started);
+ GrpcPreconditions.CheckState(started);
cancelRequested = true;
if (!disposed)
@@ -135,8 +135,8 @@ namespace Grpc.Core.Internal
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
- CheckSendingAllowed();
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ CheckSendingAllowed(allowFinished: false);
call.StartSendMessage(HandleSendFinished, payload, writeFlags, !initialMetadataSent);
@@ -154,7 +154,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
CheckReadingAllowed();
call.StartReceiveMessage(HandleReadFinished);
@@ -202,24 +202,24 @@ namespace Grpc.Core.Internal
{
}
- protected void CheckSendingAllowed()
+ protected void CheckSendingAllowed(bool allowFinished)
{
- Preconditions.CheckState(started);
+ GrpcPreconditions.CheckState(started);
CheckNotCancelled();
- Preconditions.CheckState(!disposed);
+ GrpcPreconditions.CheckState(!disposed || allowFinished);
- Preconditions.CheckState(!halfcloseRequested, "Already halfclosed.");
- Preconditions.CheckState(!finished, "Already finished.");
- Preconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time");
+ GrpcPreconditions.CheckState(!halfcloseRequested, "Already halfclosed.");
+ GrpcPreconditions.CheckState(!finished || allowFinished, "Already finished.");
+ GrpcPreconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time");
}
protected virtual void CheckReadingAllowed()
{
- Preconditions.CheckState(started);
- Preconditions.CheckState(!disposed);
+ GrpcPreconditions.CheckState(started);
+ GrpcPreconditions.CheckState(!disposed);
- Preconditions.CheckState(!readingDone, "Stream has already been closed.");
- Preconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time");
+ GrpcPreconditions.CheckState(!readingDone, "Stream has already been closed.");
+ GrpcPreconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time");
}
protected void CheckNotCancelled()
@@ -294,9 +294,9 @@ namespace Grpc.Core.Internal
}
/// <summary>
- /// Handles halfclose completion.
+ /// Handles halfclose (send close from client) completion.
/// </summary>
- protected void HandleHalfclosed(bool success)
+ protected void HandleSendCloseFromClientFinished(bool success)
{
AsyncCompletionDelegate<object> origCompletionDelegate = null;
lock (myLock)
@@ -309,7 +309,31 @@ namespace Grpc.Core.Internal
if (!success)
{
- FireCompletion(origCompletionDelegate, null, new InvalidOperationException("Halfclose failed"));
+ FireCompletion(origCompletionDelegate, null, new InvalidOperationException("Sending close from client has failed."));
+ }
+ else
+ {
+ FireCompletion(origCompletionDelegate, null, null);
+ }
+ }
+
+ /// <summary>
+ /// Handles send status from server completion.
+ /// </summary>
+ protected void HandleSendStatusFromServerFinished(bool success)
+ {
+ AsyncCompletionDelegate<object> origCompletionDelegate = null;
+ lock (myLock)
+ {
+ origCompletionDelegate = sendCompletionDelegate;
+ sendCompletionDelegate = null;
+
+ ReleaseResourcesIfPossible();
+ }
+
+ if (!success)
+ {
+ FireCompletion(origCompletionDelegate, null, new InvalidOperationException("Error sending status from server."));
}
else
{
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
index 6752d3fab3..bea2b3660c 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -53,7 +53,7 @@ namespace Grpc.Core.Internal
public AsyncCallServer(Func<TResponse, byte[]> serializer, Func<byte[], TRequest> deserializer, GrpcEnvironment environment, Server server) : base(serializer, deserializer, environment)
{
- this.server = Preconditions.CheckNotNull(server);
+ this.server = GrpcPreconditions.CheckNotNull(server);
}
public void Initialize(CallSafeHandle call)
@@ -71,7 +71,7 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckNotNull(call);
+ GrpcPreconditions.CheckNotNull(call);
started = true;
@@ -108,14 +108,14 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckNotNull(headers, "metadata");
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(headers, "metadata");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
- Preconditions.CheckState(!initialMetadataSent, "Response headers can only be sent once per call.");
- Preconditions.CheckState(streamingWritesCounter == 0, "Response headers can only be sent before the first write starts.");
- CheckSendingAllowed();
+ GrpcPreconditions.CheckState(!initialMetadataSent, "Response headers can only be sent once per call.");
+ GrpcPreconditions.CheckState(streamingWritesCounter == 0, "Response headers can only be sent before the first write starts.");
+ CheckSendingAllowed(allowFinished: false);
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
using (var metadataArray = MetadataArraySafeHandle.Create(headers))
{
@@ -136,12 +136,12 @@ namespace Grpc.Core.Internal
{
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
- CheckSendingAllowed();
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ CheckSendingAllowed(allowFinished: false);
using (var metadataArray = MetadataArraySafeHandle.Create(trailers))
{
- call.StartSendStatusFromServer(HandleHalfclosed, status, metadataArray, !initialMetadataSent);
+ call.StartSendStatusFromServer(HandleSendStatusFromServerFinished, status, metadataArray, !initialMetadataSent);
}
halfcloseRequested = true;
readingDone = true;
@@ -177,7 +177,7 @@ namespace Grpc.Core.Internal
protected override void CheckReadingAllowed()
{
base.CheckReadingAllowed();
- Preconditions.CheckArgument(!cancelRequested);
+ GrpcPreconditions.CheckArgument(!cancelRequested);
}
protected override void OnAfterReleaseResources()
@@ -193,16 +193,6 @@ namespace Grpc.Core.Internal
lock (myLock)
{
finished = true;
-
- if (cancelled)
- {
- // Once we cancel, we don't have to care that much
- // about reads and writes.
-
- // TODO(jtattermusch): is this still necessary?
- Cancel();
- }
-
ReleaseResourcesIfPossible();
}
// TODO(jtattermusch): handle error
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCompletion.cs b/src/csharp/Grpc.Core/Internal/AsyncCompletion.cs
index d5bbf676ff..7e86fddb4d 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCompletion.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCompletion.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs b/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs
index 0e2108f0f2..66d2a66f99 100644
--- a/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/CStringSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CStringSafeHandle.cs
index 4ae57aa773..0221798d2a 100644
--- a/src/csharp/Grpc.Core/Internal/CStringSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/CStringSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/CallCredentialsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CallCredentialsSafeHandle.cs
index 0f36337f11..3095a34008 100644
--- a/src/csharp/Grpc.Core/Internal/CallCredentialsSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/CallCredentialsSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs
index bc045b67b1..500653ba5d 100644
--- a/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/CallSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/ChannelArgsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelArgsSafeHandle.cs
index f6aa710b21..0038024245 100644
--- a/src/csharp/Grpc.Core/Internal/ChannelArgsSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/ChannelArgsSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
index 65cc2e019f..c85f55241a 100644
--- a/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/ChannelCredentialsSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs
index 2199905cc6..1dbd1f4e34 100644
--- a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/CompletionQueueEvent.cs b/src/csharp/Grpc.Core/Internal/CompletionQueueEvent.cs
index 36a92ecd8e..288680792a 100644
--- a/src/csharp/Grpc.Core/Internal/CompletionQueueEvent.cs
+++ b/src/csharp/Grpc.Core/Internal/CompletionQueueEvent.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
index 9d7a990c42..91364cdc70 100644
--- a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -101,7 +101,7 @@ namespace Grpc.Core.Internal
{
bool success = false;
shutdownRefcount.IncrementIfNonzero(ref success);
- Preconditions.CheckState(success, "Shutdown has already been called");
+ GrpcPreconditions.CheckState(success, "Shutdown has already been called");
}
private void EndOp()
diff --git a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs
index 2796c959a3..628844f242 100644
--- a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs
+++ b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs
@@ -59,7 +59,7 @@ namespace Grpc.Core.Internal
public void Register(IntPtr key, OpCompletionDelegate callback)
{
environment.DebugStats.PendingBatchCompletions.Increment();
- Preconditions.CheckState(dict.TryAdd(key, callback));
+ GrpcPreconditions.CheckState(dict.TryAdd(key, callback));
}
public void RegisterBatchCompletion(BatchContextSafeHandle ctx, BatchCompletionDelegate callback)
@@ -71,7 +71,7 @@ namespace Grpc.Core.Internal
public OpCompletionDelegate Extract(IntPtr key)
{
OpCompletionDelegate value;
- Preconditions.CheckState(dict.TryRemove(key, out value));
+ GrpcPreconditions.CheckState(dict.TryRemove(key, out value));
environment.DebugStats.PendingBatchCompletions.Decrement();
return value;
}
diff --git a/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs b/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs
index eeaa7add81..aa4dafd7f2 100644
--- a/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs
+++ b/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@ namespace Grpc.Core.Internal
{
lock (staticLock)
{
- var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(RootsPemResourceName);
+ var stream = typeof(DefaultSslRootsOverride).GetTypeInfo().Assembly.GetManifestResourceStream(RootsPemResourceName);
if (stream == null)
{
throw new IOException(string.Format("Error loading the embedded resource \"{0}\"", RootsPemResourceName));
diff --git a/src/csharp/Grpc.Core/Internal/Enums.cs b/src/csharp/Grpc.Core/Internal/Enums.cs
index b0eab2001b..74f86d2a30 100644
--- a/src/csharp/Grpc.Core/Internal/Enums.cs
+++ b/src/csharp/Grpc.Core/Internal/Enums.cs
@@ -72,7 +72,7 @@ namespace Grpc.Core.Internal
/// </summary>
public static void CheckOk(this GRPCCallError callError)
{
- Preconditions.CheckState(callError == GRPCCallError.OK, "Call error: " + callError);
+ GrpcPreconditions.CheckState(callError == GRPCCallError.OK, "Call error: " + callError);
}
}
diff --git a/src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs b/src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs
new file mode 100644
index 0000000000..ef48dc7121
--- /dev/null
+++ b/src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs
@@ -0,0 +1,134 @@
+#region Copyright notice and license
+
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Threading.Tasks;
+using Grpc.Core;
+using Grpc.Core.Utils;
+
+namespace Grpc.Core.Internal
+{
+ /// <summary>
+ /// Decorates an underlying <c>CallInvoker</c> to intercept call invocations.
+ /// </summary>
+ internal class InterceptingCallInvoker : CallInvoker
+ {
+ readonly CallInvoker callInvoker;
+ readonly Func<string, string> hostInterceptor;
+ readonly Func<CallOptions, CallOptions> callOptionsInterceptor;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Grpc.Core.InterceptingCallInvoker"/> class.
+ /// </summary>
+ public InterceptingCallInvoker(CallInvoker callInvoker,
+ Func<string, string> hostInterceptor = null,
+ Func<CallOptions, CallOptions> callOptionsInterceptor = null)
+ {
+ this.callInvoker = GrpcPreconditions.CheckNotNull(callInvoker);
+ this.hostInterceptor = hostInterceptor;
+ this.callOptionsInterceptor = callOptionsInterceptor;
+ }
+
+ /// <summary>
+ /// Intercepts a unary call.
+ /// </summary>
+ public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ host = InterceptHost(host);
+ options = InterceptCallOptions(options);
+ return callInvoker.BlockingUnaryCall(method, host, options, request);
+ }
+
+ /// <summary>
+ /// Invokes a simple remote call asynchronously.
+ /// </summary>
+ public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ host = InterceptHost(host);
+ options = InterceptCallOptions(options);
+ return callInvoker.AsyncUnaryCall(method, host, options, request);
+ }
+
+ /// <summary>
+ /// Invokes a server streaming call asynchronously.
+ /// In server streaming scenario, client sends on request and server responds with a stream of responses.
+ /// </summary>
+ public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ host = InterceptHost(host);
+ options = InterceptCallOptions(options);
+ return callInvoker.AsyncServerStreamingCall(method, host, options, request);
+ }
+
+ /// <summary>
+ /// Invokes a client streaming call asynchronously.
+ /// In client streaming scenario, client sends a stream of requests and server responds with a single response.
+ /// </summary>
+ public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ {
+ host = InterceptHost(host);
+ options = InterceptCallOptions(options);
+ return callInvoker.AsyncClientStreamingCall(method, host, options);
+ }
+
+ /// <summary>
+ /// Invokes a duplex streaming call asynchronously.
+ /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses.
+ /// The response stream is completely independent and both side can be sending messages at the same time.
+ /// </summary>
+ public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ {
+ host = InterceptHost(host);
+ options = InterceptCallOptions(options);
+ return callInvoker.AsyncDuplexStreamingCall(method, host, options);
+ }
+
+ private string InterceptHost(string host)
+ {
+ if (hostInterceptor == null)
+ {
+ return host;
+ }
+ return hostInterceptor(host);
+ }
+
+ private CallOptions InterceptCallOptions(CallOptions options)
+ {
+ if (callOptionsInterceptor == null)
+ {
+ return options;
+ }
+ return callOptionsInterceptor(options);
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs b/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs
index 81760d7a10..25735d5262 100644
--- a/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/NativeExtension.cs b/src/csharp/Grpc.Core/Internal/NativeExtension.cs
index e14d33ea50..bff1e56582 100644
--- a/src/csharp/Grpc.Core/Internal/NativeExtension.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeExtension.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -32,6 +32,7 @@
#endregion
using System;
+using System.Globalization;
using System.IO;
using System.Reflection;
@@ -99,14 +100,30 @@ namespace Grpc.Core.Internal
// TODO: allow customizing path to native extension (possibly through exposing a GrpcEnvironment property).
var libraryFlavor = string.Format("{0}_{1}", GetPlatformString(), GetArchitectureString());
- var fullPath = Path.Combine(GetExecutingAssemblyDirectory(),
+ var fullPath = Path.Combine(Path.GetDirectoryName(GetAssemblyPath()),
NativeLibrariesDir, libraryFlavor, GetNativeLibraryFilename());
return new UnmanagedLibrary(fullPath);
}
- private static string GetExecutingAssemblyDirectory()
+ private static string GetAssemblyPath()
{
- return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ var assembly = typeof(NativeExtension).GetTypeInfo().Assembly;
+
+ // If assembly is shadowed (e.g. in a webapp), EscapedCodeBase is pointing
+ // to the original location of the assembly, and Location is pointing
+ // to the shadow copy. We care about the original location because
+ // the native dlls don't get shadowed.
+ var escapedCodeBase = assembly.EscapedCodeBase;
+ if (IsFileUri(escapedCodeBase))
+ {
+ return new Uri(escapedCodeBase).LocalPath;
+ }
+ return assembly.Location;
+ }
+
+ private static bool IsFileUri(string uri)
+ {
+ return uri.ToLowerInvariant().StartsWith(Uri.UriSchemeFile);
}
private static string GetPlatformString()
diff --git a/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs b/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs
index 4bbbb4808c..3fcf8673ee 100644
--- a/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeLogRedirector.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs b/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
index 36b865c09c..0e4d9070d3 100644
--- a/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -53,7 +53,7 @@ namespace Grpc.Core.Internal
public NativeMetadataCredentialsPlugin(AsyncAuthInterceptor interceptor)
{
- this.interceptor = Preconditions.CheckNotNull(interceptor, "interceptor");
+ this.interceptor = GrpcPreconditions.CheckNotNull(interceptor, "interceptor");
this.nativeInterceptor = NativeMetadataInterceptorHandler;
// Make sure the callback doesn't get garbage collected until it is destroyed.
diff --git a/src/csharp/Grpc.Core/Internal/NativeMethods.cs b/src/csharp/Grpc.Core/Internal/NativeMethods.cs
index 19a573581e..9ee0ba3bc0 100644
--- a/src/csharp/Grpc.Core/Internal/NativeMethods.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeMethods.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs
index f0c5b0f63f..5d8c44b589 100644
--- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs
+++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -53,12 +53,18 @@ namespace Grpc.Core.Internal
static PlatformApis()
{
+#if DNXCORE50
+ isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
+ isMacOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+ isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+#else
var platform = Environment.OSVersion.Platform;
// PlatformID.MacOSX is never returned, commonly used trick is to identify Mac is by using uname.
isMacOSX = (platform == PlatformID.Unix && GetUname() == "Darwin");
isLinux = (platform == PlatformID.Unix && !isMacOSX);
isWindows = (platform == PlatformID.Win32NT || platform == PlatformID.Win32S || platform == PlatformID.Win32Windows);
+#endif
isMono = Type.GetType("Mono.Runtime") != null;
}
diff --git a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
index de66759b94..1f83e51548 100644
--- a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
+++ b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
@@ -78,10 +78,10 @@ namespace Grpc.Core.Internal
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
- Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
var request = requestStream.Current;
// TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated.
- Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
var result = await handler(request, context).ConfigureAwait(false);
status = context.Status;
await responseStream.WriteAsync(result).ConfigureAwait(false);
@@ -134,10 +134,10 @@ namespace Grpc.Core.Internal
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
- Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
var request = requestStream.Current;
// TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated.
- Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
await handler(request, responseStream, context).ConfigureAwait(false);
status = context.Status;
}
diff --git a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
index a1d080c7f1..24f686fddc 100644
--- a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -49,7 +49,7 @@ namespace Grpc.Core.Internal
public static ServerCredentialsSafeHandle CreateSslCredentials(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, bool forceClientAuth)
{
- Preconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length);
+ GrpcPreconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length);
return Native.grpcsharp_ssl_server_credentials_create(pemRootCerts,
keyCertPairCertChainArray, keyCertPairPrivateKeyArray,
new UIntPtr((ulong)keyCertPairCertChainArray.Length),
diff --git a/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs
index a57fb3b789..6b5f70e220 100644
--- a/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
diff --git a/src/csharp/Grpc.Core/Internal/Timespec.cs b/src/csharp/Grpc.Core/Internal/Timespec.cs
index 148d877da5..56172a5dda 100644
--- a/src/csharp/Grpc.Core/Internal/Timespec.cs
+++ b/src/csharp/Grpc.Core/Internal/Timespec.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -141,8 +141,8 @@ namespace Grpc.Core.Internal
/// </summary>
public DateTime ToDateTime()
{
- Preconditions.CheckState(tv_nsec >= 0 && tv_nsec < NanosPerSecond);
- Preconditions.CheckState(clock_type == GPRClockType.Realtime);
+ GrpcPreconditions.CheckState(tv_nsec >= 0 && tv_nsec < NanosPerSecond);
+ GrpcPreconditions.CheckState(clock_type == GPRClockType.Realtime);
// fast path for InfFuture
if (this.Equals(InfFuture))
@@ -195,7 +195,7 @@ namespace Grpc.Core.Internal
return Timespec.InfPast;
}
- Preconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, "dateTime needs of kind DateTimeKind.Utc or be equal to DateTime.MaxValue or DateTime.MinValue.");
+ GrpcPreconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, "dateTime needs of kind DateTimeKind.Utc or be equal to DateTime.MaxValue or DateTime.MinValue.");
try
{
diff --git a/src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs b/src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs
new file mode 100644
index 0000000000..0c7340873b
--- /dev/null
+++ b/src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs
@@ -0,0 +1,75 @@
+#region Copyright notice and license
+
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Threading.Tasks;
+using Grpc.Core;
+using Grpc.Core.Utils;
+
+namespace Grpc.Core.Internal
+{
+ /// <summary>
+ /// Call invoker that throws <c>NotImplementedException</c> for all requests.
+ /// </summary>
+ internal class UnimplementedCallInvoker : CallInvoker
+ {
+ public UnimplementedCallInvoker()
+ {
+ }
+
+ public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
index 95a8797e3e..47308f8c9e 100644
--- a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
+++ b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -65,7 +65,7 @@ namespace Grpc.Core.Internal
public UnmanagedLibrary(string libraryPath)
{
- this.libraryPath = Preconditions.CheckNotNull(libraryPath);
+ this.libraryPath = GrpcPreconditions.CheckNotNull(libraryPath);
if (!File.Exists(this.libraryPath))
{
diff --git a/src/csharp/Grpc.Core/KeyCertificatePair.cs b/src/csharp/Grpc.Core/KeyCertificatePair.cs
index 6f691975e9..a8f3bb073d 100644
--- a/src/csharp/Grpc.Core/KeyCertificatePair.cs
+++ b/src/csharp/Grpc.Core/KeyCertificatePair.cs
@@ -54,8 +54,8 @@ namespace Grpc.Core
/// <param name="privateKey">PEM encoded private key.</param>
public KeyCertificatePair(string certificateChain, string privateKey)
{
- this.certificateChain = Preconditions.CheckNotNull(certificateChain, "certificateChain");
- this.privateKey = Preconditions.CheckNotNull(privateKey, "privateKey");
+ this.certificateChain = GrpcPreconditions.CheckNotNull(certificateChain, "certificateChain");
+ this.privateKey = GrpcPreconditions.CheckNotNull(privateKey, "privateKey");
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs b/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
index 5c5b802164..da74e55a95 100644
--- a/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
+++ b/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
@@ -33,12 +33,16 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
namespace Grpc.Core.Logging
{
/// <summary>Logger that logs to System.Console.</summary>
public class ConsoleLogger : ILogger
{
+ // Format similar enough to C core log format except nanosecond precision is not supported.
+ const string DateTimeFormatString = "MMdd HH:mm:ss.ffffff";
+
readonly Type forType;
readonly string forTypeString;
@@ -142,7 +146,7 @@ namespace Grpc.Core.Logging
{
Console.Error.WriteLine("{0}{1} {2}{3}",
severityString,
- DateTime.Now,
+ DateTime.Now.ToString(DateTimeFormatString, CultureInfo.InvariantCulture),
forTypeString,
message);
}
diff --git a/src/csharp/Grpc.Core/Logging/NullLogger.cs b/src/csharp/Grpc.Core/Logging/NullLogger.cs
new file mode 100644
index 0000000000..58679a0ff9
--- /dev/null
+++ b/src/csharp/Grpc.Core/Logging/NullLogger.cs
@@ -0,0 +1,122 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+
+namespace Grpc.Core.Logging
+{
+ /// <summary>
+ /// Logger which doesn't log any information anywhere.
+ /// </summary>
+ public sealed class NullLogger : ILogger
+ {
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Debug(string message)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Debug(string format, params object[] formatArgs)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Error(string message)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Error(Exception exception, string message)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Error(string format, params object[] formatArgs)
+ {
+ }
+
+ /// <summary>
+ /// Returns a reference to the instance on which the method is called, as
+ /// instances aren't associated with specific types.
+ /// </summary>
+ public ILogger ForType<T>()
+ {
+ return this;
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Info(string message)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Info(string format, params object[] formatArgs)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Warning(string message)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Warning(Exception exception, string message)
+ {
+ }
+
+ /// <summary>
+ /// As with all logging calls on this logger, this method is a no-op.
+ /// </summary>
+ public void Warning(string format, params object[] formatArgs)
+ {
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core/Marshaller.cs b/src/csharp/Grpc.Core/Marshaller.cs
index 3493d2d38f..d86e75b3cb 100644
--- a/src/csharp/Grpc.Core/Marshaller.cs
+++ b/src/csharp/Grpc.Core/Marshaller.cs
@@ -51,8 +51,8 @@ namespace Grpc.Core
/// <param name="deserializer">Function that will be used to deserialize messages.</param>
public Marshaller(Func<T, byte[]> serializer, Func<byte[], T> deserializer)
{
- this.serializer = Preconditions.CheckNotNull(serializer, "serializer");
- this.deserializer = Preconditions.CheckNotNull(deserializer, "deserializer");
+ this.serializer = GrpcPreconditions.CheckNotNull(serializer, "serializer");
+ this.deserializer = GrpcPreconditions.CheckNotNull(deserializer, "deserializer");
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/Metadata.cs b/src/csharp/Grpc.Core/Metadata.cs
index 21bdf4f114..e982fa0c48 100644
--- a/src/csharp/Grpc.Core/Metadata.cs
+++ b/src/csharp/Grpc.Core/Metadata.cs
@@ -179,7 +179,7 @@ namespace Grpc.Core
private void CheckWriteable()
{
- Preconditions.CheckState(!readOnly, "Object is read only");
+ GrpcPreconditions.CheckState(!readOnly, "Object is read only");
}
#endregion
@@ -211,10 +211,10 @@ namespace Grpc.Core
public Entry(string key, byte[] valueBytes)
{
this.key = NormalizeKey(key);
- Preconditions.CheckArgument(this.key.EndsWith(BinaryHeaderSuffix),
+ GrpcPreconditions.CheckArgument(this.key.EndsWith(BinaryHeaderSuffix),
"Key for binary valued metadata entry needs to have suffix indicating binary value.");
this.value = null;
- Preconditions.CheckNotNull(valueBytes, "valueBytes");
+ GrpcPreconditions.CheckNotNull(valueBytes, "valueBytes");
this.valueBytes = new byte[valueBytes.Length];
Buffer.BlockCopy(valueBytes, 0, this.valueBytes, 0, valueBytes.Length); // defensive copy to guarantee immutability
}
@@ -227,9 +227,9 @@ namespace Grpc.Core
public Entry(string key, string value)
{
this.key = NormalizeKey(key);
- Preconditions.CheckArgument(!this.key.EndsWith(BinaryHeaderSuffix),
+ GrpcPreconditions.CheckArgument(!this.key.EndsWith(BinaryHeaderSuffix),
"Key for ASCII valued metadata entry cannot have suffix indicating binary value.");
- this.value = Preconditions.CheckNotNull(value, "value");
+ this.value = GrpcPreconditions.CheckNotNull(value, "value");
this.valueBytes = null;
}
@@ -270,7 +270,7 @@ namespace Grpc.Core
{
get
{
- Preconditions.CheckState(!IsBinary, "Cannot access string value of a binary metadata entry");
+ GrpcPreconditions.CheckState(!IsBinary, "Cannot access string value of a binary metadata entry");
return value ?? Encoding.GetString(valueBytes);
}
}
@@ -323,8 +323,8 @@ namespace Grpc.Core
private static string NormalizeKey(string key)
{
- var normalized = Preconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture);
- Preconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized),
+ var normalized = GrpcPreconditions.CheckNotNull(key, "key").ToLowerInvariant();
+ GrpcPreconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized),
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens.");
return normalized;
}
diff --git a/src/csharp/Grpc.Core/Method.cs b/src/csharp/Grpc.Core/Method.cs
index 99162a7d5d..0cf041be2b 100644
--- a/src/csharp/Grpc.Core/Method.cs
+++ b/src/csharp/Grpc.Core/Method.cs
@@ -106,10 +106,10 @@ namespace Grpc.Core
public Method(MethodType type, string serviceName, string name, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller)
{
this.type = type;
- this.serviceName = Preconditions.CheckNotNull(serviceName, "serviceName");
- this.name = Preconditions.CheckNotNull(name, "name");
- this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
- this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
+ this.serviceName = GrpcPreconditions.CheckNotNull(serviceName, "serviceName");
+ this.name = GrpcPreconditions.CheckNotNull(name, "name");
+ this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
+ this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
this.fullName = GetFullName(serviceName, name);
}
diff --git a/src/csharp/Grpc.Core/Profiling/Profilers.cs b/src/csharp/Grpc.Core/Profiling/Profilers.cs
index 471ee20875..aa0d96c0e0 100644
--- a/src/csharp/Grpc.Core/Profiling/Profilers.cs
+++ b/src/csharp/Grpc.Core/Profiling/Profilers.cs
@@ -111,7 +111,7 @@ namespace Grpc.Core.Profiling
public void Dump(string filepath)
{
- using (var stream = new StreamWriter(filepath))
+ using (var stream = File.CreateText(filepath))
{
Dump(stream);
}
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index d120f95fdf..5b61b7f060 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -125,7 +125,7 @@ namespace Grpc.Core
{
lock (myLock)
{
- Preconditions.CheckState(!startRequested);
+ GrpcPreconditions.CheckState(!startRequested);
startRequested = true;
handle.Start();
@@ -142,8 +142,8 @@ namespace Grpc.Core
{
lock (myLock)
{
- Preconditions.CheckState(startRequested);
- Preconditions.CheckState(!shutdownRequested);
+ GrpcPreconditions.CheckState(startRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
shutdownRequested = true;
}
@@ -162,8 +162,8 @@ namespace Grpc.Core
{
lock (myLock)
{
- Preconditions.CheckState(startRequested);
- Preconditions.CheckState(!shutdownRequested);
+ GrpcPreconditions.CheckState(startRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
shutdownRequested = true;
}
@@ -181,7 +181,7 @@ namespace Grpc.Core
bool success = false;
handle.DangerousAddRef(ref success);
- Preconditions.CheckState(success);
+ GrpcPreconditions.CheckState(success);
}
internal void RemoveCallReference(object call)
@@ -197,7 +197,7 @@ namespace Grpc.Core
{
lock (myLock)
{
- Preconditions.CheckState(!startRequested);
+ GrpcPreconditions.CheckState(!startRequested);
foreach (var entry in serviceDefinition.CallHandlers)
{
callHandlers.Add(entry.Key, entry.Value);
@@ -213,8 +213,8 @@ namespace Grpc.Core
{
lock (myLock)
{
- Preconditions.CheckNotNull(serverPort.Credentials, "serverPort");
- Preconditions.CheckState(!startRequested);
+ GrpcPreconditions.CheckNotNull(serverPort.Credentials, "serverPort");
+ GrpcPreconditions.CheckState(!startRequested);
var address = string.Format("{0}:{1}", serverPort.Host, serverPort.Port);
int boundPort;
using (var nativeCredentials = serverPort.Credentials.ToNativeCredentials())
diff --git a/src/csharp/Grpc.Core/ServerCredentials.cs b/src/csharp/Grpc.Core/ServerCredentials.cs
index 3c6703d30e..ace4820027 100644
--- a/src/csharp/Grpc.Core/ServerCredentials.cs
+++ b/src/csharp/Grpc.Core/ServerCredentials.cs
@@ -90,11 +90,11 @@ namespace Grpc.Core
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs, string rootCertificates, bool forceClientAuth)
{
this.keyCertificatePairs = new List<KeyCertificatePair>(keyCertificatePairs).AsReadOnly();
- Preconditions.CheckArgument(this.keyCertificatePairs.Count > 0,
+ GrpcPreconditions.CheckArgument(this.keyCertificatePairs.Count > 0,
"At least one KeyCertificatePair needs to be provided.");
if (forceClientAuth)
{
- Preconditions.CheckNotNull(rootCertificates,
+ GrpcPreconditions.CheckNotNull(rootCertificates,
"Cannot force client authentication unless you provide rootCertificates.");
}
this.rootCertificates = rootCertificates;
diff --git a/src/csharp/Grpc.Core/ServerPort.cs b/src/csharp/Grpc.Core/ServerPort.cs
index 598404d045..afae0846dd 100644
--- a/src/csharp/Grpc.Core/ServerPort.cs
+++ b/src/csharp/Grpc.Core/ServerPort.cs
@@ -62,9 +62,9 @@ namespace Grpc.Core
/// <param name="credentials">credentials to use to secure this port.</param>
public ServerPort(string host, int port, ServerCredentials credentials)
{
- this.host = Preconditions.CheckNotNull(host, "host");
+ this.host = GrpcPreconditions.CheckNotNull(host, "host");
this.port = port;
- this.credentials = Preconditions.CheckNotNull(credentials, "credentials");
+ this.credentials = GrpcPreconditions.CheckNotNull(credentials, "credentials");
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/Utils/Preconditions.cs b/src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs
index a8ab603391..fcfe97a09b 100644
--- a/src/csharp/Grpc.Core/Utils/Preconditions.cs
+++ b/src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs
@@ -38,7 +38,7 @@ namespace Grpc.Core.Utils
/// <summary>
/// Utility methods to simplify checking preconditions in the code.
/// </summary>
- public static class Preconditions
+ public static class GrpcPreconditions
{
/// <summary>
/// Throws <see cref="ArgumentException"/> if condition is false.
diff --git a/src/csharp/Grpc.Core/Version.cs b/src/csharp/Grpc.Core/Version.cs
index d02b301cac..8a26bd8362 100644
--- a/src/csharp/Grpc.Core/Version.cs
+++ b/src/csharp/Grpc.Core/Version.cs
@@ -34,4 +34,4 @@
using System.Reflection;
// The current version of gRPC C#.
-[assembly: AssemblyVersion(Grpc.Core.VersionInfo.CurrentVersion + ".0")]
+[assembly: AssemblyVersion(Grpc.Core.VersionInfo.CurrentAssemblyVersion)]
diff --git a/src/csharp/Grpc.Core/VersionInfo.cs b/src/csharp/Grpc.Core/VersionInfo.cs
index 65813909de..9014a13f40 100644
--- a/src/csharp/Grpc.Core/VersionInfo.cs
+++ b/src/csharp/Grpc.Core/VersionInfo.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -39,8 +39,13 @@ namespace Grpc.Core
public static class VersionInfo
{
/// <summary>
+ /// Current version of gRPC C# assemblies
+ /// </summary>
+ public const string CurrentAssemblyVersion = "0.14.0.0";
+
+ /// <summary>
/// Current version of gRPC C#
/// </summary>
- public const string CurrentVersion = "0.13.0";
+ public const string CurrentVersion = "0.14.0-dev";
}
}
diff --git a/src/csharp/Grpc.Examples.MathClient/MathClient.cs b/src/csharp/Grpc.Examples.MathClient/MathClient.cs
index 64e429ed5a..aadef6833d 100644
--- a/src/csharp/Grpc.Examples.MathClient/MathClient.cs
+++ b/src/csharp/Grpc.Examples.MathClient/MathClient.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@ namespace Math
public static void Main(string[] args)
{
var channel = new Channel("127.0.0.1", 23456, ChannelCredentials.Insecure);
- Math.IMathClient client = new Math.MathClient(channel);
+ Math.MathClient client = new Math.MathClient(channel);
MathExamples.DivExample(client);
MathExamples.DivAsyncExample(client).Wait();
diff --git a/src/csharp/Grpc.Examples/MathExamples.cs b/src/csharp/Grpc.Examples/MathExamples.cs
index 8009ccbbfa..6075420974 100644
--- a/src/csharp/Grpc.Examples/MathExamples.cs
+++ b/src/csharp/Grpc.Examples/MathExamples.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -38,19 +38,19 @@ namespace Math
{
public static class MathExamples
{
- public static void DivExample(Math.IMathClient client)
+ public static void DivExample(Math.MathClient client)
{
DivReply result = client.Div(new DivArgs { Dividend = 10, Divisor = 3 });
Console.WriteLine("Div Result: " + result);
}
- public static async Task DivAsyncExample(Math.IMathClient client)
+ public static async Task DivAsyncExample(Math.MathClient client)
{
DivReply result = await client.DivAsync(new DivArgs { Dividend = 4, Divisor = 5 });
Console.WriteLine("DivAsync Result: " + result);
}
- public static async Task FibExample(Math.IMathClient client)
+ public static async Task FibExample(Math.MathClient client)
{
using (var call = client.Fib(new FibArgs { Limit = 5 }))
{
@@ -59,7 +59,7 @@ namespace Math
}
}
- public static async Task SumExample(Math.IMathClient client)
+ public static async Task SumExample(Math.MathClient client)
{
var numbers = new List<Num>
{
@@ -75,7 +75,7 @@ namespace Math
}
}
- public static async Task DivManyExample(Math.IMathClient client)
+ public static async Task DivManyExample(Math.MathClient client)
{
var divArgsList = new List<DivArgs>
{
@@ -90,7 +90,7 @@ namespace Math
}
}
- public static async Task DependendRequestsExample(Math.IMathClient client)
+ public static async Task DependendRequestsExample(Math.MathClient client)
{
var numbers = new List<Num>
{
diff --git a/src/csharp/Grpc.Examples/MathGrpc.cs b/src/csharp/Grpc.Examples/MathGrpc.cs
index a6e878d0f4..f3bb0d1cdc 100644
--- a/src/csharp/Grpc.Examples/MathGrpc.cs
+++ b/src/csharp/Grpc.Examples/MathGrpc.cs
@@ -52,6 +52,7 @@ namespace Math {
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IMathClient
{
global::Math.DivReply Div(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
@@ -67,6 +68,7 @@ namespace Math {
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IMath
{
Task<global::Math.DivReply> Div(global::Math.DivArgs request, ServerCallContext context);
@@ -75,61 +77,92 @@ namespace Math {
Task<global::Math.Num> Sum(IAsyncStreamReader<global::Math.Num> requestStream, ServerCallContext context);
}
+ // server-side abstract class
+ public abstract class MathBase
+ {
+ public virtual Task<global::Math.DivReply> Div(global::Math.DivArgs request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task DivMany(IAsyncStreamReader<global::Math.DivArgs> requestStream, IServerStreamWriter<global::Math.DivReply> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task Fib(global::Math.FibArgs request, IServerStreamWriter<global::Math.Num> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task<global::Math.Num> Sum(IAsyncStreamReader<global::Math.Num> requestStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ }
+
// client stub
- public class MathClient : ClientBase, IMathClient
+ public class MathClient : ClientBase<MathClient>, IMathClient
{
public MathClient(Channel channel) : base(channel)
{
}
- public global::Math.DivReply Div(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public MathClient(CallInvoker callInvoker) : base(callInvoker)
{
- var call = CreateCall(__Method_Div, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
}
- public global::Math.DivReply Div(global::Math.DivArgs request, CallOptions options)
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected MathClient() : base()
{
- var call = CreateCall(__Method_Div, options);
- return Calls.BlockingUnaryCall(call, request);
}
- public AsyncUnaryCall<global::Math.DivReply> DivAsync(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected MathClient(ClientBaseConfiguration configuration) : base(configuration)
{
- var call = CreateCall(__Method_Div, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
}
- public AsyncUnaryCall<global::Math.DivReply> DivAsync(global::Math.DivArgs request, CallOptions options)
+
+ public virtual global::Math.DivReply Div(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Div, options);
- return Calls.AsyncUnaryCall(call, request);
+ return Div(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncDuplexStreamingCall<global::Math.DivArgs, global::Math.DivReply> DivMany(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual global::Math.DivReply Div(global::Math.DivArgs request, CallOptions options)
{
- var call = CreateCall(__Method_DivMany, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncDuplexStreamingCall(call);
+ return CallInvoker.BlockingUnaryCall(__Method_Div, null, options, request);
}
- public AsyncDuplexStreamingCall<global::Math.DivArgs, global::Math.DivReply> DivMany(CallOptions options)
+ public virtual AsyncUnaryCall<global::Math.DivReply> DivAsync(global::Math.DivArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_DivMany, options);
- return Calls.AsyncDuplexStreamingCall(call);
+ return DivAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncServerStreamingCall<global::Math.Num> Fib(global::Math.FibArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Math.DivReply> DivAsync(global::Math.DivArgs request, CallOptions options)
{
- var call = CreateCall(__Method_Fib, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncServerStreamingCall(call, request);
+ return CallInvoker.AsyncUnaryCall(__Method_Div, null, options, request);
}
- public AsyncServerStreamingCall<global::Math.Num> Fib(global::Math.FibArgs request, CallOptions options)
+ public virtual AsyncDuplexStreamingCall<global::Math.DivArgs, global::Math.DivReply> DivMany(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Fib, options);
- return Calls.AsyncServerStreamingCall(call, request);
+ return DivMany(new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncClientStreamingCall<global::Math.Num, global::Math.Num> Sum(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncDuplexStreamingCall<global::Math.DivArgs, global::Math.DivReply> DivMany(CallOptions options)
{
- var call = CreateCall(__Method_Sum, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncClientStreamingCall(call);
+ return CallInvoker.AsyncDuplexStreamingCall(__Method_DivMany, null, options);
}
- public AsyncClientStreamingCall<global::Math.Num, global::Math.Num> Sum(CallOptions options)
+ public virtual AsyncServerStreamingCall<global::Math.Num> Fib(global::Math.FibArgs request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Sum, options);
- return Calls.AsyncClientStreamingCall(call);
+ return Fib(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncServerStreamingCall<global::Math.Num> Fib(global::Math.FibArgs request, CallOptions options)
+ {
+ return CallInvoker.AsyncServerStreamingCall(__Method_Fib, null, options, request);
+ }
+ public virtual AsyncClientStreamingCall<global::Math.Num, global::Math.Num> Sum(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return Sum(new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncClientStreamingCall<global::Math.Num, global::Math.Num> Sum(CallOptions options)
+ {
+ return CallInvoker.AsyncClientStreamingCall(__Method_Sum, null, options);
+ }
+ protected override MathClient NewInstance(ClientBaseConfiguration configuration)
+ {
+ return new MathClient(configuration);
}
}
@@ -143,6 +176,16 @@ namespace Math {
.AddMethod(__Method_Sum, serviceImpl.Sum).Build();
}
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(MathBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_Div, serviceImpl.Div)
+ .AddMethod(__Method_DivMany, serviceImpl.DivMany)
+ .AddMethod(__Method_Fib, serviceImpl.Fib)
+ .AddMethod(__Method_Sum, serviceImpl.Sum).Build();
+ }
+
// creates a new client
public static MathClient NewClient(Channel channel)
{
diff --git a/src/csharp/Grpc.Examples/MathServiceImpl.cs b/src/csharp/Grpc.Examples/MathServiceImpl.cs
index 71dc655e46..79c56e57a8 100644
--- a/src/csharp/Grpc.Examples/MathServiceImpl.cs
+++ b/src/csharp/Grpc.Examples/MathServiceImpl.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -43,14 +43,14 @@ namespace Math
/// <summary>
/// Implementation of MathService server
/// </summary>
- public class MathServiceImpl : Math.IMath
+ public class MathServiceImpl : Math.MathBase
{
- public Task<DivReply> Div(DivArgs request, ServerCallContext context)
+ public override Task<DivReply> Div(DivArgs request, ServerCallContext context)
{
return Task.FromResult(DivInternal(request));
}
- public async Task Fib(FibArgs request, IServerStreamWriter<Num> responseStream, ServerCallContext context)
+ public override async Task Fib(FibArgs request, IServerStreamWriter<Num> responseStream, ServerCallContext context)
{
if (request.Limit <= 0)
{
@@ -72,7 +72,7 @@ namespace Math
}
}
- public async Task<Num> Sum(IAsyncStreamReader<Num> requestStream, ServerCallContext context)
+ public override async Task<Num> Sum(IAsyncStreamReader<Num> requestStream, ServerCallContext context)
{
long sum = 0;
await requestStream.ForEachAsync(async num =>
@@ -82,7 +82,7 @@ namespace Math
return new Num { Num_ = sum };
}
- public async Task DivMany(IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream, ServerCallContext context)
+ public override async Task DivMany(IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream, ServerCallContext context)
{
await requestStream.ForEachAsync(async divArgs => await responseStream.WriteAsync(DivInternal(divArgs)));
}
diff --git a/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs b/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
index a8a76c7492..fb292945a6 100644
--- a/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
+++ b/src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015-2016, Google Inc.
+// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -36,7 +36,7 @@ using System.Text;
using System.Threading.Tasks;
using Grpc.Core;
-using Grpc.Health.V1Alpha;
+using Grpc.Health.V1;
using NUnit.Framework;
namespace Grpc.HealthCheck.Tests
@@ -49,7 +49,7 @@ namespace Grpc.HealthCheck.Tests
const string Host = "localhost";
Server server;
Channel channel;
- Grpc.Health.V1Alpha.Health.IHealthClient client;
+ Grpc.Health.V1.Health.HealthClient client;
Grpc.HealthCheck.HealthServiceImpl serviceImpl;
[TestFixtureSetUp]
@@ -59,13 +59,13 @@ namespace Grpc.HealthCheck.Tests
server = new Server
{
- Services = { Grpc.Health.V1Alpha.Health.BindService(serviceImpl) },
+ Services = { Grpc.Health.V1.Health.BindService(serviceImpl) },
Ports = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } }
};
server.Start();
channel = new Channel(Host, server.Ports.Single().BoundPort, ChannelCredentials.Insecure);
- client = Grpc.Health.V1Alpha.Health.NewClient(channel);
+ client = Grpc.Health.V1.Health.NewClient(channel);
}
[TestFixtureTearDown]
@@ -79,16 +79,16 @@ namespace Grpc.HealthCheck.Tests
[Test]
public void ServiceIsRunning()
{
- serviceImpl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
+ serviceImpl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
- var response = client.Check(new HealthCheckRequest { Host = "", Service = "" });
+ var response = client.Check(new HealthCheckRequest { Service = "" });
Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, response.Status);
}
[Test]
public void ServiceDoesntExist()
{
- Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => client.Check(new HealthCheckRequest { Host = "", Service = "nonexistent.service" }));
+ Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => client.Check(new HealthCheckRequest { Service = "nonexistent.service" }));
}
// TODO(jtattermusch): add test with timeout once timeouts are supported
diff --git a/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs b/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs
index 2097c0dc8c..a4b79e3a7d 100644
--- a/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs
+++ b/src/csharp/Grpc.HealthCheck.Tests/HealthServiceImplTest.cs
@@ -36,7 +36,7 @@ using System.Text;
using System.Threading.Tasks;
using Grpc.Core;
-using Grpc.Health.V1Alpha;
+using Grpc.Health.V1;
using NUnit.Framework;
namespace Grpc.HealthCheck.Tests
@@ -50,58 +50,56 @@ namespace Grpc.HealthCheck.Tests
public void SetStatus()
{
var impl = new HealthServiceImpl();
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "", ""));
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, ""));
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.NOT_SERVING);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NOT_SERVING, GetStatusHelper(impl, "", ""));
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.NOT_SERVING);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.NOT_SERVING, GetStatusHelper(impl, ""));
- impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "virtual-host", ""));
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, ""));
- impl.SetStatus("virtual-host", "grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.SERVING);
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "virtual-host", "grpc.test.TestService"));
+ impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.SERVING);
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.SERVING, GetStatusHelper(impl, "grpc.test.TestService"));
}
[Test]
public void ClearStatus()
{
var impl = new HealthServiceImpl();
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
- impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
+ impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
- impl.ClearStatus("", "");
+ impl.ClearStatus("");
- Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => GetStatusHelper(impl, "", ""));
- Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "virtual-host", ""));
+ Assert.Throws(Is.TypeOf(typeof(RpcException)).And.Property("Status").Property("StatusCode").EqualTo(StatusCode.NotFound), () => GetStatusHelper(impl, ""));
+ Assert.AreEqual(HealthCheckResponse.Types.ServingStatus.UNKNOWN, GetStatusHelper(impl, "grpc.test.TestService"));
}
[Test]
public void ClearAll()
{
var impl = new HealthServiceImpl();
- impl.SetStatus("", "", HealthCheckResponse.Types.ServingStatus.SERVING);
- impl.SetStatus("virtual-host", "", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
+ impl.SetStatus("", HealthCheckResponse.Types.ServingStatus.SERVING);
+ impl.SetStatus("grpc.test.TestService", HealthCheckResponse.Types.ServingStatus.UNKNOWN);
impl.ClearAll();
- Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "", ""));
- Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "virtual-host", ""));
+ Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, ""));
+ Assert.Throws(typeof(RpcException), () => GetStatusHelper(impl, "grpc.test.TestService"));
}
[Test]
public void NullsRejected()
{
var impl = new HealthServiceImpl();
- Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, "", HealthCheckResponse.Types.ServingStatus.SERVING));
- Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus("", null, HealthCheckResponse.Types.ServingStatus.SERVING));
+ Assert.Throws(typeof(ArgumentNullException), () => impl.SetStatus(null, HealthCheckResponse.Types.ServingStatus.SERVING));
- Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null, ""));
- Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus("", null));
+ Assert.Throws(typeof(ArgumentNullException), () => impl.ClearStatus(null));
}
- private static HealthCheckResponse.Types.ServingStatus GetStatusHelper(HealthServiceImpl impl, string host, string service)
+ private static HealthCheckResponse.Types.ServingStatus GetStatusHelper(HealthServiceImpl impl, string service)
{
- return impl.Check(new HealthCheckRequest { Host = host, Service = service }, null).Result.Status;
+ return impl.Check(new HealthCheckRequest { Service = service }, null).Result.Status;
}
}
}
diff --git a/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec b/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
index 66386288df..7b3b391009 100644
--- a/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
+++ b/src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
@@ -4,7 +4,7 @@
<id>Grpc.HealthCheck</id>
<title>gRPC C# Healthchecking</title>
<summary>Implementation of gRPC health service</summary>
- <description>Example implementation of grpc.health.v1alpha service that can be used for health-checking.</description>
+ <description>Example implementation of grpc.health.v1 service that can be used for health-checking.</description>
<version>$version$</version>
<authors>Google Inc.</authors>
<owners>grpc-packages</owners>
diff --git a/src/csharp/Grpc.HealthCheck/Health.cs b/src/csharp/Grpc.HealthCheck/Health.cs
index 56673f1adf..d0d0c0b519 100644
--- a/src/csharp/Grpc.HealthCheck/Health.cs
+++ b/src/csharp/Grpc.HealthCheck/Health.cs
@@ -7,7 +7,7 @@ using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
-namespace Grpc.Health.V1Alpha {
+namespace Grpc.Health.V1 {
/// <summary>Holder for reflection information generated from health.proto</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
@@ -23,20 +23,19 @@ namespace Grpc.Health.V1Alpha {
static HealthReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
- "CgxoZWFsdGgucHJvdG8SE2dycGMuaGVhbHRoLnYxYWxwaGEiMwoSSGVhbHRo",
- "Q2hlY2tSZXF1ZXN0EgwKBGhvc3QYASABKAkSDwoHc2VydmljZRgCIAEoCSKZ",
- "AQoTSGVhbHRoQ2hlY2tSZXNwb25zZRJGCgZzdGF0dXMYASABKA4yNi5ncnBj",
- "LmhlYWx0aC52MWFscGhhLkhlYWx0aENoZWNrUmVzcG9uc2UuU2VydmluZ1N0",
- "YXR1cyI6Cg1TZXJ2aW5nU3RhdHVzEgsKB1VOS05PV04QABILCgdTRVJWSU5H",
- "EAESDwoLTk9UX1NFUlZJTkcQAjJkCgZIZWFsdGgSWgoFQ2hlY2sSJy5ncnBj",
- "LmhlYWx0aC52MWFscGhhLkhlYWx0aENoZWNrUmVxdWVzdBooLmdycGMuaGVh",
- "bHRoLnYxYWxwaGEuSGVhbHRoQ2hlY2tSZXNwb25zZUIWqgITR3JwYy5IZWFs",
- "dGguVjFBbHBoYWIGcHJvdG8z"));
+ "CgxoZWFsdGgucHJvdG8SDmdycGMuaGVhbHRoLnYxIiUKEkhlYWx0aENoZWNr",
+ "UmVxdWVzdBIPCgdzZXJ2aWNlGAEgASgJIpQBChNIZWFsdGhDaGVja1Jlc3Bv",
+ "bnNlEkEKBnN0YXR1cxgBIAEoDjIxLmdycGMuaGVhbHRoLnYxLkhlYWx0aENo",
+ "ZWNrUmVzcG9uc2UuU2VydmluZ1N0YXR1cyI6Cg1TZXJ2aW5nU3RhdHVzEgsK",
+ "B1VOS05PV04QABILCgdTRVJWSU5HEAESDwoLTk9UX1NFUlZJTkcQAjJaCgZI",
+ "ZWFsdGgSUAoFQ2hlY2sSIi5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jl",
+ "cXVlc3QaIy5ncnBjLmhlYWx0aC52MS5IZWFsdGhDaGVja1Jlc3BvbnNlQhGq",
+ "Ag5HcnBjLkhlYWx0aC5WMWIGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] {
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1Alpha.HealthCheckRequest), global::Grpc.Health.V1Alpha.HealthCheckRequest.Parser, new[]{ "Host", "Service" }, null, null, null),
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1Alpha.HealthCheckResponse), global::Grpc.Health.V1Alpha.HealthCheckResponse.Parser, new[]{ "Status" }, null, new[]{ typeof(global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus) }, null)
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1.HealthCheckRequest), global::Grpc.Health.V1.HealthCheckRequest.Parser, new[]{ "Service" }, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Health.V1.HealthCheckResponse), global::Grpc.Health.V1.HealthCheckResponse.Parser, new[]{ "Status" }, null, new[]{ typeof(global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus) }, null)
}));
}
#endregion
@@ -49,7 +48,7 @@ namespace Grpc.Health.V1Alpha {
public static pb::MessageParser<HealthCheckRequest> Parser { get { return _parser; } }
public static pbr::MessageDescriptor Descriptor {
- get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.MessageTypes[0]; }
+ get { return global::Grpc.Health.V1.HealthReflection.Descriptor.MessageTypes[0]; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor {
@@ -63,7 +62,6 @@ namespace Grpc.Health.V1Alpha {
partial void OnConstruction();
public HealthCheckRequest(HealthCheckRequest other) : this() {
- host_ = other.host_;
service_ = other.service_;
}
@@ -71,18 +69,8 @@ namespace Grpc.Health.V1Alpha {
return new HealthCheckRequest(this);
}
- /// <summary>Field number for the "host" field.</summary>
- public const int HostFieldNumber = 1;
- private string host_ = "";
- public string Host {
- get { return host_; }
- set {
- host_ = pb::Preconditions.CheckNotNull(value, "value");
- }
- }
-
/// <summary>Field number for the "service" field.</summary>
- public const int ServiceFieldNumber = 2;
+ public const int ServiceFieldNumber = 1;
private string service_ = "";
public string Service {
get { return service_; }
@@ -102,14 +90,12 @@ namespace Grpc.Health.V1Alpha {
if (ReferenceEquals(other, this)) {
return true;
}
- if (Host != other.Host) return false;
if (Service != other.Service) return false;
return true;
}
public override int GetHashCode() {
int hash = 1;
- if (Host.Length != 0) hash ^= Host.GetHashCode();
if (Service.Length != 0) hash ^= Service.GetHashCode();
return hash;
}
@@ -119,21 +105,14 @@ namespace Grpc.Health.V1Alpha {
}
public void WriteTo(pb::CodedOutputStream output) {
- if (Host.Length != 0) {
- output.WriteRawTag(10);
- output.WriteString(Host);
- }
if (Service.Length != 0) {
- output.WriteRawTag(18);
+ output.WriteRawTag(10);
output.WriteString(Service);
}
}
public int CalculateSize() {
int size = 0;
- if (Host.Length != 0) {
- size += 1 + pb::CodedOutputStream.ComputeStringSize(Host);
- }
if (Service.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Service);
}
@@ -144,9 +123,6 @@ namespace Grpc.Health.V1Alpha {
if (other == null) {
return;
}
- if (other.Host.Length != 0) {
- Host = other.Host;
- }
if (other.Service.Length != 0) {
Service = other.Service;
}
@@ -160,10 +136,6 @@ namespace Grpc.Health.V1Alpha {
input.SkipLastField();
break;
case 10: {
- Host = input.ReadString();
- break;
- }
- case 18: {
Service = input.ReadString();
break;
}
@@ -179,7 +151,7 @@ namespace Grpc.Health.V1Alpha {
public static pb::MessageParser<HealthCheckResponse> Parser { get { return _parser; } }
public static pbr::MessageDescriptor Descriptor {
- get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.MessageTypes[1]; }
+ get { return global::Grpc.Health.V1.HealthReflection.Descriptor.MessageTypes[1]; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor {
@@ -202,8 +174,8 @@ namespace Grpc.Health.V1Alpha {
/// <summary>Field number for the "status" field.</summary>
public const int StatusFieldNumber = 1;
- private global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus status_ = global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN;
- public global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus Status {
+ private global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus status_ = global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN;
+ public global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus Status {
get { return status_; }
set {
status_ = value;
@@ -227,7 +199,7 @@ namespace Grpc.Health.V1Alpha {
public override int GetHashCode() {
int hash = 1;
- if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) hash ^= Status.GetHashCode();
+ if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) hash ^= Status.GetHashCode();
return hash;
}
@@ -236,7 +208,7 @@ namespace Grpc.Health.V1Alpha {
}
public void WriteTo(pb::CodedOutputStream output) {
- if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
+ if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
output.WriteRawTag(8);
output.WriteEnum((int) Status);
}
@@ -244,7 +216,7 @@ namespace Grpc.Health.V1Alpha {
public int CalculateSize() {
int size = 0;
- if (Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
+ if (Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Status);
}
return size;
@@ -254,7 +226,7 @@ namespace Grpc.Health.V1Alpha {
if (other == null) {
return;
}
- if (other.Status != global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
+ if (other.Status != global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.UNKNOWN) {
Status = other.Status;
}
}
@@ -267,7 +239,7 @@ namespace Grpc.Health.V1Alpha {
input.SkipLastField();
break;
case 8: {
- status_ = (global::Grpc.Health.V1Alpha.HealthCheckResponse.Types.ServingStatus) input.ReadEnum();
+ status_ = (global::Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus) input.ReadEnum();
break;
}
}
diff --git a/src/csharp/Grpc.HealthCheck/HealthGrpc.cs b/src/csharp/Grpc.HealthCheck/HealthGrpc.cs
index 882edd5627..72e11cca3a 100644
--- a/src/csharp/Grpc.HealthCheck/HealthGrpc.cs
+++ b/src/csharp/Grpc.HealthCheck/HealthGrpc.cs
@@ -7,15 +7,15 @@ using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
-namespace Grpc.Health.V1Alpha {
+namespace Grpc.Health.V1 {
public static class Health
{
- static readonly string __ServiceName = "grpc.health.v1alpha.Health";
+ static readonly string __ServiceName = "grpc.health.v1.Health";
- static readonly Marshaller<global::Grpc.Health.V1Alpha.HealthCheckRequest> __Marshaller_HealthCheckRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1Alpha.HealthCheckRequest.Parser.ParseFrom);
- static readonly Marshaller<global::Grpc.Health.V1Alpha.HealthCheckResponse> __Marshaller_HealthCheckResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1Alpha.HealthCheckResponse.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Health.V1.HealthCheckRequest> __Marshaller_HealthCheckRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1.HealthCheckRequest.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Health.V1.HealthCheckResponse> __Marshaller_HealthCheckResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Health.V1.HealthCheckResponse.Parser.ParseFrom);
- static readonly Method<global::Grpc.Health.V1Alpha.HealthCheckRequest, global::Grpc.Health.V1Alpha.HealthCheckResponse> __Method_Check = new Method<global::Grpc.Health.V1Alpha.HealthCheckRequest, global::Grpc.Health.V1Alpha.HealthCheckResponse>(
+ static readonly Method<global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse> __Method_Check = new Method<global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse>(
MethodType.Unary,
__ServiceName,
"Check",
@@ -25,49 +25,73 @@ namespace Grpc.Health.V1Alpha {
// service descriptor
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
- get { return global::Grpc.Health.V1Alpha.HealthReflection.Descriptor.Services[0]; }
+ get { return global::Grpc.Health.V1.HealthReflection.Descriptor.Services[0]; }
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IHealthClient
{
- global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
- global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options);
- AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
- AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options);
+ global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options);
+ AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options);
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IHealth
{
- Task<global::Grpc.Health.V1Alpha.HealthCheckResponse> Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, ServerCallContext context);
+ Task<global::Grpc.Health.V1.HealthCheckResponse> Check(global::Grpc.Health.V1.HealthCheckRequest request, ServerCallContext context);
+ }
+
+ // server-side abstract class
+ public abstract class HealthBase
+ {
+ public virtual Task<global::Grpc.Health.V1.HealthCheckResponse> Check(global::Grpc.Health.V1.HealthCheckRequest request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
}
// client stub
- public class HealthClient : ClientBase, IHealthClient
+ public class HealthClient : ClientBase<HealthClient>, IHealthClient
{
public HealthClient(Channel channel) : base(channel)
{
}
- public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public HealthClient(CallInvoker callInvoker) : base(callInvoker)
{
- var call = CreateCall(__Method_Check, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
}
- public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options)
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected HealthClient() : base()
+ {
+ }
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected HealthClient(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ public virtual global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Check, options);
- return Calls.BlockingUnaryCall(call, request);
+ return Check(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual global::Grpc.Health.V1.HealthCheckResponse Check(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options)
{
- var call = CreateCall(__Method_Check, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
+ return CallInvoker.BlockingUnaryCall(__Method_Check, null, options, request);
}
- public AsyncUnaryCall<global::Grpc.Health.V1Alpha.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Check, options);
- return Calls.AsyncUnaryCall(call, request);
+ return CheckAsync(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncUnaryCall<global::Grpc.Health.V1.HealthCheckResponse> CheckAsync(global::Grpc.Health.V1.HealthCheckRequest request, CallOptions options)
+ {
+ return CallInvoker.AsyncUnaryCall(__Method_Check, null, options, request);
+ }
+ protected override HealthClient NewInstance(ClientBaseConfiguration configuration)
+ {
+ return new HealthClient(configuration);
}
}
@@ -78,6 +102,13 @@ namespace Grpc.Health.V1Alpha {
.AddMethod(__Method_Check, serviceImpl.Check).Build();
}
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(HealthBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_Check, serviceImpl.Check).Build();
+ }
+
// creates a new client
public static HealthClient NewClient(Channel channel)
{
diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
index 26c6445c35..d0406ece00 100644
--- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
+++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
@@ -37,7 +37,7 @@ using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Utils;
-using Grpc.Health.V1Alpha;
+using Grpc.Health.V1;
namespace Grpc.HealthCheck
{
@@ -48,44 +48,42 @@ namespace Grpc.HealthCheck
/// <code>
/// var serviceImpl = new HealthServiceImpl();
/// server = new Server();
- /// server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl));
+ /// server.AddServiceDefinition(Grpc.Health.V1.Health.BindService(serviceImpl));
/// </code>
/// </summary>
- public class HealthServiceImpl : Grpc.Health.V1Alpha.Health.IHealth
+ public class HealthServiceImpl : Grpc.Health.V1.Health.HealthBase
{
private readonly object myLock = new object();
- private readonly Dictionary<Key, HealthCheckResponse.Types.ServingStatus> statusMap =
- new Dictionary<Key, HealthCheckResponse.Types.ServingStatus>();
+ private readonly Dictionary<string, HealthCheckResponse.Types.ServingStatus> statusMap =
+ new Dictionary<string, HealthCheckResponse.Types.ServingStatus>();
/// <summary>
- /// Sets the health status for given host and service.
+ /// Sets the health status for given service.
/// </summary>
- /// <param name="host">The host. Cannot be null.</param>
/// <param name="service">The service. Cannot be null.</param>
/// <param name="status">the health status</param>
- public void SetStatus(string host, string service, HealthCheckResponse.Types.ServingStatus status)
+ public void SetStatus(string service, HealthCheckResponse.Types.ServingStatus status)
{
lock (myLock)
{
- statusMap[CreateKey(host, service)] = status;
+ statusMap[service] = status;
}
}
/// <summary>
- /// Clears health status for given host and service.
+ /// Clears health status for given service.
/// </summary>
- /// <param name="host">The host. Cannot be null.</param>
/// <param name="service">The service. Cannot be null.</param>
- public void ClearStatus(string host, string service)
+ public void ClearStatus(string service)
{
lock (myLock)
{
- statusMap.Remove(CreateKey(host, service));
+ statusMap.Remove(service);
}
}
/// <summary>
- /// Clears statuses for all hosts and services.
+ /// Clears statuses for all services.
/// </summary>
public void ClearAll()
{
@@ -101,15 +99,14 @@ namespace Grpc.HealthCheck
/// <param name="request">The check request.</param>
/// <param name="context">The call context.</param>
/// <returns>The asynchronous response.</returns>
- public Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context)
+ public override Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context)
{
lock (myLock)
{
- var host = request.Host;
var service = request.Service;
HealthCheckResponse.Types.ServingStatus status;
- if (!statusMap.TryGetValue(CreateKey(host, service), out status))
+ if (!statusMap.TryGetValue(service, out status))
{
// TODO(jtattermusch): returning specific status from server handler is not supported yet.
throw new RpcException(new Status(StatusCode.NotFound, ""));
@@ -117,22 +114,5 @@ namespace Grpc.HealthCheck
return Task.FromResult(new HealthCheckResponse { Status = status });
}
}
-
- private static Key CreateKey(string host, string service)
- {
- return new Key(host, service);
- }
-
- private struct Key
- {
- public Key(string host, string service)
- {
- this.Host = Preconditions.CheckNotNull(host);
- this.Service = Preconditions.CheckNotNull(service);
- }
-
- readonly string Host;
- readonly string Service;
- }
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting.Client/Grpc.IntegrationTesting.Client.csproj b/src/csharp/Grpc.IntegrationTesting.Client/Grpc.IntegrationTesting.Client.csproj
index f37c1464c3..339a754c02 100644
--- a/src/csharp/Grpc.IntegrationTesting.Client/Grpc.IntegrationTesting.Client.csproj
+++ b/src/csharp/Grpc.IntegrationTesting.Client/Grpc.IntegrationTesting.Client.csproj
@@ -9,7 +9,7 @@
<AssemblyName>Grpc.IntegrationTesting.Client</AssemblyName>
<StartupObject>Grpc.IntegrationTesting.Client.Program</StartupObject>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <NuGetPackageImportStamp>6d22e68f</NuGetPackageImportStamp>
+ <NuGetPackageImportStamp>dfa56e6c</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -43,28 +43,17 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Auth, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.PlatformServices.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.PlatformServices.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Core, Version=1.10.0.25331, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Core, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Core.1.10.0\lib\portable-net40+sl50+win+wpa81+wp80\Google.Apis.Core.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Core.1.11.1\lib\net45\Google.Apis.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -73,12 +62,6 @@
<Reference Include="System" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
- <Reference Include="System.Net.Http.Extensions">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http.Primitives">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
- </Reference>
<Reference Include="System.Net.Http.WebRequest" />
</ItemGroup>
<ItemGroup>
@@ -100,14 +83,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
- <Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
- <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
- <PropertyGroup>
- <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
- </PropertyGroup>
- <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
- </Target>
</Project> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting.Client/app.config b/src/csharp/Grpc.IntegrationTesting.Client/app.config
deleted file mode 100644
index 84d7534d65..0000000000
--- a/src/csharp/Grpc.IntegrationTesting.Client/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.0.0.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.9.2.38523" newVersion="1.9.2.38523" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
-</configuration> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting.Client/packages.config b/src/csharp/Grpc.IntegrationTesting.Client/packages.config
index 5fe8ca616c..c20d9ceed6 100644
--- a/src/csharp/Grpc.IntegrationTesting.Client/packages.config
+++ b/src/csharp/Grpc.IntegrationTesting.Client/packages.config
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.7.0" targetFramework="net45" />
- <package id="Google.Apis.Auth" version="1.10.0" targetFramework="net45" />
- <package id="Google.Apis.Core" version="1.10.0" targetFramework="net45" />
- <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
- <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
- <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
- <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />
+ <package id="Google.Apis.Auth" version="1.11.1" targetFramework="net45" />
+ <package id="Google.Apis.Core" version="1.11.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting.QpsWorker/app.config b/src/csharp/Grpc.IntegrationTesting.QpsWorker/app.config
index 940d25cae3..e204447bb3 100644
--- a/src/csharp/Grpc.IntegrationTesting.QpsWorker/app.config
+++ b/src/csharp/Grpc.IntegrationTesting.QpsWorker/app.config
@@ -6,6 +6,10 @@
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-1.11.1.0" newVersion="1.11.1.0" />
+ </dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting.Server/Grpc.IntegrationTesting.Server.csproj b/src/csharp/Grpc.IntegrationTesting.Server/Grpc.IntegrationTesting.Server.csproj
index f27b96a53f..27a5650308 100644
--- a/src/csharp/Grpc.IntegrationTesting.Server/Grpc.IntegrationTesting.Server.csproj
+++ b/src/csharp/Grpc.IntegrationTesting.Server/Grpc.IntegrationTesting.Server.csproj
@@ -9,7 +9,7 @@
<AssemblyName>Grpc.IntegrationTesting.Server</AssemblyName>
<StartupObject>Grpc.IntegrationTesting.Server.Program</StartupObject>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <NuGetPackageImportStamp>d9ee8e52</NuGetPackageImportStamp>
+ <NuGetPackageImportStamp>7ceb739e</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -43,28 +43,17 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Auth, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.PlatformServices.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.PlatformServices.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Core, Version=1.10.0.25331, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Core, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Core.1.10.0\lib\portable-net40+sl50+win+wpa81+wp80\Google.Apis.Core.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Core.1.11.1\lib\net45\Google.Apis.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -73,12 +62,6 @@
<Reference Include="System" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
- <Reference Include="System.Net.Http.Extensions">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="System.Net.Http.Primitives">
- <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
- </Reference>
<Reference Include="System.Net.Http.WebRequest" />
</ItemGroup>
<ItemGroup>
@@ -100,14 +83,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
- <Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
- <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
- <PropertyGroup>
- <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
- </PropertyGroup>
- <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
- </Target>
</Project> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting.Server/app.config b/src/csharp/Grpc.IntegrationTesting.Server/app.config
deleted file mode 100644
index 84d7534d65..0000000000
--- a/src/csharp/Grpc.IntegrationTesting.Server/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.0.0.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.9.2.38523" newVersion="1.9.2.38523" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
-</configuration> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting.Server/packages.config b/src/csharp/Grpc.IntegrationTesting.Server/packages.config
index 5fe8ca616c..c20d9ceed6 100644
--- a/src/csharp/Grpc.IntegrationTesting.Server/packages.config
+++ b/src/csharp/Grpc.IntegrationTesting.Server/packages.config
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.7.0" targetFramework="net45" />
- <package id="Google.Apis.Auth" version="1.10.0" targetFramework="net45" />
- <package id="Google.Apis.Core" version="1.10.0" targetFramework="net45" />
- <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
- <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
- <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
- <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />
+ <package id="Google.Apis.Auth" version="1.11.1" targetFramework="net45" />
+ <package id="Google.Apis.Core" version="1.11.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting/BenchmarkServiceImpl.cs b/src/csharp/Grpc.IntegrationTesting/BenchmarkServiceImpl.cs
index 47a15224f1..07f2703d4a 100644
--- a/src/csharp/Grpc.IntegrationTesting/BenchmarkServiceImpl.cs
+++ b/src/csharp/Grpc.IntegrationTesting/BenchmarkServiceImpl.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -44,26 +44,23 @@ namespace Grpc.Testing
/// <summary>
/// Implementation of BenchmarkService server
/// </summary>
- public class BenchmarkServiceImpl : BenchmarkService.IBenchmarkService
+ public class BenchmarkServiceImpl : BenchmarkService.BenchmarkServiceBase
{
- private readonly int responseSize;
-
- public BenchmarkServiceImpl(int responseSize)
+ public BenchmarkServiceImpl()
{
- this.responseSize = responseSize;
}
- public Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
+ public override Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
{
- var response = new SimpleResponse { Payload = CreateZerosPayload(responseSize) };
+ var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
return Task.FromResult(response);
}
- public async Task StreamingCall(IAsyncStreamReader<SimpleRequest> requestStream, IServerStreamWriter<SimpleResponse> responseStream, ServerCallContext context)
+ public override async Task StreamingCall(IAsyncStreamReader<SimpleRequest> requestStream, IServerStreamWriter<SimpleResponse> responseStream, ServerCallContext context)
{
await requestStream.ForEachAsync(async request =>
{
- var response = new SimpleResponse { Payload = CreateZerosPayload(responseSize) };
+ var response = new SimpleResponse { Payload = CreateZerosPayload(request.ResponseSize) };
await responseStream.WriteAsync(response);
});
}
diff --git a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
index e9e659cb1f..f954ca5f34 100644
--- a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
@@ -41,6 +41,7 @@ using System.Threading;
using System.Threading.Tasks;
using Google.Protobuf;
using Grpc.Core;
+using Grpc.Core.Logging;
using Grpc.Core.Utils;
using NUnit.Framework;
using Grpc.Testing;
@@ -50,58 +51,100 @@ namespace Grpc.IntegrationTesting
/// <summary>
/// Helper methods to start client runners for performance testing.
/// </summary>
- public static class ClientRunners
+ public class ClientRunners
{
+ static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<ClientRunners>();
+
/// <summary>
/// Creates a started client runner.
/// </summary>
public static IClientRunner CreateStarted(ClientConfig config)
{
- string target = config.ServerTargets.Single();
- Grpc.Core.Utils.Preconditions.CheckArgument(config.LoadParams.LoadCase == LoadParams.LoadOneofCase.ClosedLoop);
+ Logger.Debug("ClientConfig: {0}", config);
+
+ if (config.AsyncClientThreads != 0)
+ {
+ Logger.Warning("ClientConfig.AsyncClientThreads is not supported for C#. Ignoring the value");
+ }
+ if (config.CoreLimit != 0)
+ {
+ Logger.Warning("ClientConfig.CoreLimit is not supported for C#. Ignoring the value");
+ }
+ if (config.CoreList.Count > 0)
+ {
+ Logger.Warning("ClientConfig.CoreList is not supported for C#. Ignoring the value");
+ }
+
+ var channels = CreateChannels(config.ClientChannels, config.ServerTargets, config.SecurityParams);
+
+ return new ClientRunnerImpl(channels,
+ config.ClientType,
+ config.RpcType,
+ config.OutstandingRpcsPerChannel,
+ config.LoadParams,
+ config.PayloadConfig,
+ config.HistogramParams);
+ }
- var credentials = config.SecurityParams != null ? TestCredentials.CreateSslCredentials() : ChannelCredentials.Insecure;
- var channel = new Channel(target, credentials);
+ private static List<Channel> CreateChannels(int clientChannels, IEnumerable<string> serverTargets, SecurityParams securityParams)
+ {
+ GrpcPreconditions.CheckArgument(clientChannels > 0, "clientChannels needs to be at least 1.");
+ GrpcPreconditions.CheckArgument(serverTargets.Count() > 0, "at least one serverTarget needs to be specified.");
- switch (config.RpcType)
+ var credentials = securityParams != null ? TestCredentials.CreateSslCredentials() : ChannelCredentials.Insecure;
+ List<ChannelOption> channelOptions = null;
+ if (securityParams != null && securityParams.ServerHostOverride != "")
{
- case RpcType.UNARY:
- return new SyncUnaryClientRunner(channel,
- config.PayloadConfig.SimpleParams.ReqSize,
- config.HistogramParams);
+ channelOptions = new List<ChannelOption>
+ {
+ new ChannelOption(ChannelOptions.SslTargetNameOverride, securityParams.ServerHostOverride)
+ };
+ }
- case RpcType.STREAMING:
- default:
- throw new ArgumentException("Unsupported RpcType.");
+ var result = new List<Channel>();
+ for (int i = 0; i < clientChannels; i++)
+ {
+ var target = serverTargets.ElementAt(i % serverTargets.Count());
+ var channel = new Channel(target, credentials, channelOptions);
+ result.Add(channel);
}
+ return result;
}
}
- /// <summary>
- /// Client that starts synchronous unary calls in a closed loop.
- /// </summary>
- public class SyncUnaryClientRunner : IClientRunner
+ public class ClientRunnerImpl : IClientRunner
{
const double SecondsToNanos = 1e9;
- readonly Channel channel;
- readonly int payloadSize;
+ readonly List<Channel> channels;
+ readonly ClientType clientType;
+ readonly RpcType rpcType;
+ readonly PayloadConfig payloadConfig;
readonly Histogram histogram;
- readonly BenchmarkService.IBenchmarkServiceClient client;
- readonly Task runnerTask;
- readonly CancellationTokenSource stoppedCts;
+ readonly List<Task> runnerTasks;
+ readonly CancellationTokenSource stoppedCts = new CancellationTokenSource();
readonly WallClockStopwatch wallClockStopwatch = new WallClockStopwatch();
- public SyncUnaryClientRunner(Channel channel, int payloadSize, HistogramParams histogramParams)
+ public ClientRunnerImpl(List<Channel> channels, ClientType clientType, RpcType rpcType, int outstandingRpcsPerChannel, LoadParams loadParams, PayloadConfig payloadConfig, HistogramParams histogramParams)
{
- this.channel = Grpc.Core.Utils.Preconditions.CheckNotNull(channel);
- this.payloadSize = payloadSize;
+ GrpcPreconditions.CheckArgument(outstandingRpcsPerChannel > 0, "outstandingRpcsPerChannel");
+ this.channels = new List<Channel>(channels);
+ this.clientType = clientType;
+ this.rpcType = rpcType;
+ this.payloadConfig = payloadConfig;
this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);
- this.stoppedCts = new CancellationTokenSource();
- this.client = BenchmarkService.NewClient(channel);
- this.runnerTask = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
+ this.runnerTasks = new List<Task>();
+ foreach (var channel in this.channels)
+ {
+ for (int i = 0; i < outstandingRpcsPerChannel; i++)
+ {
+ var timer = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
+ var threadBody = GetThreadBody(channel, timer);
+ this.runnerTasks.Add(Task.Factory.StartNew(threadBody, TaskCreationOptions.LongRunning));
+ }
+ }
}
public ClientStats GetStats(bool reset)
@@ -122,16 +165,20 @@ namespace Grpc.IntegrationTesting
public async Task StopAsync()
{
stoppedCts.Cancel();
- await runnerTask;
- await channel.ShutdownAsync();
+ foreach (var runnerTask in runnerTasks)
+ {
+ await runnerTask;
+ }
+ foreach (var channel in channels)
+ {
+ await channel.ShutdownAsync();
+ }
}
- private void Run()
+ private void RunUnary(Channel channel, IInterarrivalTimer timer)
{
- var request = new SimpleRequest
- {
- Payload = CreateZerosPayload(payloadSize)
- };
+ var client = BenchmarkService.NewClient(channel);
+ var request = CreateSimpleRequest();
var stopwatch = new Stopwatch();
while (!stoppedCts.Token.IsCancellationRequested)
@@ -142,12 +189,153 @@ namespace Grpc.IntegrationTesting
// spec requires data point in nanoseconds.
histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);
+
+ timer.WaitForNext();
}
}
+ private async Task RunUnaryAsync(Channel channel, IInterarrivalTimer timer)
+ {
+ var client = BenchmarkService.NewClient(channel);
+ var request = CreateSimpleRequest();
+ var stopwatch = new Stopwatch();
+
+ while (!stoppedCts.Token.IsCancellationRequested)
+ {
+ stopwatch.Restart();
+ await client.UnaryCallAsync(request);
+ stopwatch.Stop();
+
+ // spec requires data point in nanoseconds.
+ histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);
+
+ await timer.WaitForNextAsync();
+ }
+ }
+
+ private async Task RunStreamingPingPongAsync(Channel channel, IInterarrivalTimer timer)
+ {
+ var client = BenchmarkService.NewClient(channel);
+ var request = CreateSimpleRequest();
+ var stopwatch = new Stopwatch();
+
+ using (var call = client.StreamingCall())
+ {
+ while (!stoppedCts.Token.IsCancellationRequested)
+ {
+ stopwatch.Restart();
+ await call.RequestStream.WriteAsync(request);
+ await call.ResponseStream.MoveNext();
+ stopwatch.Stop();
+
+ // spec requires data point in nanoseconds.
+ histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);
+
+ await timer.WaitForNextAsync();
+ }
+
+ // finish the streaming call
+ await call.RequestStream.CompleteAsync();
+ Assert.IsFalse(await call.ResponseStream.MoveNext());
+ }
+ }
+
+ private async Task RunGenericStreamingAsync(Channel channel, IInterarrivalTimer timer)
+ {
+ var request = CreateByteBufferRequest();
+ var stopwatch = new Stopwatch();
+
+ var callDetails = new CallInvocationDetails<byte[], byte[]>(channel, GenericService.StreamingCallMethod, new CallOptions());
+
+ using (var call = Calls.AsyncDuplexStreamingCall(callDetails))
+ {
+ while (!stoppedCts.Token.IsCancellationRequested)
+ {
+ stopwatch.Restart();
+ await call.RequestStream.WriteAsync(request);
+ await call.ResponseStream.MoveNext();
+ stopwatch.Stop();
+
+ // spec requires data point in nanoseconds.
+ histogram.AddObservation(stopwatch.Elapsed.TotalSeconds * SecondsToNanos);
+
+ await timer.WaitForNextAsync();
+ }
+
+ // finish the streaming call
+ await call.RequestStream.CompleteAsync();
+ Assert.IsFalse(await call.ResponseStream.MoveNext());
+ }
+ }
+
+ private Action GetThreadBody(Channel channel, IInterarrivalTimer timer)
+ {
+ if (payloadConfig.PayloadCase == PayloadConfig.PayloadOneofCase.BytebufParams)
+ {
+ GrpcPreconditions.CheckArgument(clientType == ClientType.ASYNC_CLIENT, "Generic client only supports async API");
+ GrpcPreconditions.CheckArgument(rpcType == RpcType.STREAMING, "Generic client only supports streaming calls");
+ return () =>
+ {
+ RunGenericStreamingAsync(channel, timer).Wait();
+ };
+ }
+
+ GrpcPreconditions.CheckNotNull(payloadConfig.SimpleParams);
+ if (clientType == ClientType.SYNC_CLIENT)
+ {
+ GrpcPreconditions.CheckArgument(rpcType == RpcType.UNARY, "Sync client can only be used for Unary calls in C#");
+ return () => RunUnary(channel, timer);
+ }
+ else if (clientType == ClientType.ASYNC_CLIENT)
+ {
+ switch (rpcType)
+ {
+ case RpcType.UNARY:
+ return () =>
+ {
+ RunUnaryAsync(channel, timer).Wait();
+ };
+ case RpcType.STREAMING:
+ return () =>
+ {
+ RunStreamingPingPongAsync(channel, timer).Wait();
+ };
+ }
+ }
+ throw new ArgumentException("Unsupported configuration.");
+ }
+
+ private SimpleRequest CreateSimpleRequest()
+ {
+ GrpcPreconditions.CheckNotNull(payloadConfig.SimpleParams);
+ return new SimpleRequest
+ {
+ Payload = CreateZerosPayload(payloadConfig.SimpleParams.ReqSize),
+ ResponseSize = payloadConfig.SimpleParams.RespSize
+ };
+ }
+
+ private byte[] CreateByteBufferRequest()
+ {
+ return new byte[payloadConfig.BytebufParams.ReqSize];
+ }
+
private static Payload CreateZerosPayload(int size)
{
return new Payload { Body = ByteString.CopyFrom(new byte[size]) };
}
+
+ private static IInterarrivalTimer CreateTimer(LoadParams loadParams, double loadMultiplier)
+ {
+ switch (loadParams.LoadCase)
+ {
+ case LoadParams.LoadOneofCase.ClosedLoop:
+ return new ClosedLoopInterarrivalTimer();
+ case LoadParams.LoadOneofCase.Poisson:
+ return new PoissonInterarrivalTimer(loadParams.Poisson.OfferedLoad * loadMultiplier);
+ default:
+ throw new ArgumentException("Unknown load type");
+ }
+ }
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting/Control.cs b/src/csharp/Grpc.IntegrationTesting/Control.cs
index b90243c2bd..291bc75397 100644
--- a/src/csharp/Grpc.IntegrationTesting/Control.cs
+++ b/src/csharp/Grpc.IntegrationTesting/Control.cs
@@ -38,7 +38,7 @@ namespace Grpc.Testing {
"LmdycGMudGVzdGluZy5EZXRlcm1pbmlzdGljUGFyYW1zSAASLAoGcGFyZXRv",
"GAUgASgLMhouZ3JwYy50ZXN0aW5nLlBhcmV0b1BhcmFtc0gAQgYKBGxvYWQi",
"QwoOU2VjdXJpdHlQYXJhbXMSEwoLdXNlX3Rlc3RfY2EYASABKAgSHAoUc2Vy",
- "dmVyX2hvc3Rfb3ZlcnJpZGUYAiABKAkirwMKDENsaWVudENvbmZpZxIWCg5z",
+ "dmVyX2hvc3Rfb3ZlcnJpZGUYAiABKAki1gMKDENsaWVudENvbmZpZxIWCg5z",
"ZXJ2ZXJfdGFyZ2V0cxgBIAMoCRItCgtjbGllbnRfdHlwZRgCIAEoDjIYLmdy",
"cGMudGVzdGluZy5DbGllbnRUeXBlEjUKD3NlY3VyaXR5X3BhcmFtcxgDIAEo",
"CzIcLmdycGMudGVzdGluZy5TZWN1cml0eVBhcmFtcxIkChxvdXRzdGFuZGlu",
@@ -48,24 +48,27 @@ namespace Grpc.Testing {
"GAogASgLMhguZ3JwYy50ZXN0aW5nLkxvYWRQYXJhbXMSMwoOcGF5bG9hZF9j",
"b25maWcYCyABKAsyGy5ncnBjLnRlc3RpbmcuUGF5bG9hZENvbmZpZxI3ChBo",
"aXN0b2dyYW1fcGFyYW1zGAwgASgLMh0uZ3JwYy50ZXN0aW5nLkhpc3RvZ3Jh",
- "bVBhcmFtcyI4CgxDbGllbnRTdGF0dXMSKAoFc3RhdHMYASABKAsyGS5ncnBj",
- "LnRlc3RpbmcuQ2xpZW50U3RhdHMiFQoETWFyaxINCgVyZXNldBgBIAEoCCJo",
- "CgpDbGllbnRBcmdzEisKBXNldHVwGAEgASgLMhouZ3JwYy50ZXN0aW5nLkNs",
- "aWVudENvbmZpZ0gAEiIKBG1hcmsYAiABKAsyEi5ncnBjLnRlc3RpbmcuTWFy",
- "a0gAQgkKB2FyZ3R5cGUi9wEKDFNlcnZlckNvbmZpZxItCgtzZXJ2ZXJfdHlw",
- "ZRgBIAEoDjIYLmdycGMudGVzdGluZy5TZXJ2ZXJUeXBlEjUKD3NlY3VyaXR5",
- "X3BhcmFtcxgCIAEoCzIcLmdycGMudGVzdGluZy5TZWN1cml0eVBhcmFtcxIM",
- "CgRob3N0GAMgASgJEgwKBHBvcnQYBCABKAUSHAoUYXN5bmNfc2VydmVyX3Ro",
- "cmVhZHMYByABKAUSEgoKY29yZV9saW1pdBgIIAEoBRIzCg5wYXlsb2FkX2Nv",
- "bmZpZxgJIAEoCzIbLmdycGMudGVzdGluZy5QYXlsb2FkQ29uZmlnImgKClNl",
- "cnZlckFyZ3MSKwoFc2V0dXAYASABKAsyGi5ncnBjLnRlc3RpbmcuU2VydmVy",
- "Q29uZmlnSAASIgoEbWFyaxgCIAEoCzISLmdycGMudGVzdGluZy5NYXJrSABC",
- "CQoHYXJndHlwZSJVCgxTZXJ2ZXJTdGF0dXMSKAoFc3RhdHMYASABKAsyGS5n",
- "cnBjLnRlc3RpbmcuU2VydmVyU3RhdHMSDAoEcG9ydBgCIAEoBRINCgVjb3Jl",
- "cxgDIAEoBSovCgpDbGllbnRUeXBlEg8KC1NZTkNfQ0xJRU5UEAASEAoMQVNZ",
- "TkNfQ0xJRU5UEAEqLwoKU2VydmVyVHlwZRIPCgtTWU5DX1NFUlZFUhAAEhAK",
- "DEFTWU5DX1NFUlZFUhABKiMKB1JwY1R5cGUSCQoFVU5BUlkQABINCglTVFJF",
- "QU1JTkcQAWIGcHJvdG8z"));
+ "bVBhcmFtcxIRCgljb3JlX2xpc3QYDSADKAUSEgoKY29yZV9saW1pdBgOIAEo",
+ "BSI4CgxDbGllbnRTdGF0dXMSKAoFc3RhdHMYASABKAsyGS5ncnBjLnRlc3Rp",
+ "bmcuQ2xpZW50U3RhdHMiFQoETWFyaxINCgVyZXNldBgBIAEoCCJoCgpDbGll",
+ "bnRBcmdzEisKBXNldHVwGAEgASgLMhouZ3JwYy50ZXN0aW5nLkNsaWVudENv",
+ "bmZpZ0gAEiIKBG1hcmsYAiABKAsyEi5ncnBjLnRlc3RpbmcuTWFya0gAQgkK",
+ "B2FyZ3R5cGUi/AEKDFNlcnZlckNvbmZpZxItCgtzZXJ2ZXJfdHlwZRgBIAEo",
+ "DjIYLmdycGMudGVzdGluZy5TZXJ2ZXJUeXBlEjUKD3NlY3VyaXR5X3BhcmFt",
+ "cxgCIAEoCzIcLmdycGMudGVzdGluZy5TZWN1cml0eVBhcmFtcxIMCgRwb3J0",
+ "GAQgASgFEhwKFGFzeW5jX3NlcnZlcl90aHJlYWRzGAcgASgFEhIKCmNvcmVf",
+ "bGltaXQYCCABKAUSMwoOcGF5bG9hZF9jb25maWcYCSABKAsyGy5ncnBjLnRl",
+ "c3RpbmcuUGF5bG9hZENvbmZpZxIRCgljb3JlX2xpc3QYCiADKAUiaAoKU2Vy",
+ "dmVyQXJncxIrCgVzZXR1cBgBIAEoCzIaLmdycGMudGVzdGluZy5TZXJ2ZXJD",
+ "b25maWdIABIiCgRtYXJrGAIgASgLMhIuZ3JwYy50ZXN0aW5nLk1hcmtIAEIJ",
+ "Cgdhcmd0eXBlIlUKDFNlcnZlclN0YXR1cxIoCgVzdGF0cxgBIAEoCzIZLmdy",
+ "cGMudGVzdGluZy5TZXJ2ZXJTdGF0cxIMCgRwb3J0GAIgASgFEg0KBWNvcmVz",
+ "GAMgASgFIg0KC0NvcmVSZXF1ZXN0Ih0KDENvcmVSZXNwb25zZRINCgVjb3Jl",
+ "cxgBIAEoBSIGCgRWb2lkKi8KCkNsaWVudFR5cGUSDwoLU1lOQ19DTElFTlQQ",
+ "ABIQCgxBU1lOQ19DTElFTlQQASpJCgpTZXJ2ZXJUeXBlEg8KC1NZTkNfU0VS",
+ "VkVSEAASEAoMQVNZTkNfU0VSVkVSEAESGAoUQVNZTkNfR0VORVJJQ19TRVJW",
+ "RVIQAiojCgdScGNUeXBlEgkKBVVOQVJZEAASDQoJU1RSRUFNSU5HEAFiBnBy",
+ "b3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Grpc.Testing.PayloadsReflection.Descriptor, global::Grpc.Testing.StatsReflection.Descriptor, },
new pbr::GeneratedCodeInfo(new[] {typeof(global::Grpc.Testing.ClientType), typeof(global::Grpc.Testing.ServerType), typeof(global::Grpc.Testing.RpcType), }, new pbr::GeneratedCodeInfo[] {
@@ -76,13 +79,16 @@ namespace Grpc.Testing {
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClosedLoopParams), global::Grpc.Testing.ClosedLoopParams.Parser, null, null, null, null),
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.LoadParams), global::Grpc.Testing.LoadParams.Parser, new[]{ "ClosedLoop", "Poisson", "Uniform", "Determ", "Pareto" }, new[]{ "Load" }, null, null),
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.SecurityParams), global::Grpc.Testing.SecurityParams.Parser, new[]{ "UseTestCa", "ServerHostOverride" }, null, null, null),
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientConfig), global::Grpc.Testing.ClientConfig.Parser, new[]{ "ServerTargets", "ClientType", "SecurityParams", "OutstandingRpcsPerChannel", "ClientChannels", "AsyncClientThreads", "RpcType", "LoadParams", "PayloadConfig", "HistogramParams" }, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientConfig), global::Grpc.Testing.ClientConfig.Parser, new[]{ "ServerTargets", "ClientType", "SecurityParams", "OutstandingRpcsPerChannel", "ClientChannels", "AsyncClientThreads", "RpcType", "LoadParams", "PayloadConfig", "HistogramParams", "CoreList", "CoreLimit" }, null, null, null),
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientStatus), global::Grpc.Testing.ClientStatus.Parser, new[]{ "Stats" }, null, null, null),
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.Mark), global::Grpc.Testing.Mark.Parser, new[]{ "Reset" }, null, null, null),
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ClientArgs), global::Grpc.Testing.ClientArgs.Parser, new[]{ "Setup", "Mark" }, new[]{ "Argtype" }, null, null),
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerConfig), global::Grpc.Testing.ServerConfig.Parser, new[]{ "ServerType", "SecurityParams", "Host", "Port", "AsyncServerThreads", "CoreLimit", "PayloadConfig" }, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerConfig), global::Grpc.Testing.ServerConfig.Parser, new[]{ "ServerType", "SecurityParams", "Port", "AsyncServerThreads", "CoreLimit", "PayloadConfig", "CoreList" }, null, null, null),
new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerArgs), global::Grpc.Testing.ServerArgs.Parser, new[]{ "Setup", "Mark" }, new[]{ "Argtype" }, null, null),
- new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerStatus), global::Grpc.Testing.ServerStatus.Parser, new[]{ "Stats", "Port", "Cores" }, null, null, null)
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.ServerStatus), global::Grpc.Testing.ServerStatus.Parser, new[]{ "Stats", "Port", "Cores" }, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.CoreRequest), global::Grpc.Testing.CoreRequest.Parser, null, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.CoreResponse), global::Grpc.Testing.CoreResponse.Parser, new[]{ "Cores" }, null, null, null),
+ new pbr::GeneratedCodeInfo(typeof(global::Grpc.Testing.Void), global::Grpc.Testing.Void.Parser, null, null, null, null)
}));
}
#endregion
@@ -97,6 +103,7 @@ namespace Grpc.Testing {
public enum ServerType {
SYNC_SERVER = 0,
ASYNC_SERVER = 1,
+ ASYNC_GENERIC_SERVER = 2,
}
public enum RpcType {
@@ -1097,6 +1104,8 @@ namespace Grpc.Testing {
LoadParams = other.loadParams_ != null ? other.LoadParams.Clone() : null;
PayloadConfig = other.payloadConfig_ != null ? other.PayloadConfig.Clone() : null;
HistogramParams = other.histogramParams_ != null ? other.HistogramParams.Clone() : null;
+ coreList_ = other.coreList_.Clone();
+ coreLimit_ = other.coreLimit_;
}
public ClientConfig Clone() {
@@ -1219,6 +1228,28 @@ namespace Grpc.Testing {
}
}
+ /// <summary>Field number for the "core_list" field.</summary>
+ public const int CoreListFieldNumber = 13;
+ private static readonly pb::FieldCodec<int> _repeated_coreList_codec
+ = pb::FieldCodec.ForInt32(106);
+ private readonly pbc::RepeatedField<int> coreList_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Specify the cores we should run the client on, if desired
+ /// </summary>
+ public pbc::RepeatedField<int> CoreList {
+ get { return coreList_; }
+ }
+
+ /// <summary>Field number for the "core_limit" field.</summary>
+ public const int CoreLimitFieldNumber = 14;
+ private int coreLimit_;
+ public int CoreLimit {
+ get { return coreLimit_; }
+ set {
+ coreLimit_ = value;
+ }
+ }
+
public override bool Equals(object other) {
return Equals(other as ClientConfig);
}
@@ -1240,6 +1271,8 @@ namespace Grpc.Testing {
if (!object.Equals(LoadParams, other.LoadParams)) return false;
if (!object.Equals(PayloadConfig, other.PayloadConfig)) return false;
if (!object.Equals(HistogramParams, other.HistogramParams)) return false;
+ if(!coreList_.Equals(other.coreList_)) return false;
+ if (CoreLimit != other.CoreLimit) return false;
return true;
}
@@ -1255,6 +1288,8 @@ namespace Grpc.Testing {
if (loadParams_ != null) hash ^= LoadParams.GetHashCode();
if (payloadConfig_ != null) hash ^= PayloadConfig.GetHashCode();
if (histogramParams_ != null) hash ^= HistogramParams.GetHashCode();
+ hash ^= coreList_.GetHashCode();
+ if (CoreLimit != 0) hash ^= CoreLimit.GetHashCode();
return hash;
}
@@ -1300,6 +1335,11 @@ namespace Grpc.Testing {
output.WriteRawTag(98);
output.WriteMessage(HistogramParams);
}
+ coreList_.WriteTo(output, _repeated_coreList_codec);
+ if (CoreLimit != 0) {
+ output.WriteRawTag(112);
+ output.WriteInt32(CoreLimit);
+ }
}
public int CalculateSize() {
@@ -1332,6 +1372,10 @@ namespace Grpc.Testing {
if (histogramParams_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(HistogramParams);
}
+ size += coreList_.CalculateSize(_repeated_coreList_codec);
+ if (CoreLimit != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(CoreLimit);
+ }
return size;
}
@@ -1379,6 +1423,10 @@ namespace Grpc.Testing {
}
HistogramParams.MergeFrom(other.HistogramParams);
}
+ coreList_.Add(other.coreList_);
+ if (other.CoreLimit != 0) {
+ CoreLimit = other.CoreLimit;
+ }
}
public void MergeFrom(pb::CodedInputStream input) {
@@ -1440,6 +1488,15 @@ namespace Grpc.Testing {
input.ReadMessage(histogramParams_);
break;
}
+ case 106:
+ case 104: {
+ coreList_.AddEntriesFrom(input, _repeated_coreList_codec);
+ break;
+ }
+ case 112: {
+ CoreLimit = input.ReadInt32();
+ break;
+ }
}
}
}
@@ -1855,11 +1912,11 @@ namespace Grpc.Testing {
public ServerConfig(ServerConfig other) : this() {
serverType_ = other.serverType_;
SecurityParams = other.securityParams_ != null ? other.SecurityParams.Clone() : null;
- host_ = other.host_;
port_ = other.port_;
asyncServerThreads_ = other.asyncServerThreads_;
coreLimit_ = other.coreLimit_;
PayloadConfig = other.payloadConfig_ != null ? other.PayloadConfig.Clone() : null;
+ coreList_ = other.coreList_.Clone();
}
public ServerConfig Clone() {
@@ -1886,19 +1943,6 @@ namespace Grpc.Testing {
}
}
- /// <summary>Field number for the "host" field.</summary>
- public const int HostFieldNumber = 3;
- private string host_ = "";
- /// <summary>
- /// Host on which to listen.
- /// </summary>
- public string Host {
- get { return host_; }
- set {
- host_ = pb::Preconditions.CheckNotNull(value, "value");
- }
- }
-
/// <summary>Field number for the "port" field.</summary>
public const int PortFieldNumber = 4;
private int port_;
@@ -1929,7 +1973,7 @@ namespace Grpc.Testing {
public const int CoreLimitFieldNumber = 8;
private int coreLimit_;
/// <summary>
- /// restrict core usage, currently unused
+ /// Specify the number of cores to limit server to, if desired
/// </summary>
public int CoreLimit {
get { return coreLimit_; }
@@ -1941,6 +1985,9 @@ namespace Grpc.Testing {
/// <summary>Field number for the "payload_config" field.</summary>
public const int PayloadConfigFieldNumber = 9;
private global::Grpc.Testing.PayloadConfig payloadConfig_;
+ /// <summary>
+ /// payload config, used in generic server
+ /// </summary>
public global::Grpc.Testing.PayloadConfig PayloadConfig {
get { return payloadConfig_; }
set {
@@ -1948,6 +1995,18 @@ namespace Grpc.Testing {
}
}
+ /// <summary>Field number for the "core_list" field.</summary>
+ public const int CoreListFieldNumber = 10;
+ private static readonly pb::FieldCodec<int> _repeated_coreList_codec
+ = pb::FieldCodec.ForInt32(82);
+ private readonly pbc::RepeatedField<int> coreList_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Specify the cores we should run the server on, if desired
+ /// </summary>
+ public pbc::RepeatedField<int> CoreList {
+ get { return coreList_; }
+ }
+
public override bool Equals(object other) {
return Equals(other as ServerConfig);
}
@@ -1961,11 +2020,11 @@ namespace Grpc.Testing {
}
if (ServerType != other.ServerType) return false;
if (!object.Equals(SecurityParams, other.SecurityParams)) return false;
- if (Host != other.Host) return false;
if (Port != other.Port) return false;
if (AsyncServerThreads != other.AsyncServerThreads) return false;
if (CoreLimit != other.CoreLimit) return false;
if (!object.Equals(PayloadConfig, other.PayloadConfig)) return false;
+ if(!coreList_.Equals(other.coreList_)) return false;
return true;
}
@@ -1973,11 +2032,11 @@ namespace Grpc.Testing {
int hash = 1;
if (ServerType != global::Grpc.Testing.ServerType.SYNC_SERVER) hash ^= ServerType.GetHashCode();
if (securityParams_ != null) hash ^= SecurityParams.GetHashCode();
- if (Host.Length != 0) hash ^= Host.GetHashCode();
if (Port != 0) hash ^= Port.GetHashCode();
if (AsyncServerThreads != 0) hash ^= AsyncServerThreads.GetHashCode();
if (CoreLimit != 0) hash ^= CoreLimit.GetHashCode();
if (payloadConfig_ != null) hash ^= PayloadConfig.GetHashCode();
+ hash ^= coreList_.GetHashCode();
return hash;
}
@@ -1994,10 +2053,6 @@ namespace Grpc.Testing {
output.WriteRawTag(18);
output.WriteMessage(SecurityParams);
}
- if (Host.Length != 0) {
- output.WriteRawTag(26);
- output.WriteString(Host);
- }
if (Port != 0) {
output.WriteRawTag(32);
output.WriteInt32(Port);
@@ -2014,6 +2069,7 @@ namespace Grpc.Testing {
output.WriteRawTag(74);
output.WriteMessage(PayloadConfig);
}
+ coreList_.WriteTo(output, _repeated_coreList_codec);
}
public int CalculateSize() {
@@ -2024,9 +2080,6 @@ namespace Grpc.Testing {
if (securityParams_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(SecurityParams);
}
- if (Host.Length != 0) {
- size += 1 + pb::CodedOutputStream.ComputeStringSize(Host);
- }
if (Port != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Port);
}
@@ -2039,6 +2092,7 @@ namespace Grpc.Testing {
if (payloadConfig_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(PayloadConfig);
}
+ size += coreList_.CalculateSize(_repeated_coreList_codec);
return size;
}
@@ -2055,9 +2109,6 @@ namespace Grpc.Testing {
}
SecurityParams.MergeFrom(other.SecurityParams);
}
- if (other.Host.Length != 0) {
- Host = other.Host;
- }
if (other.Port != 0) {
Port = other.Port;
}
@@ -2073,6 +2124,7 @@ namespace Grpc.Testing {
}
PayloadConfig.MergeFrom(other.PayloadConfig);
}
+ coreList_.Add(other.coreList_);
}
public void MergeFrom(pb::CodedInputStream input) {
@@ -2093,10 +2145,6 @@ namespace Grpc.Testing {
input.ReadMessage(securityParams_);
break;
}
- case 26: {
- Host = input.ReadString();
- break;
- }
case 32: {
Port = input.ReadInt32();
break;
@@ -2116,6 +2164,11 @@ namespace Grpc.Testing {
input.ReadMessage(payloadConfig_);
break;
}
+ case 82:
+ case 80: {
+ coreList_.AddEntriesFrom(input, _repeated_coreList_codec);
+ break;
+ }
}
}
}
@@ -2347,7 +2400,7 @@ namespace Grpc.Testing {
public const int CoresFieldNumber = 3;
private int cores_;
/// <summary>
- /// Number of cores on the server. See gpr_cpu_num_cores.
+ /// Number of cores available to the server
/// </summary>
public int Cores {
get { return cores_; }
@@ -2460,6 +2513,264 @@ namespace Grpc.Testing {
}
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class CoreRequest : pb::IMessage<CoreRequest> {
+ private static readonly pb::MessageParser<CoreRequest> _parser = new pb::MessageParser<CoreRequest>(() => new CoreRequest());
+ public static pb::MessageParser<CoreRequest> Parser { get { return _parser; } }
+
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Grpc.Testing.ControlReflection.Descriptor.MessageTypes[14]; }
+ }
+
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ public CoreRequest() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ public CoreRequest(CoreRequest other) : this() {
+ }
+
+ public CoreRequest Clone() {
+ return new CoreRequest(this);
+ }
+
+ public override bool Equals(object other) {
+ return Equals(other as CoreRequest);
+ }
+
+ public bool Equals(CoreRequest other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ public void MergeFrom(CoreRequest other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class CoreResponse : pb::IMessage<CoreResponse> {
+ private static readonly pb::MessageParser<CoreResponse> _parser = new pb::MessageParser<CoreResponse>(() => new CoreResponse());
+ public static pb::MessageParser<CoreResponse> Parser { get { return _parser; } }
+
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Grpc.Testing.ControlReflection.Descriptor.MessageTypes[15]; }
+ }
+
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ public CoreResponse() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ public CoreResponse(CoreResponse other) : this() {
+ cores_ = other.cores_;
+ }
+
+ public CoreResponse Clone() {
+ return new CoreResponse(this);
+ }
+
+ /// <summary>Field number for the "cores" field.</summary>
+ public const int CoresFieldNumber = 1;
+ private int cores_;
+ /// <summary>
+ /// Number of cores available on the server
+ /// </summary>
+ public int Cores {
+ get { return cores_; }
+ set {
+ cores_ = value;
+ }
+ }
+
+ public override bool Equals(object other) {
+ return Equals(other as CoreResponse);
+ }
+
+ public bool Equals(CoreResponse other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Cores != other.Cores) return false;
+ return true;
+ }
+
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Cores != 0) hash ^= Cores.GetHashCode();
+ return hash;
+ }
+
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Cores != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Cores);
+ }
+ }
+
+ public int CalculateSize() {
+ int size = 0;
+ if (Cores != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Cores);
+ }
+ return size;
+ }
+
+ public void MergeFrom(CoreResponse other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Cores != 0) {
+ Cores = other.Cores;
+ }
+ }
+
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Cores = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Void : pb::IMessage<Void> {
+ private static readonly pb::MessageParser<Void> _parser = new pb::MessageParser<Void>(() => new Void());
+ public static pb::MessageParser<Void> Parser { get { return _parser; } }
+
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Grpc.Testing.ControlReflection.Descriptor.MessageTypes[16]; }
+ }
+
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ public Void() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ public Void(Void other) : this() {
+ }
+
+ public Void Clone() {
+ return new Void(this);
+ }
+
+ public override bool Equals(object other) {
+ return Equals(other as Void);
+ }
+
+ public bool Equals(Void other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ public void MergeFrom(Void other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
#endregion
}
diff --git a/src/csharp/Grpc.IntegrationTesting/GeneratedClientTest.cs b/src/csharp/Grpc.IntegrationTesting/GeneratedClientTest.cs
new file mode 100644
index 0000000000..37786b6c30
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/GeneratedClientTest.cs
@@ -0,0 +1,106 @@
+#region Copyright notice and license
+
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Grpc.Core;
+using Grpc.Core.Utils;
+using Grpc.Testing;
+using Moq;
+using NUnit.Framework;
+
+namespace Grpc.IntegrationTesting
+{
+ public class GeneratedClientTest
+ {
+ TestService.TestServiceClient unimplementedClient = new UnimplementedTestServiceClient();
+
+ [Test]
+ public void ExpandedParamOverloadCanBeMocked()
+ {
+ var expected = new SimpleResponse();
+
+ var mockClient = new Mock<TestService.TestServiceClient>();
+ // mocking is relatively clumsy because one needs to specify value for all the optional params.
+ mockClient.Setup(m => m.UnaryCall(It.IsAny<SimpleRequest>(), null, null, CancellationToken.None)).Returns(expected);
+
+ Assert.AreSame(expected, mockClient.Object.UnaryCall(new SimpleRequest()));
+ }
+
+ [Test]
+ public void CallOptionsOverloadCanBeMocked()
+ {
+ var expected = new SimpleResponse();
+
+ var mockClient = new Mock<TestService.TestServiceClient>();
+ mockClient.Setup(m => m.UnaryCall(It.IsAny<SimpleRequest>(), It.IsAny<CallOptions>())).Returns(expected);
+
+ Assert.AreSame(expected, mockClient.Object.UnaryCall(new SimpleRequest(), new CallOptions()));
+ }
+
+ [Test]
+ public void DefaultMethodStubThrows_UnaryCall()
+ {
+ Assert.Throws(typeof(NotImplementedException), () => unimplementedClient.UnaryCall(new SimpleRequest()));
+ }
+
+ [Test]
+ public void DefaultMethodStubThrows_ClientStreaming()
+ {
+ Assert.Throws(typeof(NotImplementedException), () => unimplementedClient.StreamingInputCall());
+ }
+
+ [Test]
+ public void DefaultMethodStubThrows_ServerStreaming()
+ {
+ Assert.Throws(typeof(NotImplementedException), () => unimplementedClient.StreamingOutputCall(new StreamingOutputCallRequest()));
+ }
+
+ [Test]
+ public void DefaultMethodStubThrows_DuplexStreaming()
+ {
+ Assert.Throws(typeof(NotImplementedException), () => unimplementedClient.FullDuplexCall());
+ }
+
+ /// <summary>
+ /// Subclass of the generated client that doesn't override any method stubs.
+ /// </summary>
+ private class UnimplementedTestServiceClient : TestService.TestServiceClient
+ {
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs b/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs
new file mode 100644
index 0000000000..99aa729030
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs
@@ -0,0 +1,116 @@
+#region Copyright notice and license
+
+// Copyright 2015-2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Grpc.Core;
+using Grpc.Core.Utils;
+using Grpc.Testing;
+using Moq;
+using NUnit.Framework;
+
+namespace Grpc.IntegrationTesting
+{
+ public class GeneratedServiceBaseTest
+ {
+ const string Host = "localhost";
+ Server server;
+ Channel channel;
+ TestService.TestServiceClient client;
+
+ [SetUp]
+ public void Init()
+ {
+ server = new Server
+ {
+ Services = { TestService.BindService(new UnimplementedTestServiceImpl()) },
+ Ports = { { Host, ServerPort.PickUnused, SslServerCredentials.Insecure } }
+ };
+ server.Start();
+ channel = new Channel(Host, server.Ports.Single().BoundPort, ChannelCredentials.Insecure);
+ client = TestService.NewClient(channel);
+ }
+
+ [TearDown]
+ public void Cleanup()
+ {
+ channel.ShutdownAsync().Wait();
+ server.ShutdownAsync().Wait();
+ }
+
+ [Test]
+ public void UnimplementedByDefault_Unary()
+ {
+ var ex = Assert.Throws<RpcException>(() => client.UnaryCall(new SimpleRequest { }));
+ Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
+ }
+
+ [Test]
+ public async Task UnimplementedByDefault_ClientStreaming()
+ {
+ var call = client.StreamingInputCall();
+
+ var ex = Assert.Throws<RpcException>(async () => await call);
+ Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
+ }
+
+ [Test]
+ public async Task UnimplementedByDefault_ServerStreamingCall()
+ {
+ var call = client.StreamingOutputCall(new StreamingOutputCallRequest());
+
+ var ex = Assert.Throws<RpcException>(async () => await call.ResponseStream.MoveNext());
+ Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
+ }
+
+ [Test]
+ public async Task UnimplementedByDefault_DuplexStreamingCall()
+ {
+ var call = client.FullDuplexCall();
+
+ var ex = Assert.Throws<RpcException>(async () => await call.ResponseStream.MoveNext());
+ Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
+ }
+
+ /// <summary>
+ /// Implementation of TestService that doesn't override any methods.
+ /// </summary>
+ private class UnimplementedTestServiceImpl : TestService.TestServiceBase
+ {
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/GenericService.cs b/src/csharp/Grpc.IntegrationTesting/GenericService.cs
new file mode 100644
index 0000000000..c6128264ac
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/GenericService.cs
@@ -0,0 +1,71 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Google.Protobuf;
+using Grpc.Core;
+using Grpc.Core.Utils;
+using NUnit.Framework;
+using Grpc.Testing;
+
+namespace Grpc.IntegrationTesting
+{
+ /// <summary>
+ /// Utility methods for defining and calling a service that doesn't use protobufs
+ /// for serialization/deserialization.
+ /// </summary>
+ public static class GenericService
+ {
+ readonly static Marshaller<byte[]> ByteArrayMarshaller = new Marshaller<byte[]>((b) => b, (b) => b);
+
+ public readonly static Method<byte[], byte[]> StreamingCallMethod = new Method<byte[], byte[]>(
+ MethodType.DuplexStreaming,
+ "grpc.testing.BenchmarkService",
+ "StreamingCall",
+ ByteArrayMarshaller,
+ ByteArrayMarshaller
+ );
+
+ public static ServerServiceDefinition BindHandler(DuplexStreamingServerMethod<byte[], byte[]> handler)
+ {
+ return ServerServiceDefinition.CreateBuilder(StreamingCallMethod.ServiceName)
+ .AddMethod(StreamingCallMethod, handler).Build();
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
index 372991374e..7ea80b11f0 100644
--- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
+++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
@@ -8,7 +8,7 @@
<RootNamespace>Grpc.IntegrationTesting</RootNamespace>
<AssemblyName>Grpc.IntegrationTesting</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <NuGetPackageImportStamp>6566287f</NuGetPackageImportStamp>
+ <NuGetPackageImportStamp>3a1c655d</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -38,20 +38,24 @@
<AssemblyOriginatorKeyFile>..\keys\Grpc.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="BouncyCastle.Crypto, Version=1.7.4137.9688, Culture=neutral, PublicKeyToken=a4292a325f69b123, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
+ </Reference>
<Reference Include="CommandLine">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Auth, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.10.0.25333, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Auth.PlatformServices, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Auth.1.10.0\lib\net40\Google.Apis.Auth.PlatformServices.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.PlatformServices.dll</HintPath>
</Reference>
- <Reference Include="Google.Apis.Core, Version=1.10.0.25331, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
+ <Reference Include="Google.Apis.Core, Version=1.11.1.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Google.Apis.Core.1.10.0\lib\portable-net40+sl50+win+wpa81+wp80\Google.Apis.Core.dll</HintPath>
+ <HintPath>..\packages\Google.Apis.Core.1.11.1\lib\net45\Google.Apis.Core.dll</HintPath>
</Reference>
<Reference Include="Google.Protobuf, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -60,6 +64,10 @@
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
</Reference>
+ <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
@@ -71,27 +79,11 @@
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
- <Reference Include="BouncyCastle.Crypto">
- <HintPath>..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
- <HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
- </Reference>
- <Reference Include="Newtonsoft.Json">
- <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
- </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Grpc.Core\Version.cs">
<Link>Version.cs</Link>
</Compile>
- <Compile Include="HeaderInterceptorTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Empty.cs" />
<Compile Include="Messages.cs" />
@@ -120,6 +112,10 @@
<Compile Include="WorkerServiceImpl.cs" />
<Compile Include="QpsWorker.cs" />
<Compile Include="WallClockStopwatch.cs" />
+ <Compile Include="GenericService.cs" />
+ <Compile Include="GeneratedServiceBaseTest.cs" />
+ <Compile Include="GeneratedClientTest.cs" />
+ <Compile Include="InterarrivalTimers.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -133,8 +129,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
- <None Include="packages.config" />
+ <None Include="packages.config">
+ <SubType>Designer</SubType>
+ </None>
<None Include="data\README">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -151,11 +148,4 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
- <Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
- <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
- <PropertyGroup>
- <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
- </PropertyGroup>
- <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
- </Target>
</Project> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting/Histogram.cs b/src/csharp/Grpc.IntegrationTesting/Histogram.cs
index 7e7cb2c4de..28d1f078a9 100644
--- a/src/csharp/Grpc.IntegrationTesting/Histogram.cs
+++ b/src/csharp/Grpc.IntegrationTesting/Histogram.cs
@@ -66,8 +66,8 @@ namespace Grpc.IntegrationTesting
public Histogram(double resolution, double maxPossible)
{
- Grpc.Core.Utils.Preconditions.CheckArgument(resolution > 0);
- Grpc.Core.Utils.Preconditions.CheckArgument(maxPossible > 0);
+ GrpcPreconditions.CheckArgument(resolution > 0);
+ GrpcPreconditions.CheckArgument(maxPossible > 0);
this.maxPossible = maxPossible;
this.multiplier = 1.0 + resolution;
this.oneOnLogMultiplier = 1.0 / Math.Log(1.0 + resolution);
diff --git a/src/csharp/Grpc.IntegrationTesting/InterarrivalTimers.cs b/src/csharp/Grpc.IntegrationTesting/InterarrivalTimers.cs
new file mode 100644
index 0000000000..6492d34890
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/InterarrivalTimers.cs
@@ -0,0 +1,148 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
+using Google.Protobuf;
+using Grpc.Core;
+using Grpc.Core.Utils;
+using Grpc.Testing;
+
+namespace Grpc.IntegrationTesting
+{
+ public interface IInterarrivalTimer
+ {
+ void WaitForNext();
+
+ Task WaitForNextAsync();
+ }
+
+ /// <summary>
+ /// Interarrival timer that doesn't wait at all.
+ /// </summary>
+ public class ClosedLoopInterarrivalTimer : IInterarrivalTimer
+ {
+ public ClosedLoopInterarrivalTimer()
+ {
+ }
+
+ public void WaitForNext()
+ {
+ // NOP
+ }
+
+ public Task WaitForNextAsync()
+ {
+ return Task.FromResult<object>(null);
+ }
+ }
+
+ /// <summary>
+ /// Interarrival timer that generates Poisson process load.
+ /// </summary>
+ public class PoissonInterarrivalTimer : IInterarrivalTimer
+ {
+ readonly ExponentialDistribution exponentialDistribution;
+ DateTime? lastEventTime;
+
+ public PoissonInterarrivalTimer(double offeredLoad)
+ {
+ this.exponentialDistribution = new ExponentialDistribution(new Random(), offeredLoad);
+ this.lastEventTime = DateTime.UtcNow;
+ }
+
+ public void WaitForNext()
+ {
+ var waitDuration = GetNextWaitDuration();
+ int millisTimeout = (int) Math.Round(waitDuration.TotalMilliseconds);
+ if (millisTimeout > 0)
+ {
+ // TODO(jtattermusch): probably only works well for a relatively low interarrival rate
+ Thread.Sleep(millisTimeout);
+ }
+ }
+
+ public async Task WaitForNextAsync()
+ {
+ var waitDuration = GetNextWaitDuration();
+ int millisTimeout = (int) Math.Round(waitDuration.TotalMilliseconds);
+ if (millisTimeout > 0)
+ {
+ // TODO(jtattermusch): probably only works well for a relatively low interarrival rate
+ await Task.Delay(millisTimeout);
+ }
+ }
+
+ private TimeSpan GetNextWaitDuration()
+ {
+ if (!lastEventTime.HasValue)
+ {
+ this.lastEventTime = DateTime.Now;
+ }
+
+ var origLastEventTime = this.lastEventTime.Value;
+ this.lastEventTime = origLastEventTime + TimeSpan.FromSeconds(exponentialDistribution.Next());
+ return this.lastEventTime.Value - origLastEventTime;
+ }
+
+ /// <summary>
+ /// Exp generator.
+ /// </summary>
+ private class ExponentialDistribution
+ {
+ readonly Random random;
+ readonly double lambda;
+ readonly double lambdaReciprocal;
+
+ public ExponentialDistribution(Random random, double lambda)
+ {
+ this.random = random;
+ this.lambda = lambda;
+ this.lambdaReciprocal = 1.0 / lambda;
+ }
+
+ public double Next()
+ {
+ double uniform = random.NextDouble();
+ // Use 1.0-uni above to avoid NaN if uni is 0
+ return lambdaReciprocal * (-Math.Log(1.0 - uniform));
+ }
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index b0e33e49f7..7ca5221936 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -217,7 +217,7 @@ namespace Grpc.IntegrationTesting
}
}
- public static void RunEmptyUnary(TestService.ITestServiceClient client)
+ public static void RunEmptyUnary(TestService.TestServiceClient client)
{
Console.WriteLine("running empty_unary");
var response = client.EmptyCall(new Empty());
@@ -225,7 +225,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static void RunLargeUnary(TestService.ITestServiceClient client)
+ public static void RunLargeUnary(TestService.TestServiceClient client)
{
Console.WriteLine("running large_unary");
var request = new SimpleRequest
@@ -241,7 +241,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunClientStreamingAsync(TestService.ITestServiceClient client)
+ public static async Task RunClientStreamingAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running client_streaming");
@@ -257,7 +257,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunServerStreamingAsync(TestService.ITestServiceClient client)
+ public static async Task RunServerStreamingAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running server_streaming");
@@ -281,7 +281,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunPingPongAsync(TestService.ITestServiceClient client)
+ public static async Task RunPingPongAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running ping_pong");
@@ -338,7 +338,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunEmptyStreamAsync(TestService.ITestServiceClient client)
+ public static async Task RunEmptyStreamAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running empty_stream");
using (var call = client.FullDuplexCall())
@@ -434,7 +434,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunCancelAfterBeginAsync(TestService.ITestServiceClient client)
+ public static async Task RunCancelAfterBeginAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running cancel_after_begin");
@@ -451,7 +451,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunCancelAfterFirstResponseAsync(TestService.ITestServiceClient client)
+ public static async Task RunCancelAfterFirstResponseAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running cancel_after_first_response");
@@ -477,7 +477,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunTimeoutOnSleepingServerAsync(TestService.ITestServiceClient client)
+ public static async Task RunTimeoutOnSleepingServerAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running timeout_on_sleeping_server");
@@ -499,7 +499,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunCustomMetadataAsync(TestService.ITestServiceClient client)
+ public static async Task RunCustomMetadataAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running custom_metadata");
{
@@ -546,7 +546,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static async Task RunStatusCodeAndMessageAsync(TestService.ITestServiceClient client)
+ public static async Task RunStatusCodeAndMessageAsync(TestService.TestServiceClient client)
{
Console.WriteLine("running status_code_and_message");
var echoStatus = new EchoStatus
@@ -580,7 +580,7 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
- public static void RunUnimplementedMethod(UnimplementedService.IUnimplementedServiceClient client)
+ public static void RunUnimplementedMethod(UnimplementedService.UnimplementedServiceClient client)
{
Console.WriteLine("running unimplemented_method");
var e = Assert.Throws<RpcException>(() => client.UnimplementedCall(new Empty()));
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs b/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
index 18168f9970..4ee1ff5ec8 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
@@ -51,7 +51,7 @@ namespace Grpc.IntegrationTesting
const string Host = "localhost";
Server server;
Channel channel;
- TestService.ITestServiceClient client;
+ TestService.TestServiceClient client;
[TestFixtureSetUp]
public void Init()
@@ -140,14 +140,12 @@ namespace Grpc.IntegrationTesting
}
[Test]
- [Ignore("TODO: see #4427")]
public async Task StatusCodeAndMessage()
{
await InteropClient.RunStatusCodeAndMessageAsync(client);
}
[Test]
- [Ignore("TODO: see #4427")]
public void UnimplementedMethod()
{
InteropClient.RunUnimplementedMethod(UnimplementedService.NewClient(channel));
diff --git a/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs b/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
index 1c8bfed1f6..f95af5008f 100644
--- a/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -50,15 +50,15 @@ namespace Grpc.IntegrationTesting
const string Host = "localhost";
Server server;
Channel channel;
- TestService.ITestServiceClient client;
+ TestService.TestServiceClient client;
List<ChannelOption> options;
- Mock<TestService.ITestService> serviceMock;
+ Mock<TestService.TestServiceBase> serviceMock;
AsyncAuthInterceptor asyncAuthInterceptor;
[SetUp]
public void Init()
{
- serviceMock = new Mock<TestService.ITestService>();
+ serviceMock = new Mock<TestService.TestServiceBase>();
serviceMock.Setup(m => m.UnaryCall(It.IsAny<SimpleRequest>(), It.IsAny<ServerCallContext>()))
.Returns(new Func<SimpleRequest, ServerCallContext, Task<SimpleResponse>>(UnaryCallHandler));
diff --git a/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs b/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs
index 686b484345..a7c9fa894d 100644
--- a/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs
+++ b/src/csharp/Grpc.IntegrationTesting/QpsWorker.cs
@@ -85,24 +85,27 @@ namespace Grpc.IntegrationTesting
}
var workerServer = new QpsWorker(options);
- workerServer.Run();
+ workerServer.RunAsync().Wait();
}
- private void Run()
+ private async Task RunAsync()
{
string host = "0.0.0.0";
int port = options.DriverPort;
+ var tcs = new TaskCompletionSource<object>();
+ var workerServiceImpl = new WorkerServiceImpl(() => { Task.Run(() => tcs.SetResult(null)); });
+
var server = new Server
{
- Services = { WorkerService.BindService(new WorkerServiceImpl()) },
+ Services = { WorkerService.BindService(workerServiceImpl) },
Ports = { new ServerPort(host, options.DriverPort, ServerCredentials.Insecure )}
};
int boundPort = server.Ports.Single().BoundPort;
Console.WriteLine("Running qps worker server on " + string.Format("{0}:{1}", host, boundPort));
server.Start();
-
- server.ShutdownTask.Wait();
+ await tcs.Task;
+ await server.ShutdownAsync();
}
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs b/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs
index 3dd91b7948..13ab5a25ab 100644
--- a/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/RunnerClientServerTest.cs
@@ -48,7 +48,6 @@ namespace Grpc.IntegrationTesting
/// </summary>
public class RunnerClientServerTest
{
- const string Host = "localhost";
IServerRunner serverRunner;
[TestFixtureSetUp]
@@ -56,15 +55,7 @@ namespace Grpc.IntegrationTesting
{
var serverConfig = new ServerConfig
{
- ServerType = ServerType.ASYNC_SERVER,
- Host = Host,
- PayloadConfig = new PayloadConfig
- {
- SimpleParams = new SimpleProtoParams
- {
- RespSize = 100
- }
- }
+ ServerType = ServerType.ASYNC_SERVER
};
serverRunner = ServerRunners.CreateStarted(serverConfig);
}
@@ -83,14 +74,15 @@ namespace Grpc.IntegrationTesting
{
var config = new ClientConfig
{
- ServerTargets = { string.Format("{0}:{1}", Host, serverRunner.BoundPort) },
+ ServerTargets = { string.Format("{0}:{1}", "localhost", serverRunner.BoundPort) },
RpcType = RpcType.UNARY,
LoadParams = new LoadParams { ClosedLoop = new ClosedLoopParams() },
PayloadConfig = new PayloadConfig
{
SimpleParams = new SimpleProtoParams
{
- ReqSize = 100
+ ReqSize = 100,
+ RespSize = 100
}
},
HistogramParams = new HistogramParams
diff --git a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
index e8be7758ce..d7859443e0 100644
--- a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
@@ -41,6 +41,7 @@ using System.Threading;
using System.Threading.Tasks;
using Google.Protobuf;
using Grpc.Core;
+using Grpc.Core.Logging;
using Grpc.Core.Utils;
using NUnit.Framework;
using Grpc.Testing;
@@ -50,27 +51,78 @@ namespace Grpc.IntegrationTesting
/// <summary>
/// Helper methods to start server runners for performance testing.
/// </summary>
- public static class ServerRunners
+ public class ServerRunners
{
+ static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<ServerRunners>();
+
/// <summary>
/// Creates a started server runner.
/// </summary>
public static IServerRunner CreateStarted(ServerConfig config)
{
- Grpc.Core.Utils.Preconditions.CheckArgument(config.ServerType == ServerType.ASYNC_SERVER);
+ Logger.Debug("ServerConfig: {0}", config);
var credentials = config.SecurityParams != null ? TestCredentials.CreateSslServerCredentials() : ServerCredentials.Insecure;
- // TODO: qps_driver needs to setup payload properly...
- int responseSize = config.PayloadConfig != null ? config.PayloadConfig.SimpleParams.RespSize : 0;
+ if (config.AsyncServerThreads != 0)
+ {
+ Logger.Warning("ServerConfig.AsyncServerThreads is not supported for C#. Ignoring the value");
+ }
+ if (config.CoreLimit != 0)
+ {
+ Logger.Warning("ServerConfig.CoreLimit is not supported for C#. Ignoring the value");
+ }
+ if (config.CoreList.Count > 0)
+ {
+ Logger.Warning("ServerConfig.CoreList is not supported for C#. Ignoring the value");
+ }
+
+ ServerServiceDefinition service = null;
+ if (config.ServerType == ServerType.ASYNC_SERVER)
+ {
+ GrpcPreconditions.CheckArgument(config.PayloadConfig == null,
+ "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server.");
+ service = BenchmarkService.BindService(new BenchmarkServiceImpl());
+ }
+ else if (config.ServerType == ServerType.ASYNC_GENERIC_SERVER)
+ {
+ var genericService = new GenericServiceImpl(config.PayloadConfig.BytebufParams.RespSize);
+ service = GenericService.BindHandler(genericService.StreamingCall);
+ }
+ else
+ {
+ throw new ArgumentException("Unsupported ServerType");
+ }
+
var server = new Server
{
- Services = { BenchmarkService.BindService(new BenchmarkServiceImpl(responseSize)) },
- Ports = { new ServerPort(config.Host, config.Port, credentials) }
+ Services = { service },
+ Ports = { new ServerPort("[::]", config.Port, credentials) }
};
server.Start();
return new ServerRunnerImpl(server);
}
+
+ private class GenericServiceImpl
+ {
+ readonly byte[] response;
+
+ public GenericServiceImpl(int responseSize)
+ {
+ this.response = new byte[responseSize];
+ }
+
+ /// <summary>
+ /// Generic streaming call handler.
+ /// </summary>
+ public async Task StreamingCall(IAsyncStreamReader<byte[]> requestStream, IServerStreamWriter<byte[]> responseStream, ServerCallContext context)
+ {
+ await requestStream.ForEachAsync(async request =>
+ {
+ await responseStream.WriteAsync(response);
+ });
+ }
+ }
}
/// <summary>
@@ -83,7 +135,7 @@ namespace Grpc.IntegrationTesting
public ServerRunnerImpl(Server server)
{
- this.server = Grpc.Core.Utils.Preconditions.CheckNotNull(server);
+ this.server = GrpcPreconditions.CheckNotNull(server);
}
public int BoundPort
@@ -119,6 +171,5 @@ namespace Grpc.IntegrationTesting
{
return server.ShutdownAsync();
}
- }
-
+ }
}
diff --git a/src/csharp/Grpc.IntegrationTesting/Services.cs b/src/csharp/Grpc.IntegrationTesting/Services.cs
index 04a092ccd7..a8475c1817 100644
--- a/src/csharp/Grpc.IntegrationTesting/Services.cs
+++ b/src/csharp/Grpc.IntegrationTesting/Services.cs
@@ -29,11 +29,14 @@ namespace Grpc.Testing {
"QmVuY2htYXJrU2VydmljZRJGCglVbmFyeUNhbGwSGy5ncnBjLnRlc3Rpbmcu",
"U2ltcGxlUmVxdWVzdBocLmdycGMudGVzdGluZy5TaW1wbGVSZXNwb25zZRJO",
"Cg1TdHJlYW1pbmdDYWxsEhsuZ3JwYy50ZXN0aW5nLlNpbXBsZVJlcXVlc3Qa",
- "HC5ncnBjLnRlc3RpbmcuU2ltcGxlUmVzcG9uc2UoATABMp0BCg1Xb3JrZXJT",
+ "HC5ncnBjLnRlc3RpbmcuU2ltcGxlUmVzcG9uc2UoATABMpcCCg1Xb3JrZXJT",
"ZXJ2aWNlEkUKCVJ1blNlcnZlchIYLmdycGMudGVzdGluZy5TZXJ2ZXJBcmdz",
"GhouZ3JwYy50ZXN0aW5nLlNlcnZlclN0YXR1cygBMAESRQoJUnVuQ2xpZW50",
"EhguZ3JwYy50ZXN0aW5nLkNsaWVudEFyZ3MaGi5ncnBjLnRlc3RpbmcuQ2xp",
- "ZW50U3RhdHVzKAEwAWIGcHJvdG8z"));
+ "ZW50U3RhdHVzKAEwARJCCglDb3JlQ291bnQSGS5ncnBjLnRlc3RpbmcuQ29y",
+ "ZVJlcXVlc3QaGi5ncnBjLnRlc3RpbmcuQ29yZVJlc3BvbnNlEjQKClF1aXRX",
+ "b3JrZXISEi5ncnBjLnRlc3RpbmcuVm9pZBoSLmdycGMudGVzdGluZy5Wb2lk",
+ "YgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Grpc.Testing.MessagesReflection.Descriptor, global::Grpc.Testing.ControlReflection.Descriptor, },
new pbr::GeneratedCodeInfo(null, null));
diff --git a/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs b/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs
index dd30afb427..46b16cf202 100644
--- a/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ServicesGrpc.cs
@@ -36,6 +36,7 @@ namespace Grpc.Testing {
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IBenchmarkServiceClient
{
global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
@@ -47,47 +48,73 @@ namespace Grpc.Testing {
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IBenchmarkService
{
Task<global::Grpc.Testing.SimpleResponse> UnaryCall(global::Grpc.Testing.SimpleRequest request, ServerCallContext context);
Task StreamingCall(IAsyncStreamReader<global::Grpc.Testing.SimpleRequest> requestStream, IServerStreamWriter<global::Grpc.Testing.SimpleResponse> responseStream, ServerCallContext context);
}
+ // server-side abstract class
+ public abstract class BenchmarkServiceBase
+ {
+ public virtual Task<global::Grpc.Testing.SimpleResponse> UnaryCall(global::Grpc.Testing.SimpleRequest request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task StreamingCall(IAsyncStreamReader<global::Grpc.Testing.SimpleRequest> requestStream, IServerStreamWriter<global::Grpc.Testing.SimpleResponse> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ }
+
// client stub
- public class BenchmarkServiceClient : ClientBase, IBenchmarkServiceClient
+ public class BenchmarkServiceClient : ClientBase<BenchmarkServiceClient>, IBenchmarkServiceClient
{
public BenchmarkServiceClient(Channel channel) : base(channel)
{
}
- public global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public BenchmarkServiceClient(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected BenchmarkServiceClient() : base()
+ {
+ }
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected BenchmarkServiceClient(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ public virtual global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return UnaryCall(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, CallOptions options)
{
- var call = CreateCall(__Method_UnaryCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
+ return CallInvoker.BlockingUnaryCall(__Method_UnaryCall, null, options, request);
}
- public global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_UnaryCall, options);
- return Calls.BlockingUnaryCall(call, request);
+ return UnaryCallAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, CallOptions options)
{
- var call = CreateCall(__Method_UnaryCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
+ return CallInvoker.AsyncUnaryCall(__Method_UnaryCall, null, options, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, CallOptions options)
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.SimpleRequest, global::Grpc.Testing.SimpleResponse> StreamingCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_UnaryCall, options);
- return Calls.AsyncUnaryCall(call, request);
+ return StreamingCall(new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.SimpleRequest, global::Grpc.Testing.SimpleResponse> StreamingCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.SimpleRequest, global::Grpc.Testing.SimpleResponse> StreamingCall(CallOptions options)
{
- var call = CreateCall(__Method_StreamingCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncDuplexStreamingCall(call);
+ return CallInvoker.AsyncDuplexStreamingCall(__Method_StreamingCall, null, options);
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.SimpleRequest, global::Grpc.Testing.SimpleResponse> StreamingCall(CallOptions options)
+ protected override BenchmarkServiceClient NewInstance(ClientBaseConfiguration configuration)
{
- var call = CreateCall(__Method_StreamingCall, options);
- return Calls.AsyncDuplexStreamingCall(call);
+ return new BenchmarkServiceClient(configuration);
}
}
@@ -99,6 +126,14 @@ namespace Grpc.Testing {
.AddMethod(__Method_StreamingCall, serviceImpl.StreamingCall).Build();
}
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(BenchmarkServiceBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_UnaryCall, serviceImpl.UnaryCall)
+ .AddMethod(__Method_StreamingCall, serviceImpl.StreamingCall).Build();
+ }
+
// creates a new client
public static BenchmarkServiceClient NewClient(Channel channel)
{
@@ -114,6 +149,9 @@ namespace Grpc.Testing {
static readonly Marshaller<global::Grpc.Testing.ServerStatus> __Marshaller_ServerStatus = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.ServerStatus.Parser.ParseFrom);
static readonly Marshaller<global::Grpc.Testing.ClientArgs> __Marshaller_ClientArgs = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.ClientArgs.Parser.ParseFrom);
static readonly Marshaller<global::Grpc.Testing.ClientStatus> __Marshaller_ClientStatus = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.ClientStatus.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Testing.CoreRequest> __Marshaller_CoreRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.CoreRequest.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Testing.CoreResponse> __Marshaller_CoreResponse = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.CoreResponse.Parser.ParseFrom);
+ static readonly Marshaller<global::Grpc.Testing.Void> __Marshaller_Void = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Grpc.Testing.Void.Parser.ParseFrom);
static readonly Method<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> __Method_RunServer = new Method<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus>(
MethodType.DuplexStreaming,
@@ -129,6 +167,20 @@ namespace Grpc.Testing {
__Marshaller_ClientArgs,
__Marshaller_ClientStatus);
+ static readonly Method<global::Grpc.Testing.CoreRequest, global::Grpc.Testing.CoreResponse> __Method_CoreCount = new Method<global::Grpc.Testing.CoreRequest, global::Grpc.Testing.CoreResponse>(
+ MethodType.Unary,
+ __ServiceName,
+ "CoreCount",
+ __Marshaller_CoreRequest,
+ __Marshaller_CoreResponse);
+
+ static readonly Method<global::Grpc.Testing.Void, global::Grpc.Testing.Void> __Method_QuitWorker = new Method<global::Grpc.Testing.Void, global::Grpc.Testing.Void>(
+ MethodType.Unary,
+ __ServiceName,
+ "QuitWorker",
+ __Marshaller_Void,
+ __Marshaller_Void);
+
// service descriptor
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
@@ -136,46 +188,127 @@ namespace Grpc.Testing {
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IWorkerServiceClient
{
AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(CallOptions options);
AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(CallOptions options);
+ global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, CallOptions options);
+ AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, CallOptions options);
+ global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, CallOptions options);
+ AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
+ AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, CallOptions options);
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IWorkerService
{
Task RunServer(IAsyncStreamReader<global::Grpc.Testing.ServerArgs> requestStream, IServerStreamWriter<global::Grpc.Testing.ServerStatus> responseStream, ServerCallContext context);
Task RunClient(IAsyncStreamReader<global::Grpc.Testing.ClientArgs> requestStream, IServerStreamWriter<global::Grpc.Testing.ClientStatus> responseStream, ServerCallContext context);
+ Task<global::Grpc.Testing.CoreResponse> CoreCount(global::Grpc.Testing.CoreRequest request, ServerCallContext context);
+ Task<global::Grpc.Testing.Void> QuitWorker(global::Grpc.Testing.Void request, ServerCallContext context);
+ }
+
+ // server-side abstract class
+ public abstract class WorkerServiceBase
+ {
+ public virtual Task RunServer(IAsyncStreamReader<global::Grpc.Testing.ServerArgs> requestStream, IServerStreamWriter<global::Grpc.Testing.ServerStatus> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task RunClient(IAsyncStreamReader<global::Grpc.Testing.ClientArgs> requestStream, IServerStreamWriter<global::Grpc.Testing.ClientStatus> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task<global::Grpc.Testing.CoreResponse> CoreCount(global::Grpc.Testing.CoreRequest request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task<global::Grpc.Testing.Void> QuitWorker(global::Grpc.Testing.Void request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
}
// client stub
- public class WorkerServiceClient : ClientBase, IWorkerServiceClient
+ public class WorkerServiceClient : ClientBase<WorkerServiceClient>, IWorkerServiceClient
{
public WorkerServiceClient(Channel channel) : base(channel)
{
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public WorkerServiceClient(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected WorkerServiceClient() : base()
+ {
+ }
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected WorkerServiceClient(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return RunServer(new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(CallOptions options)
+ {
+ return CallInvoker.AsyncDuplexStreamingCall(__Method_RunServer, null, options);
+ }
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return RunClient(new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(CallOptions options)
+ {
+ return CallInvoker.AsyncDuplexStreamingCall(__Method_RunClient, null, options);
+ }
+ public virtual global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return CoreCount(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual global::Grpc.Testing.CoreResponse CoreCount(global::Grpc.Testing.CoreRequest request, CallOptions options)
{
- var call = CreateCall(__Method_RunServer, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncDuplexStreamingCall(call);
+ return CallInvoker.BlockingUnaryCall(__Method_CoreCount, null, options, request);
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.ServerArgs, global::Grpc.Testing.ServerStatus> RunServer(CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_RunServer, options);
- return Calls.AsyncDuplexStreamingCall(call);
+ return CoreCountAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Grpc.Testing.CoreResponse> CoreCountAsync(global::Grpc.Testing.CoreRequest request, CallOptions options)
{
- var call = CreateCall(__Method_RunClient, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncDuplexStreamingCall(call);
+ return CallInvoker.AsyncUnaryCall(__Method_CoreCount, null, options, request);
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.ClientArgs, global::Grpc.Testing.ClientStatus> RunClient(CallOptions options)
+ public virtual global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_RunClient, options);
- return Calls.AsyncDuplexStreamingCall(call);
+ return QuitWorker(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual global::Grpc.Testing.Void QuitWorker(global::Grpc.Testing.Void request, CallOptions options)
+ {
+ return CallInvoker.BlockingUnaryCall(__Method_QuitWorker, null, options, request);
+ }
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return QuitWorkerAsync(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Void> QuitWorkerAsync(global::Grpc.Testing.Void request, CallOptions options)
+ {
+ return CallInvoker.AsyncUnaryCall(__Method_QuitWorker, null, options, request);
+ }
+ protected override WorkerServiceClient NewInstance(ClientBaseConfiguration configuration)
+ {
+ return new WorkerServiceClient(configuration);
}
}
@@ -184,7 +317,19 @@ namespace Grpc.Testing {
{
return ServerServiceDefinition.CreateBuilder(__ServiceName)
.AddMethod(__Method_RunServer, serviceImpl.RunServer)
- .AddMethod(__Method_RunClient, serviceImpl.RunClient).Build();
+ .AddMethod(__Method_RunClient, serviceImpl.RunClient)
+ .AddMethod(__Method_CoreCount, serviceImpl.CoreCount)
+ .AddMethod(__Method_QuitWorker, serviceImpl.QuitWorker).Build();
+ }
+
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(WorkerServiceBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_RunServer, serviceImpl.RunServer)
+ .AddMethod(__Method_RunClient, serviceImpl.RunClient)
+ .AddMethod(__Method_CoreCount, serviceImpl.CoreCount)
+ .AddMethod(__Method_QuitWorker, serviceImpl.QuitWorker).Build();
}
// creates a new client
diff --git a/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs b/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs
index 37b2518c21..3df45b5f70 100644
--- a/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -53,7 +53,7 @@ namespace Grpc.IntegrationTesting
const string Host = "localhost";
Server server;
Channel channel;
- TestService.ITestServiceClient client;
+ TestService.TestServiceClient client;
[TestFixtureSetUp]
public void Init()
diff --git a/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs b/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs
index 2c469080d9..b84ec2d984 100644
--- a/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs
+++ b/src/csharp/Grpc.IntegrationTesting/TestGrpc.cs
@@ -69,6 +69,7 @@ namespace Grpc.Testing {
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface ITestServiceClient
{
global::Grpc.Testing.Empty EmptyCall(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
@@ -90,6 +91,7 @@ namespace Grpc.Testing {
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface ITestService
{
Task<global::Grpc.Testing.Empty> EmptyCall(global::Grpc.Testing.Empty request, ServerCallContext context);
@@ -100,91 +102,126 @@ namespace Grpc.Testing {
Task HalfDuplexCall(IAsyncStreamReader<global::Grpc.Testing.StreamingOutputCallRequest> requestStream, IServerStreamWriter<global::Grpc.Testing.StreamingOutputCallResponse> responseStream, ServerCallContext context);
}
+ // server-side abstract class
+ public abstract class TestServiceBase
+ {
+ public virtual Task<global::Grpc.Testing.Empty> EmptyCall(global::Grpc.Testing.Empty request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task<global::Grpc.Testing.SimpleResponse> UnaryCall(global::Grpc.Testing.SimpleRequest request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task StreamingOutputCall(global::Grpc.Testing.StreamingOutputCallRequest request, IServerStreamWriter<global::Grpc.Testing.StreamingOutputCallResponse> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task<global::Grpc.Testing.StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader<global::Grpc.Testing.StreamingInputCallRequest> requestStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task FullDuplexCall(IAsyncStreamReader<global::Grpc.Testing.StreamingOutputCallRequest> requestStream, IServerStreamWriter<global::Grpc.Testing.StreamingOutputCallResponse> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task HalfDuplexCall(IAsyncStreamReader<global::Grpc.Testing.StreamingOutputCallRequest> requestStream, IServerStreamWriter<global::Grpc.Testing.StreamingOutputCallResponse> responseStream, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ }
+
// client stub
- public class TestServiceClient : ClientBase, ITestServiceClient
+ public class TestServiceClient : ClientBase<TestServiceClient>, ITestServiceClient
{
public TestServiceClient(Channel channel) : base(channel)
{
}
- public global::Grpc.Testing.Empty EmptyCall(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public TestServiceClient(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected TestServiceClient() : base()
+ {
+ }
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected TestServiceClient(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ public virtual global::Grpc.Testing.Empty EmptyCall(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_EmptyCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
+ return EmptyCall(request, new CallOptions(headers, deadline, cancellationToken));
}
- public global::Grpc.Testing.Empty EmptyCall(global::Grpc.Testing.Empty request, CallOptions options)
+ public virtual global::Grpc.Testing.Empty EmptyCall(global::Grpc.Testing.Empty request, CallOptions options)
{
- var call = CreateCall(__Method_EmptyCall, options);
- return Calls.BlockingUnaryCall(call, request);
+ return CallInvoker.BlockingUnaryCall(__Method_EmptyCall, null, options, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.Empty> EmptyCallAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Empty> EmptyCallAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_EmptyCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
+ return EmptyCallAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncUnaryCall<global::Grpc.Testing.Empty> EmptyCallAsync(global::Grpc.Testing.Empty request, CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Empty> EmptyCallAsync(global::Grpc.Testing.Empty request, CallOptions options)
{
- var call = CreateCall(__Method_EmptyCall, options);
- return Calls.AsyncUnaryCall(call, request);
+ return CallInvoker.AsyncUnaryCall(__Method_EmptyCall, null, options, request);
}
- public global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_UnaryCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
+ return UnaryCall(request, new CallOptions(headers, deadline, cancellationToken));
}
- public global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, CallOptions options)
+ public virtual global::Grpc.Testing.SimpleResponse UnaryCall(global::Grpc.Testing.SimpleRequest request, CallOptions options)
{
- var call = CreateCall(__Method_UnaryCall, options);
- return Calls.BlockingUnaryCall(call, request);
+ return CallInvoker.BlockingUnaryCall(__Method_UnaryCall, null, options, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_UnaryCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
+ return UnaryCallAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Testing.SimpleResponse> UnaryCallAsync(global::Grpc.Testing.SimpleRequest request, CallOptions options)
{
- var call = CreateCall(__Method_UnaryCall, options);
- return Calls.AsyncUnaryCall(call, request);
+ return CallInvoker.AsyncUnaryCall(__Method_UnaryCall, null, options, request);
}
- public AsyncServerStreamingCall<global::Grpc.Testing.StreamingOutputCallResponse> StreamingOutputCall(global::Grpc.Testing.StreamingOutputCallRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncServerStreamingCall<global::Grpc.Testing.StreamingOutputCallResponse> StreamingOutputCall(global::Grpc.Testing.StreamingOutputCallRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_StreamingOutputCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncServerStreamingCall(call, request);
+ return StreamingOutputCall(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncServerStreamingCall<global::Grpc.Testing.StreamingOutputCallResponse> StreamingOutputCall(global::Grpc.Testing.StreamingOutputCallRequest request, CallOptions options)
+ public virtual AsyncServerStreamingCall<global::Grpc.Testing.StreamingOutputCallResponse> StreamingOutputCall(global::Grpc.Testing.StreamingOutputCallRequest request, CallOptions options)
{
- var call = CreateCall(__Method_StreamingOutputCall, options);
- return Calls.AsyncServerStreamingCall(call, request);
+ return CallInvoker.AsyncServerStreamingCall(__Method_StreamingOutputCall, null, options, request);
}
- public AsyncClientStreamingCall<global::Grpc.Testing.StreamingInputCallRequest, global::Grpc.Testing.StreamingInputCallResponse> StreamingInputCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncClientStreamingCall<global::Grpc.Testing.StreamingInputCallRequest, global::Grpc.Testing.StreamingInputCallResponse> StreamingInputCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_StreamingInputCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncClientStreamingCall(call);
+ return StreamingInputCall(new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncClientStreamingCall<global::Grpc.Testing.StreamingInputCallRequest, global::Grpc.Testing.StreamingInputCallResponse> StreamingInputCall(CallOptions options)
+ public virtual AsyncClientStreamingCall<global::Grpc.Testing.StreamingInputCallRequest, global::Grpc.Testing.StreamingInputCallResponse> StreamingInputCall(CallOptions options)
{
- var call = CreateCall(__Method_StreamingInputCall, options);
- return Calls.AsyncClientStreamingCall(call);
+ return CallInvoker.AsyncClientStreamingCall(__Method_StreamingInputCall, null, options);
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> FullDuplexCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> FullDuplexCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_FullDuplexCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncDuplexStreamingCall(call);
+ return FullDuplexCall(new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> FullDuplexCall(CallOptions options)
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> FullDuplexCall(CallOptions options)
{
- var call = CreateCall(__Method_FullDuplexCall, options);
- return Calls.AsyncDuplexStreamingCall(call);
+ return CallInvoker.AsyncDuplexStreamingCall(__Method_FullDuplexCall, null, options);
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> HalfDuplexCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> HalfDuplexCall(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_HalfDuplexCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncDuplexStreamingCall(call);
+ return HalfDuplexCall(new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> HalfDuplexCall(CallOptions options)
+ public virtual AsyncDuplexStreamingCall<global::Grpc.Testing.StreamingOutputCallRequest, global::Grpc.Testing.StreamingOutputCallResponse> HalfDuplexCall(CallOptions options)
{
- var call = CreateCall(__Method_HalfDuplexCall, options);
- return Calls.AsyncDuplexStreamingCall(call);
+ return CallInvoker.AsyncDuplexStreamingCall(__Method_HalfDuplexCall, null, options);
+ }
+ protected override TestServiceClient NewInstance(ClientBaseConfiguration configuration)
+ {
+ return new TestServiceClient(configuration);
}
}
@@ -200,6 +237,18 @@ namespace Grpc.Testing {
.AddMethod(__Method_HalfDuplexCall, serviceImpl.HalfDuplexCall).Build();
}
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(TestServiceBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_EmptyCall, serviceImpl.EmptyCall)
+ .AddMethod(__Method_UnaryCall, serviceImpl.UnaryCall)
+ .AddMethod(__Method_StreamingOutputCall, serviceImpl.StreamingOutputCall)
+ .AddMethod(__Method_StreamingInputCall, serviceImpl.StreamingInputCall)
+ .AddMethod(__Method_FullDuplexCall, serviceImpl.FullDuplexCall)
+ .AddMethod(__Method_HalfDuplexCall, serviceImpl.HalfDuplexCall).Build();
+ }
+
// creates a new client
public static TestServiceClient NewClient(Channel channel)
{
@@ -227,6 +276,7 @@ namespace Grpc.Testing {
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IUnimplementedServiceClient
{
global::Grpc.Testing.Empty UnimplementedCall(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
@@ -236,36 +286,59 @@ namespace Grpc.Testing {
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IUnimplementedService
{
Task<global::Grpc.Testing.Empty> UnimplementedCall(global::Grpc.Testing.Empty request, ServerCallContext context);
}
+ // server-side abstract class
+ public abstract class UnimplementedServiceBase
+ {
+ public virtual Task<global::Grpc.Testing.Empty> UnimplementedCall(global::Grpc.Testing.Empty request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ }
+
// client stub
- public class UnimplementedServiceClient : ClientBase, IUnimplementedServiceClient
+ public class UnimplementedServiceClient : ClientBase<UnimplementedServiceClient>, IUnimplementedServiceClient
{
public UnimplementedServiceClient(Channel channel) : base(channel)
{
}
- public global::Grpc.Testing.Empty UnimplementedCall(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public UnimplementedServiceClient(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected UnimplementedServiceClient() : base()
+ {
+ }
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected UnimplementedServiceClient(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ public virtual global::Grpc.Testing.Empty UnimplementedCall(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return UnimplementedCall(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual global::Grpc.Testing.Empty UnimplementedCall(global::Grpc.Testing.Empty request, CallOptions options)
{
- var call = CreateCall(__Method_UnimplementedCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
+ return CallInvoker.BlockingUnaryCall(__Method_UnimplementedCall, null, options, request);
}
- public global::Grpc.Testing.Empty UnimplementedCall(global::Grpc.Testing.Empty request, CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Empty> UnimplementedCallAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_UnimplementedCall, options);
- return Calls.BlockingUnaryCall(call, request);
+ return UnimplementedCallAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncUnaryCall<global::Grpc.Testing.Empty> UnimplementedCallAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Empty> UnimplementedCallAsync(global::Grpc.Testing.Empty request, CallOptions options)
{
- var call = CreateCall(__Method_UnimplementedCall, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
+ return CallInvoker.AsyncUnaryCall(__Method_UnimplementedCall, null, options, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.Empty> UnimplementedCallAsync(global::Grpc.Testing.Empty request, CallOptions options)
+ protected override UnimplementedServiceClient NewInstance(ClientBaseConfiguration configuration)
{
- var call = CreateCall(__Method_UnimplementedCall, options);
- return Calls.AsyncUnaryCall(call, request);
+ return new UnimplementedServiceClient(configuration);
}
}
@@ -276,6 +349,13 @@ namespace Grpc.Testing {
.AddMethod(__Method_UnimplementedCall, serviceImpl.UnimplementedCall).Build();
}
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(UnimplementedServiceBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_UnimplementedCall, serviceImpl.UnimplementedCall).Build();
+ }
+
// creates a new client
public static UnimplementedServiceClient NewClient(Channel channel)
{
@@ -311,6 +391,7 @@ namespace Grpc.Testing {
}
// client interface
+ [System.Obsolete("Client side interfaced will be removed in the next release. Use client class directly.")]
public interface IReconnectServiceClient
{
global::Grpc.Testing.Empty Start(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken));
@@ -324,57 +405,81 @@ namespace Grpc.Testing {
}
// server-side interface
+ [System.Obsolete("Service implementations should inherit from the generated abstract base class instead.")]
public interface IReconnectService
{
Task<global::Grpc.Testing.Empty> Start(global::Grpc.Testing.Empty request, ServerCallContext context);
Task<global::Grpc.Testing.ReconnectInfo> Stop(global::Grpc.Testing.Empty request, ServerCallContext context);
}
+ // server-side abstract class
+ public abstract class ReconnectServiceBase
+ {
+ public virtual Task<global::Grpc.Testing.Empty> Start(global::Grpc.Testing.Empty request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ public virtual Task<global::Grpc.Testing.ReconnectInfo> Stop(global::Grpc.Testing.Empty request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ }
+
// client stub
- public class ReconnectServiceClient : ClientBase, IReconnectServiceClient
+ public class ReconnectServiceClient : ClientBase<ReconnectServiceClient>, IReconnectServiceClient
{
public ReconnectServiceClient(Channel channel) : base(channel)
{
}
- public global::Grpc.Testing.Empty Start(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public ReconnectServiceClient(CallInvoker callInvoker) : base(callInvoker)
{
- var call = CreateCall(__Method_Start, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
}
- public global::Grpc.Testing.Empty Start(global::Grpc.Testing.Empty request, CallOptions options)
+ ///<summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected ReconnectServiceClient() : base()
{
- var call = CreateCall(__Method_Start, options);
- return Calls.BlockingUnaryCall(call, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.Empty> StartAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ ///<summary>Protected constructor to allow creation of configured clients.</summary>
+ protected ReconnectServiceClient(ClientBaseConfiguration configuration) : base(configuration)
{
- var call = CreateCall(__Method_Start, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.Empty> StartAsync(global::Grpc.Testing.Empty request, CallOptions options)
+
+ public virtual global::Grpc.Testing.Empty Start(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Start, options);
- return Calls.AsyncUnaryCall(call, request);
+ return Start(request, new CallOptions(headers, deadline, cancellationToken));
}
- public global::Grpc.Testing.ReconnectInfo Stop(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual global::Grpc.Testing.Empty Start(global::Grpc.Testing.Empty request, CallOptions options)
{
- var call = CreateCall(__Method_Stop, new CallOptions(headers, deadline, cancellationToken));
- return Calls.BlockingUnaryCall(call, request);
+ return CallInvoker.BlockingUnaryCall(__Method_Start, null, options, request);
}
- public global::Grpc.Testing.ReconnectInfo Stop(global::Grpc.Testing.Empty request, CallOptions options)
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Empty> StartAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Stop, options);
- return Calls.BlockingUnaryCall(call, request);
+ return StartAsync(request, new CallOptions(headers, deadline, cancellationToken));
}
- public AsyncUnaryCall<global::Grpc.Testing.ReconnectInfo> StopAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ public virtual AsyncUnaryCall<global::Grpc.Testing.Empty> StartAsync(global::Grpc.Testing.Empty request, CallOptions options)
{
- var call = CreateCall(__Method_Stop, new CallOptions(headers, deadline, cancellationToken));
- return Calls.AsyncUnaryCall(call, request);
+ return CallInvoker.AsyncUnaryCall(__Method_Start, null, options, request);
}
- public AsyncUnaryCall<global::Grpc.Testing.ReconnectInfo> StopAsync(global::Grpc.Testing.Empty request, CallOptions options)
+ public virtual global::Grpc.Testing.ReconnectInfo Stop(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var call = CreateCall(__Method_Stop, options);
- return Calls.AsyncUnaryCall(call, request);
+ return Stop(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual global::Grpc.Testing.ReconnectInfo Stop(global::Grpc.Testing.Empty request, CallOptions options)
+ {
+ return CallInvoker.BlockingUnaryCall(__Method_Stop, null, options, request);
+ }
+ public virtual AsyncUnaryCall<global::Grpc.Testing.ReconnectInfo> StopAsync(global::Grpc.Testing.Empty request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return StopAsync(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ public virtual AsyncUnaryCall<global::Grpc.Testing.ReconnectInfo> StopAsync(global::Grpc.Testing.Empty request, CallOptions options)
+ {
+ return CallInvoker.AsyncUnaryCall(__Method_Stop, null, options, request);
+ }
+ protected override ReconnectServiceClient NewInstance(ClientBaseConfiguration configuration)
+ {
+ return new ReconnectServiceClient(configuration);
}
}
@@ -386,6 +491,14 @@ namespace Grpc.Testing {
.AddMethod(__Method_Stop, serviceImpl.Stop).Build();
}
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(ReconnectServiceBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_Start, serviceImpl.Start)
+ .AddMethod(__Method_Stop, serviceImpl.Stop).Build();
+ }
+
// creates a new client
public static ReconnectServiceClient NewClient(Channel channel)
{
diff --git a/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs b/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs
index 5a1b4cf319..354318e80e 100644
--- a/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs
+++ b/src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -45,14 +45,14 @@ namespace Grpc.Testing
/// <summary>
/// Implementation of TestService server
/// </summary>
- public class TestServiceImpl : TestService.ITestService
+ public class TestServiceImpl : TestService.TestServiceBase
{
- public Task<Empty> EmptyCall(Empty request, ServerCallContext context)
+ public override Task<Empty> EmptyCall(Empty request, ServerCallContext context)
{
return Task.FromResult(new Empty());
}
- public async Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
+ public override async Task<SimpleResponse> UnaryCall(SimpleRequest request, ServerCallContext context)
{
await EnsureEchoMetadataAsync(context);
EnsureEchoStatus(request.ResponseStatus, context);
@@ -61,7 +61,7 @@ namespace Grpc.Testing
return response;
}
- public async Task StreamingOutputCall(StreamingOutputCallRequest request, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context)
+ public override async Task StreamingOutputCall(StreamingOutputCallRequest request, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context)
{
await EnsureEchoMetadataAsync(context);
EnsureEchoStatus(request.ResponseStatus, context);
@@ -73,7 +73,7 @@ namespace Grpc.Testing
}
}
- public async Task<StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader<StreamingInputCallRequest> requestStream, ServerCallContext context)
+ public override async Task<StreamingInputCallResponse> StreamingInputCall(IAsyncStreamReader<StreamingInputCallRequest> requestStream, ServerCallContext context)
{
await EnsureEchoMetadataAsync(context);
@@ -85,7 +85,7 @@ namespace Grpc.Testing
return new StreamingInputCallResponse { AggregatedPayloadSize = sum };
}
- public async Task FullDuplexCall(IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context)
+ public override async Task FullDuplexCall(IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context)
{
await EnsureEchoMetadataAsync(context);
@@ -100,7 +100,7 @@ namespace Grpc.Testing
});
}
- public async Task HalfDuplexCall(IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context)
+ public override async Task HalfDuplexCall(IAsyncStreamReader<StreamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCallResponse> responseStream, ServerCallContext context)
{
throw new NotImplementedException();
}
diff --git a/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs b/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs
index bb2918bf46..80dad9fdd9 100644
--- a/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs
+++ b/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs
@@ -45,11 +45,18 @@ namespace Grpc.Testing
/// <summary>
/// Implementation of WorkerService server
/// </summary>
- public class WorkerServiceImpl : WorkerService.IWorkerService
+ public class WorkerServiceImpl : WorkerService.WorkerServiceBase
{
- public async Task RunServer(IAsyncStreamReader<ServerArgs> requestStream, IServerStreamWriter<ServerStatus> responseStream, ServerCallContext context)
+ readonly Action stopRequestHandler;
+
+ public WorkerServiceImpl(Action stopRequestHandler)
+ {
+ this.stopRequestHandler = GrpcPreconditions.CheckNotNull(stopRequestHandler);
+ }
+
+ public override async Task RunServer(IAsyncStreamReader<ServerArgs> requestStream, IServerStreamWriter<ServerStatus> responseStream, ServerCallContext context)
{
- Grpc.Core.Utils.Preconditions.CheckState(await requestStream.MoveNext());
+ GrpcPreconditions.CheckState(await requestStream.MoveNext());
var serverConfig = requestStream.Current.Setup;
var runner = ServerRunners.CreateStarted(serverConfig);
@@ -71,9 +78,9 @@ namespace Grpc.Testing
await runner.StopAsync();
}
- public async Task RunClient(IAsyncStreamReader<ClientArgs> requestStream, IServerStreamWriter<ClientStatus> responseStream, ServerCallContext context)
+ public override async Task RunClient(IAsyncStreamReader<ClientArgs> requestStream, IServerStreamWriter<ClientStatus> responseStream, ServerCallContext context)
{
- Grpc.Core.Utils.Preconditions.CheckState(await requestStream.MoveNext());
+ GrpcPreconditions.CheckState(await requestStream.MoveNext());
var clientConfig = requestStream.Current.Setup;
var runner = ClientRunners.CreateStarted(clientConfig);
@@ -92,5 +99,16 @@ namespace Grpc.Testing
}
await runner.StopAsync();
}
+
+ public override Task<CoreResponse> CoreCount(CoreRequest request, ServerCallContext context)
+ {
+ return Task.FromResult(new CoreResponse { Cores = Environment.ProcessorCount });
+ }
+
+ public override Task<Void> QuitWorker(Void request, ServerCallContext context)
+ {
+ stopRequestHandler();
+ return Task.FromResult(new Void());
+ }
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting/app.config b/src/csharp/Grpc.IntegrationTesting/app.config
deleted file mode 100644
index 84d7534d65..0000000000
--- a/src/csharp/Grpc.IntegrationTesting/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.0.0.0" />
- </dependentAssembly>
- <dependentAssembly>
- <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-1.9.2.38523" newVersion="1.9.2.38523" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
-</configuration> \ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting/packages.config b/src/csharp/Grpc.IntegrationTesting/packages.config
index 462dc9d604..0ae8bf4e70 100644
--- a/src/csharp/Grpc.IntegrationTesting/packages.config
+++ b/src/csharp/Grpc.IntegrationTesting/packages.config
@@ -2,14 +2,10 @@
<packages>
<package id="BouncyCastle" version="1.7.0" targetFramework="net45" />
<package id="CommandLineParser" version="1.9.71" targetFramework="net45" />
- <package id="Google.Apis.Auth" version="1.10.0" targetFramework="net45" />
- <package id="Google.Apis.Core" version="1.10.0" targetFramework="net45" />
+ <package id="Google.Apis.Auth" version="1.11.1" targetFramework="net45" />
+ <package id="Google.Apis.Core" version="1.11.1" targetFramework="net45" />
<package id="Google.Protobuf" version="3.0.0-beta2" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
- <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
- <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
- <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
- <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
diff --git a/src/csharp/Grpc.Tools.nuspec b/src/csharp/Grpc.Tools.nuspec
index 48a7b1f3af..31d1bed647 100644
--- a/src/csharp/Grpc.Tools.nuspec
+++ b/src/csharp/Grpc.Tools.nuspec
@@ -4,18 +4,29 @@
<id>Grpc.Tools</id>
<title>gRPC C# Tools</title>
<summary>Tools for C# implementation of gRPC - an RPC library and framework</summary>
- <description>Precompiled Windows binary for generating gRPC client/server code</description>
+ <description>Precompiled protobuf compiler and gRPC protobuf compiler plugin for generating gRPC client/server C# code. Binaries are available for Windows, Linux and MacOS.</description>
<version>$version$</version>
<authors>Google Inc.</authors>
<owners>grpc-packages</owners>
<licenseUrl>https://github.com/grpc/grpc/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/grpc/grpc</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
- <releaseNotes>grpc_csharp_plugin.exe - gRPC C# protoc plugin version $version$</releaseNotes>
+ <releaseNotes>Release $version$</releaseNotes>
<copyright>Copyright 2015, Google Inc.</copyright>
<tags>gRPC RPC Protocol HTTP/2</tags>
</metadata>
<files>
- <file src="..\..\vsprojects\Release\grpc_csharp_plugin.exe" target="tools" />
+ <file src="protoc_plugins\windows_x86\protoc.exe" target="tools\windows_x86\protoc.exe" />
+ <file src="protoc_plugins\windows_x86\grpc_csharp_plugin.exe" target="tools\windows_x86\grpc_csharp_plugin.exe" />
+ <file src="protoc_plugins\windows_x64\protoc.exe" target="tools\windows_x64\protoc.exe" />
+ <file src="protoc_plugins\windows_x64\grpc_csharp_plugin.exe" target="tools\windows_x64\grpc_csharp_plugin.exe" />
+ <file src="protoc_plugins\linux_x86\protoc" target="tools\linux_x86\protoc" />
+ <file src="protoc_plugins\linux_x86\grpc_csharp_plugin" target="tools\linux_x86\grpc_csharp_plugin" />
+ <file src="protoc_plugins\linux_x64\protoc" target="tools\linux_x64\protoc" />
+ <file src="protoc_plugins\linux_x64\grpc_csharp_plugin" target="tools\linux_x64\grpc_csharp_plugin" />
+ <file src="protoc_plugins\macosx_x86\protoc" target="tools\macosx_x86\protoc" />
+ <file src="protoc_plugins\macosx_x86\grpc_csharp_plugin" target="tools\macosx_x86\grpc_csharp_plugin" />
+ <file src="protoc_plugins\macosx_x64\protoc" target="tools\macosx_x64\protoc" />
+ <file src="protoc_plugins\macosx_x64\grpc_csharp_plugin" target="tools\macosx_x64\grpc_csharp_plugin" />
</files>
</package>
diff --git a/src/csharp/README.md b/src/csharp/README.md
index 65ae0b5efd..201c5ab0b5 100644
--- a/src/csharp/README.md
+++ b/src/csharp/README.md
@@ -12,9 +12,9 @@ Beta
PREREQUISITES
--------------
-- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015.
-- Linux: Mono 3.2.8+, MonoDevelop 5.9 with NuGet add-in installed.
-- Mac OS X: [homebrew][], Xamarin Studio with NuGet add-in installed.
+- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015
+- Linux: Mono 4+, MonoDevelop 5.9+ (with NuGet add-in installed)
+- Mac OS X: Xamarin Studio 5.9+
HOW TO USE
--------------
@@ -24,66 +24,28 @@ HOW TO USE
- Open Visual Studio and start a new project/solution.
- Add NuGet package `Grpc` as a dependency (Project options -> Manage NuGet Packages).
- That will also pull all the transitive dependencies (including the native libraries that
+ That will also pull all the transitive dependencies (including the gRPC native library that
gRPC C# is using internally).
**Linux (Debian)**
-- Add [Debian jessie-backports][] to your `sources.list` file. Example:
-
- ```sh
- echo "deb http://http.debian.net/debian jessie-backports main" | \
- sudo tee -a /etc/apt/sources.list
- ```
-
-- Install the gRPC Debian package
-
- ```sh
- sudo apt-get update
- sudo apt-get install libgrpc0
- ```
-
-- gRPC C# depends on native shared library `libgrpc_csharp_ext.so` (Unix flavor of grpc_csharp_ext.dll).
- This library is not part of the base gRPC debian package and needs to be installed manually from
- a `.deb` file. Download the debian package `libgrpc_csharp_ext` from corresponding gRPC release on GitHub
- and install it using `dpkg`.
-
- ```sh
- # choose version corresponding to the version of libgrpc you've installed.
- wget https://github.com/grpc/grpc/releases/download/release-0_11_0/libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb
- dpkg -i libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb
- ```
-
- Open MonoDevelop and start a new project/solution.
- Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages).
+ That will also pull all the transitive dependencies (including the gRPC native library that
+ gRPC C# is using internally).
-- NOTE: Currently, there are no debian packages for the latest version Protocol Buffers compiler (_protoc_)
- and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][].
+- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Linux version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][].
**Mac OS X**
-- WARNING: As of now gRPC C# only works on 64bit version of Mono (because we don't compile
- the native extension for C# in 32bit mode yet). That means your development experience
- with Xamarin Studio on MacOS will not be great, as you won't be able to run your
- code directly from Xamarin Studio (which requires 32bit version of Mono).
-
-- Install [homebrew][]. Run the following command to install gRPC C# native dependencies.
-
- ```sh
- $ curl -fsSL https://goo.gl/getgrpc | bash -
- ```
- This will download and run the [gRPC install script][], then install the latest version of gRPC C core and native C# extension.
- It also installs Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin for C#.
-
-- Install 64-bit version of mono with command `brew install mono`.
-
- Open Xamarin Studio and start a new project/solution.
- Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages).
+ That will also pull all the transitive dependencies (including the gRPC native library that
+ gRPC C# is using internally).
-- *You will be able to build your project in Xamarin Studio, but to run or test it,
- you will need to run it under 64-bit version of Mono.*
+- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Mac OS X version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Homebrew instructions][].
BUILD FROM SOURCE
-----------------
@@ -93,39 +55,32 @@ If you are a user of gRPC C#, go to Usage section above.
**Windows**
-- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. You can
- either build the native solution in `vsprojects/grpc.sln` from Visual Studio manually, or you can use
- a convenience batch script that builds everything for you.
+- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. Open the
+ solution `vsprojects/grpc_csharp_ext.sln` in Visual Studio and build it.
- ```
- > REM From src/csharp directory
- > buildall.bat
- ```
-
-- Open Grpc.sln using Visual Studio. NuGet dependencies will be restored
- upon build (you need to have NuGet add-in installed).
+- Open `src\csharp\Grpc.sln` (path is relative to gRPC repository root)
+ using Visual Studio
**Linux**
+- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution:
```sh
- $ sudo apt-get install mono-devel
- $ sudo apt-get install nunit nunit-console
+ # from the gRPC repository root
+ $ make CONFIG=dbg grpc_csharp_ext
```
-You can use older versions of MonoDevelop, but then you might need to restore
-NuGet dependencies manually (by `nuget restore`), because older versions of MonoDevelop
-don't support NuGet add-in.
+- Use MonoDevelop to open the solution Grpc.sln
+
+**Mac OS X**
+
+- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution.
-- Compile and install the gRPC C# extension library (that will be used via
- P/Invoke from C#).
```sh
- $ make grpc_csharp_ext
- $ sudo make install_grpc_csharp_ext
+ # from the gRPC repository root
+ $ tools/run_tests/run_tests.py -c dbg -l csharp --build_only
```
-- Use MonoDevelop to open the solution Grpc.sln
-
-- Build the solution & run all the tests from test view.
+- Use Xamarin Studio to open the solution Grpc.sln
RUNNING TESTS
-------------
@@ -135,17 +90,9 @@ gRPC C# is using NUnit as the testing framework.
Under Visual Studio, make sure NUnit test adapter is installed (under "Extensions and Updates").
Then you should be able to run all the tests using Test Explorer.
-Under Monodevelop, make sure you installed "NUnit support" in Add-in manager.
+Under Monodevelop or Xamarin Studio, make sure you installed "NUnit support" in Add-in manager.
Then you should be able to run all the test from the Test View.
-After building the solution, you can also run the tests from command line
-using nunit-console tool.
-
-```sh
-# from Grpc.Core.Test/bin/Debug directory
-$ nunit-console Grpc.Core.Tests.dll
-```
-
gRPC team uses a Python script to simplify facilitate running tests for
different languages.
@@ -176,27 +123,15 @@ CONTENTS
- Grpc.IntegrationTesting:
Cross-language gRPC implementation testing (interop testing).
-TROUBLESHOOTING
+THE NATIVE DEPENDENCY
---------------
-### Problem: Unable to load DLL 'grpc_csharp_ext.dll'
-
-Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. If you get the above error, it means that the native dependencies could not be located by the C# runtime (or they are incompatible with the current runtime, so they could not be loaded). The solution to this is environment specific.
-
-- If you are developing on Windows in Visual Studio, the `grpc_csharp_ext.dll` that is shipped by gRPC nuget packages should be automatically copied to your build destination folder once you build. By adjusting project properties in your VS project file, you can influence which exact configuration of `grpc_csharp_ext.dll` will be used (based on VS version, bitness, debug/release configuration).
-
-- If you are running your application that is using gRPC on Windows machine that doesn't have Visual Studio installed, you might need to install [Visual C++ 2013 redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=40784) that contains some system .dll libraries that `grpc_csharp_ext.dll` depends on (see #905 for more details).
-
-- On Linux (or Docker), you need to first install gRPC C core and `libgrpc_csharp_ext.so` shared libraries.
- See [How to Use](#how-to-use) section for details how to install it.
- Installation on a machine where your application is going to be deployed is no different.
-
-- On Mac, you need to first install gRPC C core and `libgrpc_csharp_ext.dylib` shared libraries using Homebrew. See above for installation instruction.
- Installation on a machine where your application is going to be deployed is no different.
+Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke.
-- Possible cause for the problem is that the `grpc_csharp_ext` library is installed, but it has different bitness (32/64bit) than your C# runtime (in case you are using mono) or C# application.
+Prior to version 0.13, installing `grpc_csharp_ext` was required to make gRPC work on Linux and MacOS. Starting with version 0.13, we have improved the packaging story significantly and precompiled versions of the native library for all supported platforms are now shipped with the NuGet package. Just installing the `Grpc` NuGet package should be the only step needed to use gRPC C#, regardless of your platform (Windows, Linux or Mac) and the bitness (32 or 64bit).
[gRPC Linuxbrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux
+[gRPC Homebrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux
[homebrew]:http://brew.sh
[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
[grpc.io]: http://www.grpc.io/docs/installation/csharp.html
diff --git a/src/csharp/build_packages.bat b/src/csharp/build_packages.bat
index e423545ef8..7c42a6d3fc 100644
--- a/src/csharp/build_packages.bat
+++ b/src/csharp/build_packages.bat
@@ -1,7 +1,7 @@
@rem Builds gRPC NuGet packages
@rem Current package versions
-set VERSION=0.13.0
+set VERSION=0.14.0-dev
set PROTOBUF_VERSION=3.0.0-beta2
@rem Packages that depend on prerelease packages (like Google.Protobuf) need to have prerelease suffix as well.
@@ -19,6 +19,14 @@ xcopy /Y /I ..\..\architecture=x64,language=csharp,platform=linux\artifacts\* gr
xcopy /Y /I ..\..\architecture=x86,language=csharp,platform=macos\artifacts\* grpc.native.csharp\macosx_x86\
xcopy /Y /I ..\..\architecture=x64,language=csharp,platform=macos\artifacts\* grpc.native.csharp\macosx_x64\
+@rem Collect protoc artifacts built by the previous build step
+xcopy /Y /I ..\..\architecture=x86,language=protoc,platform=windows\artifacts\* protoc_plugins\windows_x86\
+xcopy /Y /I ..\..\architecture=x64,language=protoc,platform=windows\artifacts\* protoc_plugins\windows_x64\
+xcopy /Y /I ..\..\architecture=x86,language=protoc,platform=linux\artifacts\* protoc_plugins\linux_x86\
+xcopy /Y /I ..\..\architecture=x64,language=protoc,platform=linux\artifacts\* protoc_plugins\linux_x64\
+xcopy /Y /I ..\..\architecture=x86,language=protoc,platform=macos\artifacts\* protoc_plugins\macosx_x86\
+xcopy /Y /I ..\..\architecture=x64,language=protoc,platform=macos\artifacts\* protoc_plugins\macosx_x64\
+
@rem Fetch all dependencies
%NUGET% restore ..\..\vsprojects\grpc_csharp_ext.sln || goto :error
%NUGET% restore Grpc.sln || goto :error
@@ -27,24 +35,19 @@ setlocal
@call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" x86
-@rem We won't use the native libraries from this step, but without this Grpc.sln will fail.
+@rem We won't use the native libraries from this step, but without this Grpc.sln will fail.
msbuild ..\..\vsprojects\grpc_csharp_ext.sln /p:Configuration=Release /p:PlatformToolset=v120 || goto :error
msbuild Grpc.sln /p:Configuration=ReleaseSigned || goto :error
endlocal
-@rem TODO(jtattermusch): re-enable protoc plugin building
-@rem @call ..\..\vsprojects\build_plugins.bat || goto :error
-
%NUGET% pack grpc.native.csharp\grpc.native.csharp.nuspec -Version %VERSION% || goto :error
%NUGET% pack Grpc.Auth\Grpc.Auth.nuspec -Symbols -Version %VERSION% || goto :error
%NUGET% pack Grpc.Core\Grpc.Core.nuspec -Symbols -Version %VERSION% || goto :error
%NUGET% pack Grpc.HealthCheck\Grpc.HealthCheck.nuspec -Symbols -Version %VERSION_WITH_BETA% -Properties ProtobufVersion=%PROTOBUF_VERSION% || goto :error
%NUGET% pack Grpc.nuspec -Version %VERSION% || goto :error
-
-@rem TODO(jtattermusch): re-enable building Grpc.Tools package
-@rem %NUGET% pack Grpc.Tools.nuspec -Version %VERSION% || goto :error
+%NUGET% pack Grpc.Tools.nuspec -Version %VERSION% || goto :error
@rem copy resulting nuget packages to artifacts directory
xcopy /Y /I *.nupkg ..\..\artifacts\
diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c
index 1df74a0993..8d769e5f6a 100644
--- a/src/csharp/ext/grpc_csharp_ext.c
+++ b/src/csharp/ext/grpc_csharp_ext.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015-2016, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
*
*/
-#include "src/core/support/string.h"
+#include "src/core/lib/support/string.h"
#include <grpc/byte_buffer_reader.h>
#include <grpc/support/port_platform.h>
diff --git a/src/csharp/generate_proto_csharp.sh b/src/csharp/generate_proto_csharp.sh
index 0261a458af..9ac770b79d 100755
--- a/src/csharp/generate_proto_csharp.sh
+++ b/src/csharp/generate_proto_csharp.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2015-2016, Google Inc.
+# Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -42,7 +42,7 @@ $PROTOC --plugin=$PLUGIN --csharp_out=$EXAMPLES_DIR --grpc_out=$EXAMPLES_DIR \
-I src/proto/math src/proto/math/math.proto
$PROTOC --plugin=$PLUGIN --csharp_out=$HEALTHCHECK_DIR --grpc_out=$HEALTHCHECK_DIR \
- -I src/proto/grpc/health/v1alpha src/proto/grpc/health/v1alpha/health.proto
+ -I src/proto/grpc/health/v1 src/proto/grpc/health/v1/health.proto
$PROTOC --plugin=$PLUGIN --csharp_out=$TESTING_DIR --grpc_out=$TESTING_DIR \
-I . src/proto/grpc/testing/{control,empty,messages,payloads,services,stats,test}.proto
diff --git a/src/csharp/grpc.native.csharp/grpc.native.csharp.nuspec b/src/csharp/grpc.native.csharp/grpc.native.csharp.nuspec
index 6a1795b709..cc688e2bc7 100644
--- a/src/csharp/grpc.native.csharp/grpc.native.csharp.nuspec
+++ b/src/csharp/grpc.native.csharp/grpc.native.csharp.nuspec
@@ -10,7 +10,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Native extension needed by gRPC C# library. This is not the package you are looking for, it is only meant to be used as a dependency.</description>
<releaseNotes>Release of gRPC C core $version$ libraries.</releaseNotes>
- <copyright>Copyright 2015-2016</copyright>
+ <copyright>Copyright 2015</copyright>
<title>gRPC C# Native Extension</title>
<summary>Native library required by gRPC C#</summary>
<tags>gRPC native</tags>
diff --git a/src/csharp/tests.json b/src/csharp/tests.json
index 4aa93668ad..718bfa3287 100644
--- a/src/csharp/tests.json
+++ b/src/csharp/tests.json
@@ -21,6 +21,7 @@
"Grpc.Core.Tests.CompressionTest",
"Grpc.Core.Tests.ContextPropagationTest",
"Grpc.Core.Tests.GrpcEnvironmentTest",
+ "Grpc.Core.Tests.HalfcloseTest",
"Grpc.Core.Tests.MarshallingErrorsTest",
"Grpc.Core.Tests.MetadataTest",
"Grpc.Core.Tests.NUnitVersionTest",
@@ -35,8 +36,9 @@
"Math.Tests.MathClientServerTest",
"Grpc.HealthCheck.Tests.HealthClientServerTest",
"Grpc.HealthCheck.Tests.HealthServiceImplTest",
- "Grpc.IntegrationTesting.HeaderInterceptorTest",
"Grpc.IntegrationTesting.HistogramTest",
+ "Grpc.IntegrationTesting.GeneratedClientTest",
+ "Grpc.IntegrationTesting.GeneratedServiceBaseTest",
"Grpc.IntegrationTesting.InteropClientServerTest",
"Grpc.IntegrationTesting.MetadataCredentialsTest",
"Grpc.IntegrationTesting.RunnerClientServerTest",