adjust C# generator to match the new API

pull/2459/head
Jan Tattermusch 10 years ago
parent e5c9b80566
commit b533281e8e
  1. 28
      src/compiler/csharp_generator.cc
  2. 10
      src/csharp/Grpc.Core.Tests/Internal/MetadataArraySafeHandleTest.cs
  3. 11
      src/csharp/Grpc.Core/ClientBase.cs
  4. 10
      src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs
  5. 18
      src/csharp/Grpc.Examples/MathGrpc.cs
  6. 2
      src/csharp/Grpc.HealthCheck.Tests/HealthClientServerTest.cs
  7. 18
      src/csharp/Grpc.HealthCheck/HealthGrpc.cs
  8. 5
      src/csharp/Grpc.IntegrationTesting/InteropClient.cs
  9. 2
      src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
  10. 18
      src/csharp/Grpc.IntegrationTesting/TestGrpc.cs
  11. 9
      src/csharp/generate_proto_csharp.sh

@ -257,7 +257,7 @@ void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) {
}
void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) {
out->Print("// client-side stub interface\n");
out->Print("// client interface\n");
out->Print("public interface $name$\n", "name",
GetClientInterfaceName(service));
out->Print("{\n");
@ -312,7 +312,7 @@ void GenerateServerInterface(Printer* out, const ServiceDescriptor *service) {
void GenerateClientStub(Printer* out, const ServiceDescriptor *service) {
out->Print("// client stub\n");
out->Print(
"public class $name$ : AbstractStub<$name$, StubConfiguration>, $interface$\n",
"public class $name$ : ClientBase, $interface$\n",
"name", GetClientClassName(service), "interface",
GetClientInterfaceName(service));
out->Print("{\n");
@ -320,12 +320,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor *service) {
// constructors
out->Print(
"public $name$(Channel channel) : this(channel, StubConfiguration.Default)\n",
"name", GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
out->Print(
"public $name$(Channel channel, StubConfiguration config) : base(channel, config)\n",
"public $name$(Channel channel) : base(channel)\n",
"name", GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
@ -423,9 +418,9 @@ void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor *service) {
}
void GenerateNewStubMethods(Printer* out, const ServiceDescriptor *service) {
out->Print("// creates a new client stub\n");
out->Print("public static $interface$ NewStub(Channel channel)\n",
"interface", GetClientInterfaceName(service));
out->Print("// creates a new client\n");
out->Print("public static $classname$ NewClient(Channel channel)\n",
"classname", GetClientClassName(service));
out->Print("{\n");
out->Indent();
out->Print("return new $classname$(channel);\n", "classname",
@ -433,17 +428,6 @@ void GenerateNewStubMethods(Printer* out, const ServiceDescriptor *service) {
out->Outdent();
out->Print("}\n");
out->Print("\n");
out->Print("// creates a new client stub\n");
out->Print(
"public static $interface$ NewStub(Channel channel, StubConfiguration config)\n",
"interface", GetClientInterfaceName(service));
out->Print("{\n");
out->Indent();
out->Print("return new $classname$(channel, config);\n", "classname",
GetClientClassName(service));
out->Outdent();
out->Print("}\n");
}
void GenerateService(Printer* out, const ServiceDescriptor *service) {

@ -44,17 +44,17 @@ namespace Grpc.Core.Internal.Tests
[Test]
public void CreateEmptyAndDestroy()
{
var metadata = Metadata.CreateBuilder().Build();
var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
var nativeMetadata = MetadataArraySafeHandle.Create(new Metadata());
nativeMetadata.Dispose();
}
[Test]
public void CreateAndDestroy()
{
var metadata = Metadata.CreateBuilder()
.Add(new Metadata.MetadataEntry("host", "somehost"))
.Add(new Metadata.MetadataEntry("header2", "header value")).Build();
var metadata = new Metadata {
new Metadata.Entry("host", "somehost"),
new Metadata.Entry("header2", "header value"),
};
var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
nativeMetadata.Dispose();
}

@ -80,9 +80,14 @@ namespace Grpc.Core
where TRequest : class
where TResponse : class
{
var metadata = new Metadata();
HeaderInterceptor(metadata);
metadata.Freeze();
var metadata = Metadata.Empty;
var interceptor = HeaderInterceptor;
if (interceptor != null)
{
metadata = new Metadata();
interceptor(metadata);
metadata.Freeze();
}
return new Call<TRequest, TResponse>(serviceName, method, channel, metadata);
}
}

@ -49,7 +49,7 @@ namespace math.Tests
string host = "localhost";
Server server;
Channel channel;
Math.IMathClient client;
Math.MathClient client;
[TestFixtureSetUp]
public void Init()
@ -59,14 +59,14 @@ namespace math.Tests
int port = server.AddListeningPort(host, Server.PickUnusedPort);
server.Start();
channel = new Channel(host, port);
client = Math.NewClient(channel);
// TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
// for header support.
var stubConfig = new StubConfiguration((headerBuilder) =>
client.HeaderInterceptor = (metadata) =>
{
headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
});
client = Math.NewStub(channel, stubConfig);
metadata.Add(new Metadata.Entry("customHeader", "abcdef"));
};
}
[TestFixtureTearDown]

@ -41,7 +41,7 @@ namespace math {
__Marshaller_Num,
__Marshaller_Num);
// client-side stub interface
// client interface
public interface IMathClient
{
global::math.DivReply Div(global::math.DivArgs request, CancellationToken token = default(CancellationToken));
@ -61,12 +61,9 @@ namespace math {
}
// client stub
public class MathClient : ClientBase<MathClient, StubConfiguration>, IMathClient
public class MathClient : ClientBase, IMathClient
{
public MathClient(Channel channel) : this(channel, StubConfiguration.Default)
{
}
public MathClient(Channel channel, StubConfiguration config) : base(channel, config)
public MathClient(Channel channel) : base(channel)
{
}
public global::math.DivReply Div(global::math.DivArgs request, CancellationToken token = default(CancellationToken))
@ -106,17 +103,12 @@ namespace math {
.AddMethod(__Method_Sum, serviceImpl.Sum).Build();
}
// creates a new client stub
public static IMathClient NewStub(Channel channel)
// creates a new client
public static MathClient NewClient(Channel channel)
{
return new MathClient(channel);
}
// creates a new client stub
public static IMathClient NewStub(Channel channel, StubConfiguration config)
{
return new MathClient(channel, config);
}
}
}
#endregion

@ -63,7 +63,7 @@ namespace Grpc.HealthCheck.Tests
server.Start();
channel = new Channel(Host, port);
client = Grpc.Health.V1Alpha.Health.NewStub(channel);
client = Grpc.Health.V1Alpha.Health.NewClient(channel);
}
[TestFixtureTearDown]

@ -21,7 +21,7 @@ namespace Grpc.Health.V1Alpha {
__Marshaller_HealthCheckRequest,
__Marshaller_HealthCheckResponse);
// client-side stub interface
// client interface
public interface IHealthClient
{
global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CancellationToken token = default(CancellationToken));
@ -35,12 +35,9 @@ namespace Grpc.Health.V1Alpha {
}
// client stub
public class HealthClient : ClientBase<HealthClient, StubConfiguration>, IHealthClient
public class HealthClient : ClientBase, IHealthClient
{
public HealthClient(Channel channel) : this(channel, StubConfiguration.Default)
{
}
public HealthClient(Channel channel, StubConfiguration config) : base(channel, config)
public HealthClient(Channel channel) : base(channel)
{
}
public global::Grpc.Health.V1Alpha.HealthCheckResponse Check(global::Grpc.Health.V1Alpha.HealthCheckRequest request, CancellationToken token = default(CancellationToken))
@ -62,17 +59,12 @@ namespace Grpc.Health.V1Alpha {
.AddMethod(__Method_Check, serviceImpl.Check).Build();
}
// creates a new client stub
public static IHealthClient NewStub(Channel channel)
// creates a new client
public static HealthClient NewClient(Channel channel)
{
return new HealthClient(channel);
}
// creates a new client stub
public static IHealthClient NewStub(Channel channel, StubConfiguration config)
{
return new HealthClient(channel, config);
}
}
}
#endregion

@ -119,7 +119,7 @@ namespace Grpc.IntegrationTesting
using (Channel channel = new Channel(options.serverHost, options.serverPort.Value, credentials, channelOptions))
{
var stubConfig = StubConfiguration.Default;
TestService.TestServiceClient client = new TestService.TestServiceClient(channel);
if (options.testCase == "service_account_creds" || options.testCase == "compute_engine_creds")
{
var credential = GoogleCredential.GetApplicationDefault();
@ -127,10 +127,9 @@ namespace Grpc.IntegrationTesting
{
credential = credential.CreateScoped(new[] { AuthScope });
}
stubConfig = new StubConfiguration(OAuth2InterceptorFactory.Create(credential));
client.HeaderInterceptor = OAuth2InterceptorFactory.Create(credential);
}
TestService.ITestServiceClient client = new TestService.TestServiceClient(channel, stubConfig);
RunTestCase(options.testCase, client);
}
GrpcEnvironment.Shutdown();

@ -65,7 +65,7 @@ namespace Grpc.IntegrationTesting
new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
};
channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options);
client = TestService.NewStub(channel);
client = TestService.NewClient(channel);
}
[TestFixtureTearDown]

@ -56,7 +56,7 @@ namespace grpc.testing {
__Marshaller_StreamingOutputCallRequest,
__Marshaller_StreamingOutputCallResponse);
// client-side stub interface
// client interface
public interface ITestServiceClient
{
global::grpc.testing.Empty EmptyCall(global::grpc.testing.Empty request, CancellationToken token = default(CancellationToken));
@ -81,12 +81,9 @@ namespace grpc.testing {
}
// client stub
public class TestServiceClient : ClientBase<TestServiceClient, StubConfiguration>, ITestServiceClient
public class TestServiceClient : ClientBase, ITestServiceClient
{
public TestServiceClient(Channel channel) : this(channel, StubConfiguration.Default)
{
}
public TestServiceClient(Channel channel, StubConfiguration config) : base(channel, config)
public TestServiceClient(Channel channel) : base(channel)
{
}
public global::grpc.testing.Empty EmptyCall(global::grpc.testing.Empty request, CancellationToken token = default(CancellationToken))
@ -143,17 +140,12 @@ namespace grpc.testing {
.AddMethod(__Method_HalfDuplexCall, serviceImpl.HalfDuplexCall).Build();
}
// creates a new client stub
public static ITestServiceClient NewStub(Channel channel)
// creates a new client
public static TestServiceClient NewClient(Channel channel)
{
return new TestServiceClient(channel);
}
// creates a new client stub
public static ITestServiceClient NewStub(Channel channel, StubConfiguration config)
{
return new TestServiceClient(channel, config);
}
}
}
#endregion

