Skip to content

Commit 33d99ce

Browse files
committed
Add UNIMPLEMENTED_METHOD interop test case.
Rename old UNIMPLEMENTED_METHOD test case to UNIMPLEMENTED_SERVICE.
1 parent 8702185 commit 33d99ce

File tree

8 files changed

+116
-15
lines changed

8 files changed

+116
-15
lines changed

interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ private TestServiceGrpc() {}
8585
"grpc.testing.TestService", "HalfDuplexCall"),
8686
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance()),
8787
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.getDefaultInstance()));
88+
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
89+
public static final io.grpc.MethodDescriptor<com.google.protobuf.EmptyProtos.Empty,
90+
com.google.protobuf.EmptyProtos.Empty> METHOD_UNIMPLEMENTED_CALL =
91+
io.grpc.MethodDescriptor.create(
92+
io.grpc.MethodDescriptor.MethodType.UNARY,
93+
generateFullMethodName(
94+
"grpc.testing.TestService", "UnimplementedCall"),
95+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()),
96+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()));
8897

8998
/**
9099
* Creates a new async stub that supports all call types for the service
@@ -184,6 +193,17 @@ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.Streamin
184193
return asyncUnimplementedStreamingCall(METHOD_HALF_DUPLEX_CALL, responseObserver);
185194
}
186195

196+
/**
197+
* <pre>
198+
* The test server will not implement this method. It will be used
199+
* to test the behavior when clients call unimplemented methods.
200+
* </pre>
201+
*/
202+
public void unimplementedCall(com.google.protobuf.EmptyProtos.Empty request,
203+
io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty> responseObserver) {
204+
asyncUnimplementedUnaryCall(METHOD_UNIMPLEMENTED_CALL, responseObserver);
205+
}
206+
187207
@java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
188208
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
189209
.addMethod(
@@ -228,6 +248,13 @@ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.Streamin
228248
io.grpc.testing.integration.Messages.StreamingOutputCallRequest,
229249
io.grpc.testing.integration.Messages.StreamingOutputCallResponse>(
230250
this, METHODID_HALF_DUPLEX_CALL)))
251+
.addMethod(
252+
METHOD_UNIMPLEMENTED_CALL,
253+
asyncUnaryCall(
254+
new MethodHandlers<
255+
com.google.protobuf.EmptyProtos.Empty,
256+
com.google.protobuf.EmptyProtos.Empty>(
257+
this, METHODID_UNIMPLEMENTED_CALL)))
231258
.build();
232259
}
233260
}
@@ -326,6 +353,18 @@ public io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.Streamin
326353
return asyncBidiStreamingCall(
327354
getChannel().newCall(METHOD_HALF_DUPLEX_CALL, getCallOptions()), responseObserver);
328355
}
356+
357+
/**
358+
* <pre>
359+
* The test server will not implement this method. It will be used
360+
* to test the behavior when clients call unimplemented methods.
361+
* </pre>
362+
*/
363+
public void unimplementedCall(com.google.protobuf.EmptyProtos.Empty request,
364+
io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty> responseObserver) {
365+
asyncUnaryCall(
366+
getChannel().newCall(METHOD_UNIMPLEMENTED_CALL, getCallOptions()), request, responseObserver);
367+
}
329368
}
330369

331370
/**
@@ -381,6 +420,17 @@ public java.util.Iterator<io.grpc.testing.integration.Messages.StreamingOutputCa
381420
return blockingServerStreamingCall(
382421
getChannel(), METHOD_STREAMING_OUTPUT_CALL, getCallOptions(), request);
383422
}
423+
424+
/**
425+
* <pre>
426+
* The test server will not implement this method. It will be used
427+
* to test the behavior when clients call unimplemented methods.
428+
* </pre>
429+
*/
430+
public com.google.protobuf.EmptyProtos.Empty unimplementedCall(com.google.protobuf.EmptyProtos.Empty request) {
431+
return blockingUnaryCall(
432+
getChannel(), METHOD_UNIMPLEMENTED_CALL, getCallOptions(), request);
433+
}
384434
}
385435

386436
/**
@@ -426,14 +476,27 @@ public com.google.common.util.concurrent.ListenableFuture<io.grpc.testing.integr
426476
return futureUnaryCall(
427477
getChannel().newCall(METHOD_UNARY_CALL, getCallOptions()), request);
428478
}
479+
480+
/**
481+
* <pre>
482+
* The test server will not implement this method. It will be used
483+
* to test the behavior when clients call unimplemented methods.
484+
* </pre>
485+
*/
486+
public com.google.common.util.concurrent.ListenableFuture<com.google.protobuf.EmptyProtos.Empty> unimplementedCall(
487+
com.google.protobuf.EmptyProtos.Empty request) {
488+
return futureUnaryCall(
489+
getChannel().newCall(METHOD_UNIMPLEMENTED_CALL, getCallOptions()), request);
490+
}
429491
}
430492

431493
private static final int METHODID_EMPTY_CALL = 0;
432494
private static final int METHODID_UNARY_CALL = 1;
433495
private static final int METHODID_STREAMING_OUTPUT_CALL = 2;
434-
private static final int METHODID_STREAMING_INPUT_CALL = 3;
435-
private static final int METHODID_FULL_DUPLEX_CALL = 4;
436-
private static final int METHODID_HALF_DUPLEX_CALL = 5;
496+
private static final int METHODID_UNIMPLEMENTED_CALL = 3;
497+
private static final int METHODID_STREAMING_INPUT_CALL = 4;
498+
private static final int METHODID_FULL_DUPLEX_CALL = 5;
499+
private static final int METHODID_HALF_DUPLEX_CALL = 6;
437500

