From 7fc86e5549cf4c8d732a51293a51fd7582ab3f8c Mon Sep 17 00:00:00 2001 From: Xiao Hang Date: Thu, 20 Aug 2015 16:08:10 -0700 Subject: [PATCH] Implement unimplemented_method test --- .../integration/UnimplementedServiceGrpc.java | 151 ++++++++++++++++++ .../io/grpc/testing/integration/Test.java | 14 +- .../integration/AbstractTransportTest.java | 14 ++ .../io/grpc/testing/integration/test.proto | 7 + 4 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java new file mode 100644 index 0000000000..5bc4d34153 --- /dev/null +++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java @@ -0,0 +1,151 @@ +package io.grpc.testing.integration; + +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.futureUnaryCall; +import static io.grpc.MethodDescriptor.generateFullMethodName; +import static io.grpc.stub.ServerCalls.asyncUnaryCall; +import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; +import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; +import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; + +@javax.annotation.Generated("by gRPC proto compiler") +public class UnimplementedServiceGrpc { + + // Static method descriptors that strictly reflect the proto. + public static final io.grpc.MethodDescriptor METHOD_UNIMPLEMENTED_CALL = + io.grpc.MethodDescriptor.create( + io.grpc.MethodDescriptor.MethodType.UNARY, + generateFullMethodName( + "grpc.testing.UnimplementedService", "UnimplementedCall"), + io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()), + io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser())); + + public static UnimplementedServiceStub newStub(io.grpc.Channel channel) { + return new UnimplementedServiceStub(channel); + } + + public static UnimplementedServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + return new UnimplementedServiceBlockingStub(channel); + } + + public static UnimplementedServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + return new UnimplementedServiceFutureStub(channel); + } + + public static interface UnimplementedService { + + public void unimplementedCall(com.google.protobuf.EmptyProtos.Empty request, + io.grpc.stub.StreamObserver responseObserver); + } + + public static interface UnimplementedServiceBlockingClient { + + public com.google.protobuf.EmptyProtos.Empty unimplementedCall(com.google.protobuf.EmptyProtos.Empty request); + } + + public static interface UnimplementedServiceFutureClient { + + public com.google.common.util.concurrent.ListenableFuture unimplementedCall( + com.google.protobuf.EmptyProtos.Empty request); + } + + public static class UnimplementedServiceStub extends io.grpc.stub.AbstractStub + implements UnimplementedService { + private UnimplementedServiceStub(io.grpc.Channel channel) { + super(channel); + } + + private UnimplementedServiceStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected UnimplementedServiceStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new UnimplementedServiceStub(channel, callOptions); + } + + @java.lang.Override + public void unimplementedCall(com.google.protobuf.EmptyProtos.Empty request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnaryCall( + channel.newCall(METHOD_UNIMPLEMENTED_CALL, callOptions), request, responseObserver); + } + } + + public static class UnimplementedServiceBlockingStub extends io.grpc.stub.AbstractStub + implements UnimplementedServiceBlockingClient { + private UnimplementedServiceBlockingStub(io.grpc.Channel channel) { + super(channel); + } + + private UnimplementedServiceBlockingStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected UnimplementedServiceBlockingStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new UnimplementedServiceBlockingStub(channel, callOptions); + } + + @java.lang.Override + public com.google.protobuf.EmptyProtos.Empty unimplementedCall(com.google.protobuf.EmptyProtos.Empty request) { + return blockingUnaryCall( + channel.newCall(METHOD_UNIMPLEMENTED_CALL, callOptions), request); + } + } + + public static class UnimplementedServiceFutureStub extends io.grpc.stub.AbstractStub + implements UnimplementedServiceFutureClient { + private UnimplementedServiceFutureStub(io.grpc.Channel channel) { + super(channel); + } + + private UnimplementedServiceFutureStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected UnimplementedServiceFutureStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new UnimplementedServiceFutureStub(channel, callOptions); + } + + @java.lang.Override + public com.google.common.util.concurrent.ListenableFuture unimplementedCall( + com.google.protobuf.EmptyProtos.Empty request) { + return futureUnaryCall( + channel.newCall(METHOD_UNIMPLEMENTED_CALL, callOptions), request); + } + } + + public static io.grpc.ServerServiceDefinition bindService( + final UnimplementedService serviceImpl) { + return io.grpc.ServerServiceDefinition.builder("grpc.testing.UnimplementedService") + .addMethod(io.grpc.ServerMethodDefinition.create( + METHOD_UNIMPLEMENTED_CALL, + asyncUnaryCall( + new io.grpc.stub.ServerCalls.UnaryMethod< + com.google.protobuf.EmptyProtos.Empty, + com.google.protobuf.EmptyProtos.Empty>() { + @java.lang.Override + public void invoke( + com.google.protobuf.EmptyProtos.Empty request, + io.grpc.stub.StreamObserver responseObserver) { + serviceImpl.unimplementedCall(request, responseObserver); + } + }))).build(); + } +} diff --git a/interop-testing/src/generated/main/java/io/grpc/testing/integration/Test.java b/interop-testing/src/generated/main/java/io/grpc/testing/integration/Test.java index 3b43922e0e..7ecf881d63 100644 --- a/interop-testing/src/generated/main/java/io/grpc/testing/integration/Test.java +++ b/interop-testing/src/generated/main/java/io/grpc/testing/integration/Test.java @@ -34,12 +34,14 @@ public final class Test { ").grpc.testing.StreamingOutputCallRespon" + "se(\0010\001\022i\n\016HalfDuplexCall\022(.grpc.testing." + "StreamingOutputCallRequest\032).grpc.testin" + - "g.StreamingOutputCallResponse(\0010\0012\177\n\020Rec" + - "onnectService\0221\n\005Start\022\023.grpc.testing.Em" + - "pty\032\023.grpc.testing.Empty\0228\n\004Stop\022\023.grpc.", - "testing.Empty\032\033.grpc.testing.ReconnectIn" + - "foB\035\n\033io.grpc.testing.integrationb\006proto" + - "3" + "g.StreamingOutputCallResponse(\0010\0012U\n\024Uni" + + "mplementedService\022=\n\021UnimplementedCall\022\023" + + ".grpc.testing.Empty\032\023.grpc.testing.Empty", + "2\177\n\020ReconnectService\0221\n\005Start\022\023.grpc.tes" + + "ting.Empty\032\023.grpc.testing.Empty\0228\n\004Stop\022" + + "\023.grpc.testing.Empty\032\033.grpc.testing.Reco" + + "nnectInfoB\035\n\033io.grpc.testing.integration" + + "b\006proto3" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java index 7bc8d94514..b2d86f8acd 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractTransportTest.java @@ -59,6 +59,7 @@ import io.grpc.Metadata; import io.grpc.ServerImpl; import io.grpc.ServerInterceptors; import io.grpc.Status; +import io.grpc.StatusRuntimeException; import io.grpc.auth.ClientAuthInterceptor; import io.grpc.internal.GrpcUtil; import io.grpc.protobuf.ProtoUtils; @@ -812,6 +813,19 @@ public abstract class AbstractTransportTest { authScope.contains(response.getOauthScope())); } + /** Sends an rpc to an unimplemented method on the server. */ + @Test(timeout = 10000) + public void unimplementedMethod() { + UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub = + UnimplementedServiceGrpc.newBlockingStub(channel); + try { + stub.unimplementedCall(Empty.getDefaultInstance()); + fail(); + } catch (StatusRuntimeException e) { + assertEquals(Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode()); + } + } + protected static void assertSuccess(StreamRecorder recorder) { if (recorder.getError() != null) { throw new AssertionError(recorder.getError()); diff --git a/interop-testing/src/main/proto/io/grpc/testing/integration/test.proto b/interop-testing/src/main/proto/io/grpc/testing/integration/test.proto index 6ea169a2ff..276d4a8cbf 100644 --- a/interop-testing/src/main/proto/io/grpc/testing/integration/test.proto +++ b/interop-testing/src/main/proto/io/grpc/testing/integration/test.proto @@ -72,6 +72,13 @@ service TestService { returns (stream StreamingOutputCallResponse); } +// A simple service NOT implemented at servers so clients can test for +// that case. +service UnimplementedService { + // A call that no server should implement + rpc UnimplementedCall(grpc.testing.Empty) returns(grpc.testing.Empty); +} + // A service used to control reconnect server. service ReconnectService { rpc Start(grpc.testing.Empty) returns (grpc.testing.Empty);