Skip to content

Commit

Permalink
Account for the default behavior with and without skipDeprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
mgodave committed Nov 21, 2024
1 parent 7845ebb commit 9120c33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ void tearDown() throws Exception {
}
}

@ParameterizedTest(name = "httpVersion={0) streamingService={0)")
@ParameterizedTest(name = "httpVersion={0} streamingService={1}")
@MethodSource("params")
void testAggregated(HttpProtocolVersion httpProtocol, boolean streamingService) throws Exception {
setUp(httpProtocol, streamingService);
assertResponse(client.test(newRequest()));
}

@ParameterizedTest(name = "httpVersion={0) streamingService={0)")
@ParameterizedTest(name = "httpVersion={0} streamingService={1}")
@MethodSource("params")
void testRequestStream(HttpProtocolVersion httpProtocol, boolean streamingService) throws Exception {
setUp(httpProtocol, streamingService);
assertResponse(client.testRequestStream(Arrays.asList(newRequest(), newRequest())));
}

@ParameterizedTest(name = "httpVersion={0) streamingService={0)")
@ParameterizedTest(name = "httpVersion={0} streamingService={1}")
@MethodSource("params")
void testBiDiStream(HttpProtocolVersion httpProtocol, boolean streamingService) throws Exception {
setUp(httpProtocol, streamingService);
Expand All @@ -127,7 +127,7 @@ void testBiDiStream(HttpProtocolVersion httpProtocol, boolean streamingService)
}
}

@ParameterizedTest(name = "httpVersion={0) streamingService={0)")
@ParameterizedTest(name = "httpVersion={0} streamingService={1}")
@MethodSource("params")
void testResponseStream(HttpProtocolVersion httpProtocol, boolean streamingService) throws Exception {
setUp(httpProtocol, streamingService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1647,12 +1647,12 @@ private TypeSpec newServiceInterfaceSpec(final State state, final boolean blocki

// generate default service methods
if (defaultServiceMethods) {
final List<MethodDescriptorProto> methodList = state.serviceRpcInterfaces.stream()
final List<RpcInterface> interfaces = state.serviceRpcInterfaces.stream()
.filter(intf -> intf.blocking == blocking)
.map(intf -> intf.methodProto)
.collect(toList());
for (int i = 0; i < methodList.size(); ++i) {
final MethodDescriptorProto methodProto = methodList.get(i);
for (int i = 0; i < interfaces.size(); ++i) {
final RpcInterface rpcInterface = interfaces.get(i);
final MethodDescriptorProto methodProto = rpcInterface.methodProto;
final ClassName inClass = messageTypesMap.get(methodProto.getInputType());
final ClassName outClass = messageTypesMap.get(methodProto.getOutputType());
final String methodName = sanitizeIdentifier(methodProto.getName(), true);
Expand All @@ -1661,7 +1661,7 @@ private TypeSpec newServiceInterfaceSpec(final State state, final boolean blocki
final MethodSpec methodSpec = newRpcMethodSpec(inClass, outClass, methodName,
methodProto.getClientStreaming(),
methodProto.getServerStreaming(),
!blocking ? EnumSet.of(INTERFACE) : EnumSet.of(INTERFACE, BLOCKING),
!blocking ? EnumSet.of(INTERFACE) : EnumSet.of(INTERFACE, BLOCKING, SERVER_RESPONSE),
printJavaDocs, (__, spec) -> {
final String errorMessage = "\"Method " + methodPath + " is unimplemented\"";
spec.addModifiers(DEFAULT).addParameter(GrpcServiceContext, ctx);
Expand All @@ -1671,8 +1671,13 @@ private TypeSpec newServiceInterfaceSpec(final State state, final boolean blocki
spec.addStatement("return $T.failed(new $T(new $T($T.UNIMPLEMENTED, $L)))",
returnType, GrpcStatusException, GrpcStatus, GrpcStatusCode, errorMessage);
} else {
spec.addStatement("throw new $T(new $T($T.UNIMPLEMENTED, $L))",
GrpcStatusException, GrpcStatus, GrpcStatusCode, errorMessage);
if (!skipDeprecated && methodProto.getServerStreaming()) {
spec.addStatement("$T.super.$L(ctx, request, response)",
rpcInterface.className, methodName);
} else {
spec.addStatement("throw new $T(new $T($T.UNIMPLEMENTED, $L))",
GrpcStatusException, GrpcStatus, GrpcStatusCode, errorMessage);
}
}
if (printJavaDocs) {
extractJavaDocComments(state, methodIndex, spec);
Expand Down

0 comments on commit 9120c33

Please sign in to comment.