438501
private static class MethodHandlers<Req, Resp> implements
439502
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
@@ -464,6 +527,10 @@ public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserv
464527
serviceImpl.streamingOutputCall((io.grpc.testing.integration.Messages.StreamingOutputCallRequest) request,
465528
(io.grpc.stub.StreamObserver<io.grpc.testing.integration.Messages.StreamingOutputCallResponse>) responseObserver);
466529
break;
530+
case METHODID_UNIMPLEMENTED_CALL:
531+
serviceImpl.unimplementedCall((com.google.protobuf.EmptyProtos.Empty) request,
532+
(io.grpc.stub.StreamObserver<com.google.protobuf.EmptyProtos.Empty>) responseObserver);
533+
break;
467534
default:
468535
throw new AssertionError();
469536
}
@@ -499,7 +566,8 @@ public static synchronized io.grpc.ServiceDescriptor getServiceDescriptor() {
499566
METHOD_STREAMING_OUTPUT_CALL,
500567
METHOD_STREAMING_INPUT_CALL,
501568
METHOD_FULL_DUPLEX_CALL,
502-
METHOD_HALF_DUPLEX_CALL);
569+
METHOD_HALF_DUPLEX_CALL,
570+
METHOD_UNIMPLEMENTED_CALL);
503571
}
504572

505573
return serviceDescriptor;

interop-testing/src/generated/main/java/io/grpc/testing/integration/Test.java

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,25 @@ public void gracefulShutdown() throws Exception {
843843
verifyNoMoreInteractions(responseObserver);
844844
}
845845

846-
/** Sends an rpc to an unimplemented method on the server. */
846+
/** Sends an rpc to an unimplemented method within TestService. */
847847
@Test(timeout = 10000)
848848
public void unimplementedMethod() {
849+
try {
850+
blockingStub.unimplementedCall(Empty.getDefaultInstance());
851+
fail();
852+
} catch (StatusRuntimeException e) {
853+
assertEquals(Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode());
854+
}
855+
856+
if (metricsExpected()) {
857+
assertClientMetrics("grpc.testing.TestService/UnimplementedCall",
858+
Status.Code.UNIMPLEMENTED);
859+
}
860+
}
861+
862+
/** Sends an rpc to an unimplemented service on the server. */
863+
@Test(timeout = 10000)
864+
public void unimplementedService() {
849865
UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub =
850866
UnimplementedServiceGrpc.newBlockingStub(channel);
851867
try {

interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ private void runTestCase(Tester tester, TestCases testCase) throws Exception {
452452
break;
453453
}
454454

455+
case UNIMPLEMENTED_SERVICE: {
456+
tester.unimplementedService();
457+
break;
458+
}
459+
455460
case CANCEL_AFTER_BEGIN: {
456461
tester.cancelAfterBegin();
457462
break;

interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public enum TestCases {
4949
OAUTH2_AUTH_TOKEN("raw oauth2 access token auth"),
5050
PER_RPC_CREDS("per rpc raw oauth2 access token auth"),
5151
UNIMPLEMENTED_METHOD("call an unimplemented RPC method"),
52+
UNIMPLEMENTED_SERVICE("call an unimplemented RPC service"),
5253
CANCEL_AFTER_BEGIN("cancel stream after starting it"),
5354
CANCEL_AFTER_FIRST_RESPONSE("cancel on first response"),
5455
TIMEOUT_ON_SLEEPING_SERVER("timeout before receiving a response");

interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ private void runTest(TestCases testCase) throws Exception {
267267
break;
268268
}
269269

270+
case UNIMPLEMENTED_SERVICE: {
271+
tester.unimplementedService();
272+
break;
273+
}
274+
270275
case CANCEL_AFTER_BEGIN: {
271276
tester.cancelAfterBegin();
272277
break;

interop-testing/src/main/proto/io/grpc/testing/integration/test.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ service TestService {
7070
// first request.
7171
rpc HalfDuplexCall(stream StreamingOutputCallRequest)
7272
returns (stream StreamingOutputCallResponse);
73+
74+
// The test server will not implement this method. It will be used
75+
// to test the behavior when clients call unimplemented methods.
76+
rpc UnimplementedCall(grpc.testing.Empty) returns (grpc.testing.Empty);
7377
}
7478

7579
// A simple service NOT implemented at servers so clients can test for

interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public void testCaseNamesShouldMapToEnums() {
5858
String[] testCases = {"empty_unary", "large_unary", "client_streaming", "server_streaming",
5959
"ping_pong", "empty_stream", "compute_engine_creds", "service_account_creds",
6060
"jwt_token_creds", "oauth2_auth_token", "per_rpc_creds", "unimplemented_method",
61-
"cancel_after_begin", "cancel_after_first_response", "timeout_on_sleeping_server"};
61+
"unimplemented_service", "cancel_after_begin", "cancel_after_first_response",
62+
"timeout_on_sleeping_server"};
6263

6364
assertEquals(testCases.length, TestCases.values().length);
6465

0 commit comments

Comments
 (0)