mirror of https://github.com/grpc/grpc.git
commit
74f4f0bb4b
188 changed files with 4285 additions and 1530 deletions
@ -0,0 +1,70 @@ |
||||
GRPC Health Checking Protocol |
||||
================================ |
||||
|
||||
Health checks are used to probe whether the server is able to handle rpcs. The |
||||
client-to-server health checking can happen from point to point or via some |
||||
control system. A server may choose to reply “unhealthy” because it |
||||
is not ready to take requests, it is shutting down or some other reason. |
||||
The client can act accordingly if the response is not received within some time |
||||
window or the response says unhealthy in it. |
||||
|
||||
|
||||
A GRPC service is used as the health checking mechanism for both simple |
||||
client-to-server scenario and other control systems such as load-balancing. |
||||
Being a high |
||||
level service provides some benefits. Firstly, since it is a GRPC service |
||||
itself, doing a health check is in the same format as a normal rpc. Secondly, |
||||
it has rich semantics such as per-service health status. Thirdly, as a GRPC |
||||
service, it is able reuse all the existing billing, quota infrastructure, etc, |
||||
and thus the server has full control over the access of the health checking |
||||
service. |
||||
|
||||
## Service Definition |
||||
|
||||
The server should export a service defined in the following proto: |
||||
|
||||
``` |
||||
syntax = "proto3"; |
||||
|
||||
package grpc.health.v1alpha; |
||||
|
||||
message HealthCheckRequest { |
||||
string service = 1; |
||||
} |
||||
|
||||
message HealthCheckResponse { |
||||
enum ServingStatus { |
||||
UNKNOWN = 0; |
||||
SERVING = 1; |
||||
NOT_SERVING = 2; |
||||
} |
||||
ServingStatus status = 1; |
||||
} |
||||
|
||||
service Health { |
||||
rpc Check(HealthCheckRequest) returns (HealthCheckResponse); |
||||
} |
||||
``` |
||||
|
||||
A client can query the server’s health status by calling the `Check` method, and |
||||
a deadline should be set on the rpc. The client can optionally set the service |
||||
name it wants to query for health status. The suggested format of service name |
||||
is `package_names.ServiceName`, such as `grpc.health.v1alpha.Health`. |
||||
|
||||
The server should register all the services manually and set |
||||
the individual status, including an empty service name and its status. For each |
||||
request received, if the service name can be found in the registry, |
||||
a response must be sent back with an `OK` status and the status field should be |
||||
set to `SERVING` or `NOT_SERVING` accordingly. If the service name is not |
||||
registered, the server returns a `NOT_FOUND` GRPC status. |
||||
|
||||
The server should use an empty string as the key for server’s |
||||
overall health status, so that a client not interested in a specific service can |
||||
query the server's status with an empty request. The server can just do exact |
||||
matching of the service name without support of any kind of wildcard matching. |
||||
However, the service owner has the freedom to implement more complicated |
||||
matching semantics that both the client and server agree upon. |
||||
|
||||
A client can declare the server as unhealthy if the rpc is not finished after |
||||
some amount of time. The client should be able to handle the case where server |
||||
does not have the Health service. |
@ -1,125 +0,0 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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.Security.Cryptography; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
|
||||
using Google.Apis.Auth.OAuth2; |
||||
using Google.Apis.Auth.OAuth2.Responses; |
||||
using Newtonsoft.Json.Linq; |
||||
using Org.BouncyCastle.Crypto.Parameters; |
||||
using Org.BouncyCastle.Security; |
||||
|
||||
namespace Grpc.Auth |
||||
{ |
||||
// TODO(jtattermusch): Remove this class once possible. |
||||
/// <summary> |
||||
/// A temporary placeholder for Google credential from |
||||
/// Google Auth library for .NET. It emulates the usage pattern |
||||
/// for Usable auth. |
||||
/// </summary> |
||||
public class GoogleCredential |
||||
{ |
||||
private const string GoogleApplicationCredentialsEnvName = "GOOGLE_APPLICATION_CREDENTIALS"; |
||||
private const string ClientEmailFieldName = "client_email"; |
||||
private const string PrivateKeyFieldName = "private_key"; |
||||
|
||||
private ServiceCredential credential; |
||||
|
||||
private GoogleCredential(ServiceCredential credential) |
||||
{ |
||||
this.credential = credential; |
||||
} |
||||
|
||||
public static GoogleCredential GetApplicationDefault() |
||||
{ |
||||
return new GoogleCredential(null); |
||||
} |
||||
|
||||
public bool IsCreateScopedRequired |
||||
{ |
||||
get |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public GoogleCredential CreateScoped(IEnumerable<string> scopes) |
||||
{ |
||||
var credsPath = Environment.GetEnvironmentVariable(GoogleApplicationCredentialsEnvName); |
||||
if (credsPath == null) |
||||
{ |
||||
// Default to ComputeCredentials if path to JSON key is not set. |
||||
// ComputeCredential is not scoped actually, but for our use case it's |
||||
// fine to treat is as such. |
||||
return new GoogleCredential(new ComputeCredential(new ComputeCredential.Initializer())); |
||||
} |
||||
|
||||
JObject jsonCredentialParameters = JObject.Parse(File.ReadAllText(credsPath)); |
||||
string clientEmail = jsonCredentialParameters.GetValue(ClientEmailFieldName).Value<string>(); |
||||
string privateKeyString = jsonCredentialParameters.GetValue(PrivateKeyFieldName).Value<string>(); |
||||
|
||||
var serviceCredential = new ServiceAccountCredential( |
||||
new ServiceAccountCredential.Initializer(clientEmail) |
||||
{ |
||||
Scopes = scopes, |
||||
}.FromPrivateKey(privateKeyString)); |
||||
return new GoogleCredential(serviceCredential); |
||||
} |
||||
|
||||
public Task<bool> RequestAccessTokenAsync(CancellationToken taskCancellationToken) |
||||
{ |
||||
return credential.RequestAccessTokenAsync(taskCancellationToken); |
||||
} |
||||
|
||||
public TokenResponse Token |
||||
{ |
||||
get |
||||
{ |
||||
return credential.Token; |
||||
} |
||||
} |
||||
|
||||
internal ServiceCredential InternalCredential |
||||
{ |
||||
get |
||||
{ |
||||
return credential; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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 Grpc.Core; |
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Grpc.Core.Tests |
||||
{ |
||||
public class ClientBaseTest |
||||
{ |
||||
[Test] |
||||
public void GetAuthUriBase_Valid() |
||||
{ |
||||
Assert.AreEqual("https://some.googleapi.com/", ClientBase.GetAuthUriBase("some.googleapi.com")); |
||||
Assert.AreEqual("https://some.googleapi.com/", ClientBase.GetAuthUriBase("dns:///some.googleapi.com/")); |
||||
Assert.AreEqual("https://some.googleapi.com/", ClientBase.GetAuthUriBase("dns:///some.googleapi.com:443/")); |
||||
Assert.AreEqual("https://some.googleapi.com/", ClientBase.GetAuthUriBase("some.googleapi.com:443/")); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetAuthUriBase_Invalid() |
||||
{ |
||||
Assert.IsNull(ClientBase.GetAuthUriBase("some.googleapi.com:")); |
||||
Assert.IsNull(ClientBase.GetAuthUriBase("https://some.googleapi.com/")); |
||||
Assert.IsNull(ClientBase.GetAuthUriBase("dns://some.googleapi.com:443")); // just two slashes |
||||
Assert.IsNull(ClientBase.GetAuthUriBase("")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,128 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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.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 CompressionTest |
||||
{ |
||||
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.Dispose(); |
||||
server.ShutdownAsync().Wait(); |
||||
} |
||||
|
||||
[TestFixtureTearDown] |
||||
public void CleanupClass() |
||||
{ |
||||
GrpcEnvironment.Shutdown(); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteOptions_Unary() |
||||
{ |
||||
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
context.WriteOptions = new WriteOptions(WriteFlags.NoCompress); |
||||
return request; |
||||
}); |
||||
|
||||
var callOptions = new CallOptions(writeOptions: new WriteOptions(WriteFlags.NoCompress)); |
||||
Calls.BlockingUnaryCall(helper.CreateUnaryCall(callOptions), "abc"); |
||||
} |
||||
|
||||
[Test] |
||||
public async Task WriteOptions_DuplexStreaming() |
||||
{ |
||||
helper.DuplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) => |
||||
{ |
||||
await requestStream.ToListAsync(); |
||||
|
||||
context.WriteOptions = new WriteOptions(WriteFlags.NoCompress); |
||||
|
||||
await context.WriteResponseHeadersAsync(new Metadata { { "ascii-header", "abcdefg" } }); |
||||
|
||||
await responseStream.WriteAsync("X"); |
||||
|
||||
responseStream.WriteOptions = null; |
||||
await responseStream.WriteAsync("Y"); |
||||
|
||||
responseStream.WriteOptions = new WriteOptions(WriteFlags.NoCompress); |
||||
await responseStream.WriteAsync("Z"); |
||||
}); |
||||
|
||||
var callOptions = new CallOptions(writeOptions: new WriteOptions(WriteFlags.NoCompress)); |
||||
var call = Calls.AsyncDuplexStreamingCall(helper.CreateDuplexStreamingCall(callOptions)); |
||||
|
||||
// check that write options from call options are propagated to request stream. |
||||
Assert.IsTrue((call.RequestStream.WriteOptions.Flags & WriteFlags.NoCompress) != 0); |
||||
|
||||
call.RequestStream.WriteOptions = new WriteOptions(); |
||||
await call.RequestStream.WriteAsync("A"); |
||||
|
||||
call.RequestStream.WriteOptions = null; |
||||
await call.RequestStream.WriteAsync("B"); |
||||
|
||||
call.RequestStream.WriteOptions = new WriteOptions(WriteFlags.NoCompress); |
||||
await call.RequestStream.WriteAsync("C"); |
||||
|
||||
await call.RequestStream.CompleteAsync(); |
||||
|
||||
await call.ResponseStream.ToListAsync(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,153 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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.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 ContextPropagationTest |
||||
{ |
||||
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.Dispose(); |
||||
server.ShutdownAsync().Wait(); |
||||
} |
||||
|
||||
[TestFixtureTearDown] |
||||
public void CleanupClass() |
||||
{ |
||||
GrpcEnvironment.Shutdown(); |
||||
} |
||||
|
||||
[Test] |
||||
public async Task PropagateCancellation() |
||||
{ |
||||
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
// check that we didn't obtain the default cancellation token. |
||||
Assert.IsTrue(context.CancellationToken.CanBeCanceled); |
||||
return "PASS"; |
||||
}); |
||||
|
||||
helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) => |
||||
{ |
||||
var propagationToken = context.CreatePropagationToken(); |
||||
Assert.IsNotNull(propagationToken.ParentCall); |
||||
|
||||
var callOptions = new CallOptions(propagationToken: propagationToken); |
||||
return await Calls.AsyncUnaryCall(helper.CreateUnaryCall(callOptions), "xyz"); |
||||
}); |
||||
|
||||
var cts = new CancellationTokenSource(); |
||||
var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall(new CallOptions(cancellationToken: cts.Token))); |
||||
await call.RequestStream.CompleteAsync(); |
||||
Assert.AreEqual("PASS", await call); |
||||
} |
||||
|
||||
[Test] |
||||
public async Task PropagateDeadline() |
||||
{ |
||||
var deadline = DateTime.UtcNow.AddDays(7); |
||||
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
Assert.IsTrue(context.Deadline < deadline.AddMinutes(1)); |
||||
Assert.IsTrue(context.Deadline > deadline.AddMinutes(-1)); |
||||
return "PASS"; |
||||
}); |
||||
|
||||
helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) => |
||||
{ |
||||
Assert.Throws(typeof(ArgumentException), () => |
||||
{ |
||||
// Trying to override deadline while propagating deadline from parent call will throw. |
||||
Calls.BlockingUnaryCall(helper.CreateUnaryCall( |
||||
new CallOptions(deadline: DateTime.UtcNow.AddDays(8), |
||||
propagationToken: context.CreatePropagationToken())), ""); |
||||
}); |
||||
|
||||
var callOptions = new CallOptions(propagationToken: context.CreatePropagationToken()); |
||||
return await Calls.AsyncUnaryCall(helper.CreateUnaryCall(callOptions), "xyz"); |
||||
}); |
||||
|
||||
var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall(new CallOptions(deadline: deadline))); |
||||
await call.RequestStream.CompleteAsync(); |
||||
Assert.AreEqual("PASS", await call); |
||||
} |
||||
|
||||
[Test] |
||||
public async Task SuppressDeadlinePropagation() |
||||
{ |
||||
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
Assert.AreEqual(DateTime.MaxValue, context.Deadline); |
||||
return "PASS"; |
||||
}); |
||||
|
||||
helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) => |
||||
{ |
||||
Assert.IsTrue(context.CancellationToken.CanBeCanceled); |
||||
|
||||
var callOptions = new CallOptions(propagationToken: context.CreatePropagationToken(new ContextPropagationOptions(propagateDeadline: false))); |
||||
return await Calls.AsyncUnaryCall(helper.CreateUnaryCall(callOptions), "xyz"); |
||||
}); |
||||
|
||||
var cts = new CancellationTokenSource(); |
||||
var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall(new CallOptions(deadline: DateTime.UtcNow.AddDays(7)))); |
||||
await call.RequestStream.CompleteAsync(); |
||||
Assert.AreEqual("PASS", await call); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,244 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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.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 |
||||
{ |
||||
/// <summary> |
||||
/// Allows setting up a mock service in the client-server tests easily. |
||||
/// </summary> |
||||
public class MockServiceHelper |
||||
{ |
||||
public const string ServiceName = "tests.Test"; |
||||
|
||||
public static readonly Method<string, string> UnaryMethod = new Method<string, string>( |
||||
MethodType.Unary, |
||||
ServiceName, |
||||
"Unary", |
||||
Marshallers.StringMarshaller, |
||||
Marshallers.StringMarshaller); |
||||
|
||||
public static readonly Method<string, string> ClientStreamingMethod = new Method<string, string>( |
||||
MethodType.ClientStreaming, |
||||
ServiceName, |
||||
"ClientStreaming", |
||||
Marshallers.StringMarshaller, |
||||
Marshallers.StringMarshaller); |
||||
|
||||
public static readonly Method<string, string> ServerStreamingMethod = new Method<string, string>( |
||||
MethodType.ServerStreaming, |
||||
ServiceName, |
||||
"ServerStreaming", |
||||
Marshallers.StringMarshaller, |
||||
Marshallers.StringMarshaller); |
||||
|
||||
public static readonly Method<string, string> DuplexStreamingMethod = new Method<string, string>( |
||||
MethodType.DuplexStreaming, |
||||
ServiceName, |
||||
"DuplexStreaming", |
||||
Marshallers.StringMarshaller, |
||||
Marshallers.StringMarshaller); |
||||
|
||||
readonly string host; |
||||
readonly ServerServiceDefinition serviceDefinition; |
||||
|
||||
UnaryServerMethod<string, string> unaryHandler; |
||||
ClientStreamingServerMethod<string, string> clientStreamingHandler; |
||||
ServerStreamingServerMethod<string, string> serverStreamingHandler; |
||||
DuplexStreamingServerMethod<string, string> duplexStreamingHandler; |
||||
|
||||
Server server; |
||||
Channel channel; |
||||
|
||||
public MockServiceHelper(string host = null) |
||||
{ |
||||
this.host = host ?? "localhost"; |
||||
|
||||
serviceDefinition = ServerServiceDefinition.CreateBuilder(ServiceName) |
||||
.AddMethod(UnaryMethod, (request, context) => unaryHandler(request, context)) |
||||
.AddMethod(ClientStreamingMethod, (requestStream, context) => clientStreamingHandler(requestStream, context)) |
||||
.AddMethod(ServerStreamingMethod, (request, responseStream, context) => serverStreamingHandler(request, responseStream, context)) |
||||
.AddMethod(DuplexStreamingMethod, (requestStream, responseStream, context) => duplexStreamingHandler(requestStream, responseStream, context)) |
||||
.Build(); |
||||
|
||||
var defaultStatus = new Status(StatusCode.Unknown, "Default mock implementation. Please provide your own."); |
||||
|
||||
unaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
context.Status = defaultStatus; |
||||
return ""; |
||||
}); |
||||
|
||||
clientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) => |
||||
{ |
||||
context.Status = defaultStatus; |
||||
return ""; |
||||
}); |
||||
|
||||
serverStreamingHandler = new ServerStreamingServerMethod<string, string>(async (request, responseStream, context) => |
||||
{ |
||||
context.Status = defaultStatus; |
||||
}); |
||||
|
||||
duplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) => |
||||
{ |
||||
context.Status = defaultStatus; |
||||
}); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns the default server for this service and creates one if not yet created. |
||||
/// </summary> |
||||
public Server GetServer() |
||||
{ |
||||
if (server == null) |
||||
{ |
||||
server = new Server |
||||
{ |
||||
Services = { serviceDefinition }, |
||||
Ports = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } } |
||||
}; |
||||
} |
||||
return server; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns the default channel for this service and creates one if not yet created. |
||||
/// </summary> |
||||
public Channel GetChannel() |
||||
{ |
||||
if (channel == null) |
||||
{ |
||||
channel = new Channel(Host, GetServer().Ports.Single().BoundPort, Credentials.Insecure); |
||||
} |
||||
return channel; |
||||
} |
||||
|
||||
public CallInvocationDetails<string, string> CreateUnaryCall(CallOptions options = default(CallOptions)) |
||||
{ |
||||
return new CallInvocationDetails<string, string>(channel, UnaryMethod, options); |
||||
} |
||||
|
||||
public CallInvocationDetails<string, string> CreateClientStreamingCall(CallOptions options = default(CallOptions)) |
||||
{ |
||||
return new CallInvocationDetails<string, string>(channel, ClientStreamingMethod, options); |
||||
} |
||||
|
||||
public CallInvocationDetails<string, string> CreateServerStreamingCall(CallOptions options = default(CallOptions)) |
||||
{ |
||||
return new CallInvocationDetails<string, string>(channel, ServerStreamingMethod, options); |
||||
} |
||||
|
||||
public CallInvocationDetails<string, string> CreateDuplexStreamingCall(CallOptions options = default(CallOptions)) |
||||
{ |
||||
return new CallInvocationDetails<string, string>(channel, DuplexStreamingMethod, options); |
||||
} |
||||
|
||||
public string Host |
||||
{ |
||||
get |
||||
{ |
||||
return this.host; |
||||
} |
||||
} |
||||
|
||||
public ServerServiceDefinition ServiceDefinition |
||||
{ |
||||
get |
||||
{ |
||||
return this.serviceDefinition; |
||||
} |
||||
} |
||||
|
||||
public UnaryServerMethod<string, string> UnaryHandler |
||||
{ |
||||
get |
||||
{ |
||||
return this.unaryHandler; |
||||
} |
||||
|
||||
set |
||||
{ |
||||
unaryHandler = value; |
||||
} |
||||
} |
||||
|
||||
public ClientStreamingServerMethod<string, string> ClientStreamingHandler |
||||
{ |
||||
get |
||||
{ |
||||
return this.clientStreamingHandler; |
||||
} |
||||
|
||||
set |
||||
{ |
||||
clientStreamingHandler = value; |
||||
} |
||||
} |
||||
|
||||
public ServerStreamingServerMethod<string, string> ServerStreamingHandler |
||||
{ |
||||
get |
||||
{ |
||||
return this.serverStreamingHandler; |
||||
} |
||||
|
||||
set |
||||
{ |
||||
serverStreamingHandler = value; |
||||
} |
||||
} |
||||
|
||||
public DuplexStreamingServerMethod<string, string> DuplexStreamingHandler |
||||
{ |
||||
get |
||||
{ |
||||
return this.duplexStreamingHandler; |
||||
} |
||||
|
||||
set |
||||
{ |
||||
duplexStreamingHandler = value; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,136 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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.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 |
||||
{ |
||||
/// <summary> |
||||
/// Tests for response headers support. |
||||
/// </summary> |
||||
public class ResponseHeadersTest |
||||
{ |
||||
MockServiceHelper helper; |
||||
Server server; |
||||
Channel channel; |
||||
|
||||
Metadata headers; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
helper = new MockServiceHelper(); |
||||
|
||||
server = helper.GetServer(); |
||||
server.Start(); |
||||
channel = helper.GetChannel(); |
||||
|
||||
headers = new Metadata { { "ascii-header", "abcdefg" } }; |
||||
} |
||||
|
||||
[TearDown] |
||||
public void Cleanup() |
||||
{ |
||||
channel.Dispose(); |
||||
server.ShutdownAsync().Wait(); |
||||
} |
||||
|
||||
[TestFixtureTearDown] |
||||
public void CleanupClass() |
||||
{ |
||||
GrpcEnvironment.Shutdown(); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteResponseHeaders_NullNotAllowed() |
||||
{ |
||||
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
Assert.Throws(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null)); |
||||
return "PASS"; |
||||
}); |
||||
|
||||
Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "")); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteResponseHeaders_AllowedOnlyOnce() |
||||
{ |
||||
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => |
||||
{ |
||||
await context.WriteResponseHeadersAsync(headers); |
||||
try |
||||
{ |
||||
await context.WriteResponseHeadersAsync(headers); |
||||
Assert.Fail(); |
||||
} |
||||
catch (InvalidOperationException expected) |
||||
{ |
||||
} |
||||
return "PASS"; |
||||
}); |
||||
|
||||
Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "")); |
||||
} |
||||
|
||||
[Test] |
||||
public async Task WriteResponseHeaders_NotAllowedAfterWrite() |
||||
{ |
||||
helper.ServerStreamingHandler = new ServerStreamingServerMethod<string, string>(async (request, responseStream, context) => |
||||
{ |
||||
await responseStream.WriteAsync("A"); |
||||
try |
||||
{ |
||||
await context.WriteResponseHeadersAsync(headers); |
||||
Assert.Fail(); |
||||
} |
||||
catch (InvalidOperationException expected) |
||||
{ |
||||
} |
||||
await responseStream.WriteAsync("B"); |
||||
}); |
||||
|
||||
var call = Calls.AsyncServerStreamingCall(helper.CreateServerStreamingCall(), ""); |
||||
var responses = await call.ResponseStream.ToListAsync(); |
||||
CollectionAssert.AreEqual(new[] { "A", "B" }, responses); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,171 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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; |
||||
|
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
|
||||
namespace Grpc.Core |
||||
{ |
||||
/// <summary> |
||||
/// Token for propagating context of server side handlers to child calls. |
||||
/// In situations when a backend is making calls to another backend, |
||||
/// it makes sense to propagate properties like deadline and cancellation |
||||
/// token of the server call to the child call. |
||||
/// C core provides some other contexts (like tracing context) that |
||||
/// are not accessible to C# layer, but this token still allows propagating them. |
||||
/// </summary> |
||||
public class ContextPropagationToken |
||||
{ |
||||
/// <summary> |
||||
/// Default propagation mask used by C core. |
||||
/// </summary> |
||||
private const ContextPropagationFlags DefaultCoreMask = (ContextPropagationFlags)0xffff; |
||||
|
||||
/// <summary> |
||||
/// Default propagation mask used by C# - we want to propagate deadline |
||||
/// and cancellation token by our own means. |
||||
/// </summary> |
||||
internal const ContextPropagationFlags DefaultMask = DefaultCoreMask |
||||
& ~ContextPropagationFlags.Deadline & ~ContextPropagationFlags.Cancellation; |
||||
|
||||
readonly CallSafeHandle parentCall; |
||||
readonly DateTime deadline; |
||||
readonly CancellationToken cancellationToken; |
||||
readonly ContextPropagationOptions options; |
||||
|
||||
internal ContextPropagationToken(CallSafeHandle parentCall, DateTime deadline, CancellationToken cancellationToken, ContextPropagationOptions options) |
||||
{ |
||||
this.parentCall = Preconditions.CheckNotNull(parentCall); |
||||
this.deadline = deadline; |
||||
this.cancellationToken = cancellationToken; |
||||
this.options = options ?? ContextPropagationOptions.Default; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Gets the native handle of the parent call. |
||||
/// </summary> |
||||
internal CallSafeHandle ParentCall |
||||
{ |
||||
get |
||||
{ |
||||
return this.parentCall; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Gets the parent call's deadline. |
||||
/// </summary> |
||||
internal DateTime ParentDeadline |
||||
{ |
||||
get |
||||
{ |
||||
return this.deadline; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Gets the parent call's cancellation token. |
||||
/// </summary> |
||||
internal CancellationToken ParentCancellationToken |
||||
{ |
||||
get |
||||
{ |
||||
return this.cancellationToken; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Get the context propagation options. |
||||
/// </summary> |
||||
internal ContextPropagationOptions Options |
||||
{ |
||||
get |
||||
{ |
||||
return this.options; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Options for <see cref="ContextPropagationToken"/>. |
||||
/// </summary> |
||||
public class ContextPropagationOptions |
||||
{ |
||||
/// <summary> |
||||
/// The context propagation options that will be used by default. |
||||
/// </summary> |
||||
public static readonly ContextPropagationOptions Default = new ContextPropagationOptions(); |
||||
|
||||
bool propagateDeadline; |
||||
bool propagateCancellation; |
||||
|
||||
|
||||
/// <summary> |
||||
/// Creates new context propagation options. |
||||
/// </summary> |
||||
/// <param name="propagateDeadline">If set to <c>true</c> parent call's deadline will be propagated to the child call.</param> |
||||
/// <param name="propagateCancellation">If set to <c>true</c> parent call's cancellation token will be propagated to the child call.</param> |
||||
public ContextPropagationOptions(bool propagateDeadline = true, bool propagateCancellation = true) |
||||
{ |
||||
this.propagateDeadline = propagateDeadline; |
||||
this.propagateCancellation = propagateCancellation; |
||||
} |
||||
|
||||
/// <value><c>true</c> if parent call's deadline should be propagated to the child call.</value> |
||||
public bool IsPropagateDeadline |
||||
{ |
||||
get { return this.propagateDeadline; } |
||||
} |
||||
|
||||
/// <value><c>true</c> if parent call's cancellation token should be propagated to the child call.</value> |
||||
public bool IsPropagateCancellation |
||||
{ |
||||
get { return this.propagateCancellation; } |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Context propagation flags from grpc/grpc.h. |
||||
/// </summary> |
||||
[Flags] |
||||
internal enum ContextPropagationFlags |
||||
{ |
||||
Deadline = 1, |
||||
CensusStatsContext = 2, |
||||
CensusTracingContext = 4, |
||||
Cancellation = 8 |
||||
} |
||||
} |
@ -1,5 +1,37 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// The current version of gRPC C#. |
||||
[assembly: AssemblyVersion(Grpc.Core.VersionInfo.CurrentVersion + ".*")] |
||||
[assembly: AssemblyVersion(Grpc.Core.VersionInfo.CurrentVersion + ".0")] |
||||
|
@ -1,13 +1,46 @@ |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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 |
||||
|
||||
namespace Grpc.Core |
||||
{ |
||||
/// <summary> |
||||
/// Provides info about current version of gRPC. |
||||
/// </summary> |
||||
public static class VersionInfo |
||||
{ |
||||
/// <summary> |
||||
/// Current version of gRPC |
||||
/// </summary> |
||||
public const string CurrentVersion = "0.6.0"; |
||||
public const string CurrentVersion = "0.6.1"; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,82 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, 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 |
||||
{ |
||||
/// <summary> |
||||
/// Flags for write operations. |
||||
/// </summary> |
||||
[Flags] |
||||
public enum WriteFlags |
||||
{ |
||||
/// <summary> |
||||
/// Hint that the write may be buffered and need not go out on the wire immediately. |
||||
/// gRPC is free to buffer the message until the next non-buffered |
||||
/// write, or until write stream completion, but it need not buffer completely or at all. |
||||
/// </summary> |
||||
BufferHint = 0x1, |
||||
|
||||
/// <summary> |
||||
/// Force compression to be disabled for a particular write. |
||||
/// </summary> |
||||
NoCompress = 0x2 |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Options for write operations. |
||||
/// </summary> |
||||
public class WriteOptions |
||||
{ |
||||
/// <summary> |
||||
/// Default write options. |
||||
/// </summary> |
||||
public static readonly WriteOptions Default = new WriteOptions(); |
||||
|
||||
private WriteFlags flags; |
||||
|
||||
public WriteOptions(WriteFlags flags = default(WriteFlags)) |
||||
{ |
||||
this.flags = flags; |
||||
} |
||||
|
||||
public WriteFlags Flags |
||||
{ |
||||
get |
||||
{ |
||||
return this.flags; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,2 @@ |
||||
|
||||
SandCastle project files to generate HTML reference documentation. |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue