diff --git a/core/src/test/java/io/grpc/util/UtilServerInterceptorsTest.java b/core/src/test/java/io/grpc/util/UtilServerInterceptorsTest.java index e1f61f1932..530b619940 100644 --- a/core/src/test/java/io/grpc/util/UtilServerInterceptorsTest.java +++ b/core/src/test/java/io/grpc/util/UtilServerInterceptorsTest.java @@ -42,12 +42,12 @@ import org.junit.runners.JUnit4; */ @RunWith(JUnit4.class) public class UtilServerInterceptorsTest { - private MethodDescriptor flowMethod = TestMethodDescriptors.noopMethod(); + private MethodDescriptor flowMethod = TestMethodDescriptors.voidMethod(); private final Metadata headers = new Metadata(); - private ServerCallHandler handler = new ServerCallHandler() { + private ServerCallHandler handler = new ServerCallHandler() { @Override - public ServerCall.Listener startCall( - ServerCall call, Metadata headers) { + public ServerCall.Listener startCall( + ServerCall call, Metadata headers) { return listener; } }; @@ -55,28 +55,28 @@ public class UtilServerInterceptorsTest { ServerServiceDefinition.builder(new ServiceDescriptor("service_foo", flowMethod)) .addMethod(flowMethod, handler) .build(); - private ServerCall.Listener listener; + private ServerCall.Listener listener; @SuppressWarnings("unchecked") - private static ServerMethodDefinition getSoleMethod( + private static ServerMethodDefinition getSoleMethod( ServerServiceDefinition serviceDef) { if (serviceDef.getMethods().size() != 1) { throw new AssertionError("Not exactly one method present"); } - return (ServerMethodDefinition) getOnlyElement(serviceDef.getMethods()); + return (ServerMethodDefinition) getOnlyElement(serviceDef.getMethods()); } @Test public void statusRuntimeExceptionTransmitter() { final Status expectedStatus = Status.UNAVAILABLE; final Metadata expectedMetadata = new Metadata(); - FakeServerCall call = - new FakeServerCall(expectedStatus, expectedMetadata); + FakeServerCall call = + new FakeServerCall(expectedStatus, expectedMetadata); final StatusRuntimeException exception = new StatusRuntimeException(expectedStatus, expectedMetadata); - listener = new ServerCall.Listener() { + listener = new ServerCall.Listener() { @Override - public void onMessage(String message) { + public void onMessage(Void message) { throw exception; } @@ -106,7 +106,7 @@ public class UtilServerInterceptorsTest { Arrays.asList(TransmitStatusRuntimeExceptionInterceptor.instance())); // The interceptor should have handled the error by directly closing the ServerCall // and the exception should not propagate to the method's caller - getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onMessage("hello"); + getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onMessage(null); getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onCancel(); getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onComplete(); getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onHalfClose(); diff --git a/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java b/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java index 6931e896fe..b289152786 100644 --- a/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java +++ b/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java @@ -40,20 +40,29 @@ public final class TestMethodDescriptors { */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public static MethodDescriptor voidMethod() { - return TestMethodDescriptors.noopMethod(); + return MethodDescriptor.newBuilder() + .setType(MethodType.UNARY) + .setFullMethodName(MethodDescriptor.generateFullMethodName("service_foo", "method_bar")) + .setRequestMarshaller(TestMethodDescriptors.voidMarshaller()) + .setResponseMarshaller(TestMethodDescriptors.voidMarshaller()) + .build(); } /** * Creates a new method descriptor that always creates zero length messages, and always parses to * null objects. * + * @deprecated Prefer to use {@link #voidMethod()} instead or use one MethodDescriptor from {@code + * io.grpc.testing.protobuf.SimpleServiceGrpc} or from other generated classes. * @since 1.1.0 */ + @Deprecated @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public static MethodDescriptor noopMethod() { return noopMethod("service_foo", "method_bar"); } + @Deprecated private static MethodDescriptor noopMethod( String serviceName, String methodName) { return MethodDescriptor.newBuilder() @@ -71,14 +80,16 @@ public final class TestMethodDescriptors { */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public static MethodDescriptor.Marshaller voidMarshaller() { - return TestMethodDescriptors.noopMarshaller(); + return new NoopMarshaller(); } /** * Creates a new marshaller that does nothing. * + * @deprecated Use {@link #voidMarshaller()} instead or implement/mock one * @since 1.1.0 */ + @Deprecated @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public static MethodDescriptor.Marshaller noopMarshaller() { return new NoopMarshaller();