add servicename field to method

pull/2815/head
Jan Tattermusch 9 years ago
parent 542e21cbe0
commit a9ddd02dae
  1. 2
      src/compiler/csharp_generator.cc
  2. 39
      src/csharp/Grpc.Core.Tests/ClientServerTest.cs
  3. 15
      src/csharp/Grpc.Core.Tests/TimeoutsTest.cs
  4. 28
      src/csharp/Grpc.Core/Method.cs

@ -246,6 +246,8 @@ void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) {
out->Indent(); out->Indent();
out->Print("$methodtype$,\n", "methodtype", out->Print("$methodtype$,\n", "methodtype",
GetCSharpMethodType(GetMethodType(method))); GetCSharpMethodType(GetMethodType(method)));
out->Print("$servicenamefield$,\n", "servicenamefield",
GetServiceNameFieldName());
out->Print("\"$methodname$\",\n", "methodname", method->name()); out->Print("\"$methodname$\",\n", "methodname", method->name());
out->Print("$requestmarshaller$,\n", "requestmarshaller", out->Print("$requestmarshaller$,\n", "requestmarshaller",
GetMarshallerFieldName(method->input_type())); GetMarshallerFieldName(method->input_type()));

@ -50,19 +50,22 @@ namespace Grpc.Core.Tests
static readonly Method<string, string> EchoMethod = new Method<string, string>( static readonly Method<string, string> EchoMethod = new Method<string, string>(
MethodType.Unary, MethodType.Unary,
"/tests.Test/Echo", "tests.Test",
"Echo",
Marshallers.StringMarshaller, Marshallers.StringMarshaller,
Marshallers.StringMarshaller); Marshallers.StringMarshaller);
static readonly Method<string, string> ConcatAndEchoMethod = new Method<string, string>( static readonly Method<string, string> ConcatAndEchoMethod = new Method<string, string>(
MethodType.ClientStreaming, MethodType.ClientStreaming,
"/tests.Test/ConcatAndEcho", "tests.Test",
"ConcatAndEcho",
Marshallers.StringMarshaller, Marshallers.StringMarshaller,
Marshallers.StringMarshaller); Marshallers.StringMarshaller);
static readonly Method<string, string> NonexistentMethod = new Method<string, string>( static readonly Method<string, string> NonexistentMethod = new Method<string, string>(
MethodType.Unary, MethodType.Unary,
"/tests.Test/NonexistentMethod", "tests.Test",
"NonexistentMethod",
Marshallers.StringMarshaller, Marshallers.StringMarshaller,
Marshallers.StringMarshaller); Marshallers.StringMarshaller);
@ -102,14 +105,14 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void UnaryCall() public void UnaryCall()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
Assert.AreEqual("ABC", Calls.BlockingUnaryCall(internalCall, "ABC")); Assert.AreEqual("ABC", Calls.BlockingUnaryCall(internalCall, "ABC"));
} }
[Test] [Test]
public void UnaryCall_ServerHandlerThrows() public void UnaryCall_ServerHandlerThrows()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
try try
{ {
Calls.BlockingUnaryCall(internalCall, "THROW"); Calls.BlockingUnaryCall(internalCall, "THROW");
@ -124,7 +127,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void UnaryCall_ServerHandlerThrowsRpcException() public void UnaryCall_ServerHandlerThrowsRpcException()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
try try
{ {
Calls.BlockingUnaryCall(internalCall, "THROW_UNAUTHENTICATED"); Calls.BlockingUnaryCall(internalCall, "THROW_UNAUTHENTICATED");
@ -139,7 +142,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void UnaryCall_ServerHandlerSetsStatus() public void UnaryCall_ServerHandlerSetsStatus()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
try try
{ {
Calls.BlockingUnaryCall(internalCall, "SET_UNAUTHENTICATED"); Calls.BlockingUnaryCall(internalCall, "SET_UNAUTHENTICATED");
@ -154,7 +157,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public async Task AsyncUnaryCall() public async Task AsyncUnaryCall()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
var result = await Calls.AsyncUnaryCall(internalCall, "ABC"); var result = await Calls.AsyncUnaryCall(internalCall, "ABC");
Assert.AreEqual("ABC", result); Assert.AreEqual("ABC", result);
} }
@ -162,7 +165,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public async Task AsyncUnaryCall_ServerHandlerThrows() public async Task AsyncUnaryCall_ServerHandlerThrows()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
try try
{ {
await Calls.AsyncUnaryCall(internalCall, "THROW"); await Calls.AsyncUnaryCall(internalCall, "THROW");
@ -177,7 +180,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public async Task ClientStreamingCall() public async Task ClientStreamingCall()
{ {
var internalCall = new Call<string, string>(ServiceName, ConcatAndEchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, ConcatAndEchoMethod, new CallContext());
var call = Calls.AsyncClientStreamingCall(internalCall); var call = Calls.AsyncClientStreamingCall(internalCall);
await call.RequestStream.WriteAll(new string[] { "A", "B", "C" }); await call.RequestStream.WriteAll(new string[] { "A", "B", "C" });
@ -188,7 +191,7 @@ namespace Grpc.Core.Tests
public async Task ClientStreamingCall_CancelAfterBegin() public async Task ClientStreamingCall_CancelAfterBegin()
{ {
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
var internalCall = new Call<string, string>(ServiceName, ConcatAndEchoMethod, channel, new CallContext(cancellationToken: cts.Token)); var internalCall = new Call<string, string>(channel, ConcatAndEchoMethod, new CallContext(cancellationToken: cts.Token));
var call = Calls.AsyncClientStreamingCall(internalCall); var call = Calls.AsyncClientStreamingCall(internalCall);
// TODO(jtattermusch): we need this to ensure call has been initiated once we cancel it. // TODO(jtattermusch): we need this to ensure call has been initiated once we cancel it.
@ -213,7 +216,7 @@ namespace Grpc.Core.Tests
new Metadata.Entry("ascii-header", "abcdefg"), new Metadata.Entry("ascii-header", "abcdefg"),
new Metadata.Entry("binary-header-bin", new byte[] { 1, 2, 3, 0, 0xff }), new Metadata.Entry("binary-header-bin", new byte[] { 1, 2, 3, 0, 0xff }),
}; };
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext(headers: headers)); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext(headers: headers));
var call = Calls.AsyncUnaryCall(internalCall, "ABC"); var call = Calls.AsyncUnaryCall(internalCall, "ABC");
Assert.AreEqual("ABC", call.ResponseAsync.Result); Assert.AreEqual("ABC", call.ResponseAsync.Result);
@ -234,14 +237,14 @@ namespace Grpc.Core.Tests
{ {
channel.Dispose(); channel.Dispose();
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
Assert.Throws(typeof(ObjectDisposedException), () => Calls.BlockingUnaryCall(internalCall, "ABC")); Assert.Throws(typeof(ObjectDisposedException), () => Calls.BlockingUnaryCall(internalCall, "ABC"));
} }
[Test] [Test]
public void UnaryCallPerformance() public void UnaryCallPerformance()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
BenchmarkUtil.RunBenchmark(100, 100, BenchmarkUtil.RunBenchmark(100, 100,
() => { Calls.BlockingUnaryCall(internalCall, "ABC"); }); () => { Calls.BlockingUnaryCall(internalCall, "ABC"); });
} }
@ -249,7 +252,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void UnknownMethodHandler() public void UnknownMethodHandler()
{ {
var internalCall = new Call<string, string>(ServiceName, NonexistentMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, NonexistentMethod, new CallContext());
try try
{ {
Calls.BlockingUnaryCall(internalCall, "ABC"); Calls.BlockingUnaryCall(internalCall, "ABC");
@ -264,7 +267,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void UserAgentStringPresent() public void UserAgentStringPresent()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
string userAgent = Calls.BlockingUnaryCall(internalCall, "RETURN-USER-AGENT"); string userAgent = Calls.BlockingUnaryCall(internalCall, "RETURN-USER-AGENT");
Assert.IsTrue(userAgent.StartsWith("grpc-csharp/")); Assert.IsTrue(userAgent.StartsWith("grpc-csharp/"));
} }
@ -272,7 +275,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void PeerInfoPresent() public void PeerInfoPresent()
{ {
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
string peer = Calls.BlockingUnaryCall(internalCall, "RETURN-PEER"); string peer = Calls.BlockingUnaryCall(internalCall, "RETURN-PEER");
Assert.IsTrue(peer.Contains(Host)); Assert.IsTrue(peer.Contains(Host));
} }
@ -285,7 +288,7 @@ namespace Grpc.Core.Tests
var stateChangedTask = channel.WaitForStateChangedAsync(channel.State); var stateChangedTask = channel.WaitForStateChangedAsync(channel.State);
var internalCall = new Call<string, string>(ServiceName, EchoMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, EchoMethod, new CallContext());
await Calls.AsyncUnaryCall(internalCall, "abc"); await Calls.AsyncUnaryCall(internalCall, "abc");
await stateChangedTask; await stateChangedTask;

@ -53,7 +53,8 @@ namespace Grpc.Core.Tests
static readonly Method<string, string> TestMethod = new Method<string, string>( static readonly Method<string, string> TestMethod = new Method<string, string>(
MethodType.Unary, MethodType.Unary,
"/tests.Test/Test", "tests.Test",
"Test",
Marshallers.StringMarshaller, Marshallers.StringMarshaller,
Marshallers.StringMarshaller); Marshallers.StringMarshaller);
@ -98,11 +99,11 @@ namespace Grpc.Core.Tests
public void InfiniteDeadline() public void InfiniteDeadline()
{ {
// no deadline specified, check server sees infinite deadline // no deadline specified, check server sees infinite deadline
var internalCall = new Call<string, string>(ServiceName, TestMethod, channel, new CallContext()); var internalCall = new Call<string, string>(channel, TestMethod, new CallContext());
Assert.AreEqual("DATETIME_MAXVALUE", Calls.BlockingUnaryCall(internalCall, "RETURN_DEADLINE")); Assert.AreEqual("DATETIME_MAXVALUE", Calls.BlockingUnaryCall(internalCall, "RETURN_DEADLINE"));
// DateTime.MaxValue deadline specified, check server sees infinite deadline // DateTime.MaxValue deadline specified, check server sees infinite deadline
var internalCall2 = new Call<string, string>(ServiceName, TestMethod, channel, new CallContext()); var internalCall2 = new Call<string, string>(channel, TestMethod, new CallContext());
Assert.AreEqual("DATETIME_MAXVALUE", Calls.BlockingUnaryCall(internalCall2, "RETURN_DEADLINE")); Assert.AreEqual("DATETIME_MAXVALUE", Calls.BlockingUnaryCall(internalCall2, "RETURN_DEADLINE"));
} }
@ -112,7 +113,7 @@ namespace Grpc.Core.Tests
var remainingTimeClient = TimeSpan.FromDays(7); var remainingTimeClient = TimeSpan.FromDays(7);
var deadline = DateTime.UtcNow + remainingTimeClient; var deadline = DateTime.UtcNow + remainingTimeClient;
Thread.Sleep(1000); Thread.Sleep(1000);
var internalCall = new Call<string, string>(ServiceName, TestMethod, channel, new CallContext(deadline: deadline)); var internalCall = new Call<string, string>(channel, TestMethod, new CallContext(deadline: deadline));
var serverDeadlineTicksString = Calls.BlockingUnaryCall(internalCall, "RETURN_DEADLINE"); var serverDeadlineTicksString = Calls.BlockingUnaryCall(internalCall, "RETURN_DEADLINE");
var serverDeadline = new DateTime(long.Parse(serverDeadlineTicksString), DateTimeKind.Utc); var serverDeadline = new DateTime(long.Parse(serverDeadlineTicksString), DateTimeKind.Utc);
@ -126,7 +127,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void DeadlineInThePast() public void DeadlineInThePast()
{ {
var internalCall = new Call<string, string>(ServiceName, TestMethod, channel, new CallContext(deadline: DateTime.MinValue)); var internalCall = new Call<string, string>(channel, TestMethod, new CallContext(deadline: DateTime.MinValue));
try try
{ {
@ -144,7 +145,7 @@ namespace Grpc.Core.Tests
public void DeadlineExceededStatusOnTimeout() public void DeadlineExceededStatusOnTimeout()
{ {
var deadline = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5)); var deadline = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5));
var internalCall = new Call<string, string>(ServiceName, TestMethod, channel, new CallContext(deadline: deadline)); var internalCall = new Call<string, string>(channel, TestMethod, new CallContext(deadline: deadline));
try try
{ {
@ -162,7 +163,7 @@ namespace Grpc.Core.Tests
public void ServerReceivesCancellationOnTimeout() public void ServerReceivesCancellationOnTimeout()
{ {
var deadline = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5)); var deadline = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5));
var internalCall = new Call<string, string>(ServiceName, TestMethod, channel, new CallContext(deadline: deadline)); var internalCall = new Call<string, string>(channel, TestMethod, new CallContext(deadline: deadline));
try try
{ {

@ -53,16 +53,20 @@ namespace Grpc.Core
public class Method<TRequest, TResponse> public class Method<TRequest, TResponse>
{ {
readonly MethodType type; readonly MethodType type;
readonly string serviceName;
readonly string name; readonly string name;
readonly Marshaller<TRequest> requestMarshaller; readonly Marshaller<TRequest> requestMarshaller;
readonly Marshaller<TResponse> responseMarshaller; readonly Marshaller<TResponse> responseMarshaller;
readonly string fullName;
public Method(MethodType type, string name, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller) public Method(MethodType type, string serviceName, string name, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller)
{ {
this.type = type; this.type = type;
this.name = name; this.serviceName = Preconditions.CheckNotNull(serviceName);
this.requestMarshaller = requestMarshaller; this.name = Preconditions.CheckNotNull(name);
this.responseMarshaller = responseMarshaller; this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller);
this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller);
this.fullName = GetFullName(serviceName);
} }
public MethodType Type public MethodType Type
@ -73,6 +77,14 @@ namespace Grpc.Core
} }
} }
public string ServiceName
{
get
{
return this.serviceName;
}
}
public string Name public string Name
{ {
get get
@ -97,6 +109,14 @@ namespace Grpc.Core
} }
} }
public string FullName
{
get
{
return this.fullName;
}
}
/// <summary> /// <summary>
/// Gets full name of the method including the service name. /// Gets full name of the method including the service name.
/// </summary> /// </summary>

Loading…
Cancel
Save