@ -32,16 +32,17 @@
set +e
cd $(dirname $0)
PROTOC=../../bins/opt/protobuf/protoc
PLUGIN=protoc-gen-grpc=../../bins/opt/grpc_csharp_plugin
EXAMPLES_DIR=Grpc.Examples
INTEROP_DIR=Grpc.IntegrationTesting
HEALTHCHECK_DIR=Grpc.HealthCheck
protoc --plugin=$PLUGIN --grpc_out=$EXAMPLES_DIR \
$PROTOC --plugin=$PLUGIN --grpc_out=$EXAMPLES_DIR \
-I $EXAMPLES_DIR/proto $EXAMPLES_DIR/proto/math.proto
protoc --plugin=$PLUGIN --grpc_out=$INTEROP_DIR \
$PROTOC --plugin=$PLUGIN --grpc_out=$INTEROP_DIR \
-I $INTEROP_DIR/proto $INTEROP_DIR/proto/test.proto
protoc --plugin=$PLUGIN --grpc_out=$HEALTHCHECK_DIR \
$PROTOC --plugin=$PLUGIN --grpc_out=$HEALTHCHECK_DIR \
-I $HEALTHCHECK_DIR/proto $HEALTHCHECK_DIR/proto/health.proto

Loading…
Cancel
Save