From 566d0e9400c9e13cffac7ae309c95cce64f4936e Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Fri, 27 Jan 2017 14:41:38 -0800 Subject: [PATCH] testing: change names of noopMarshaller to void marshaller This is needed because in interceptor tests, often the types cannot be changed. The void methods stay for users who are writing tests where they actually don't care about types. The noop methods require types to be specified. This is for users who don't care about the implementation. These represent different levels of commitment. This eases the transition of code Mocking MethodDescriptor, which breaks in this release. --- .../netty/HandlerRegistryBenchmark.java | 4 +- .../java/io/grpc/ClientInterceptorsTest.java | 2 +- .../java/io/grpc/ServiceDescriptorTest.java | 12 ++--- .../io/grpc/internal/ClientCallImplTest.java | 4 +- .../okhttp/OkHttpClientTransportTest.java | 2 +- .../grpc/testing/TestMethodDescriptors.java | 49 +++++++++++++++---- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/HandlerRegistryBenchmark.java b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/HandlerRegistryBenchmark.java index 36bdb454a9..7c00056b92 100644 --- a/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/HandlerRegistryBenchmark.java +++ b/benchmarks/src/jmh/java/io/grpc/benchmarks/netty/HandlerRegistryBenchmark.java @@ -91,8 +91,8 @@ public class HandlerRegistryBenchmark { MethodDescriptor methodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNKNOWN) .setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName)) - .setRequestMarshaller(TestMethodDescriptors.noopMarshaller()) - .setResponseMarshaller(TestMethodDescriptors.noopMarshaller()) + .setRequestMarshaller(TestMethodDescriptors.voidMarshaller()) + .setResponseMarshaller(TestMethodDescriptors.voidMarshaller()) .build(); serviceBuilder.addMethod(methodDescriptor, new ServerCallHandler() { diff --git a/core/src/test/java/io/grpc/ClientInterceptorsTest.java b/core/src/test/java/io/grpc/ClientInterceptorsTest.java index 7097641a86..636524d43d 100644 --- a/core/src/test/java/io/grpc/ClientInterceptorsTest.java +++ b/core/src/test/java/io/grpc/ClientInterceptorsTest.java @@ -73,7 +73,7 @@ public class ClientInterceptorsTest { private BaseClientCall call = new BaseClientCall(); - private final MethodDescriptor method = TestMethodDescriptors.noopMethod(); + private final MethodDescriptor method = TestMethodDescriptors.voidMethod(); /** * Sets up mocks. diff --git a/core/src/test/java/io/grpc/ServiceDescriptorTest.java b/core/src/test/java/io/grpc/ServiceDescriptorTest.java index 9873715f8f..4489981456 100644 --- a/core/src/test/java/io/grpc/ServiceDescriptorTest.java +++ b/core/src/test/java/io/grpc/ServiceDescriptorTest.java @@ -76,8 +76,8 @@ public class ServiceDescriptorTest { MethodDescriptor.create( MethodType.UNARY, MethodDescriptor.generateFullMethodName("wrongservice", "method"), - TestMethodDescriptors.noopMarshaller(), - TestMethodDescriptors.noopMarshaller()))); + TestMethodDescriptors.voidMarshaller(), + TestMethodDescriptors.voidMarshaller()))); } @Test @@ -89,12 +89,12 @@ public class ServiceDescriptorTest { MethodDescriptor.create( MethodType.UNARY, MethodDescriptor.generateFullMethodName("name", "method"), - TestMethodDescriptors.noopMarshaller(), - TestMethodDescriptors.noopMarshaller()), + TestMethodDescriptors.voidMarshaller(), + TestMethodDescriptors.voidMarshaller()), MethodDescriptor.create( MethodType.UNARY, MethodDescriptor.generateFullMethodName("name", "method"), - TestMethodDescriptors.noopMarshaller(), - TestMethodDescriptors.noopMarshaller()))); + TestMethodDescriptors.voidMarshaller(), + TestMethodDescriptors.voidMarshaller()))); } } diff --git a/core/src/test/java/io/grpc/internal/ClientCallImplTest.java b/core/src/test/java/io/grpc/internal/ClientCallImplTest.java index c9c3bffa14..0875757b5d 100644 --- a/core/src/test/java/io/grpc/internal/ClientCallImplTest.java +++ b/core/src/test/java/io/grpc/internal/ClientCallImplTest.java @@ -112,8 +112,8 @@ public class ClientCallImplTest { private final MethodDescriptor method = MethodDescriptor.newBuilder() .setType(MethodType.UNARY) .setFullMethodName("service/method") - .setRequestMarshaller(TestMethodDescriptors.noopMarshaller()) - .setResponseMarshaller(TestMethodDescriptors.noopMarshaller()) + .setRequestMarshaller(TestMethodDescriptors.voidMarshaller()) + .setResponseMarshaller(TestMethodDescriptors.voidMarshaller()) .build(); private final FakeStatsContextFactory statsCtxFactory = new FakeStatsContextFactory(); diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java index 6beff3d7b5..9238022395 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java @@ -131,7 +131,7 @@ public class OkHttpClientTransportTest { @Mock private FrameWriter frameWriter; - private MethodDescriptor method = TestMethodDescriptors.noopMethod(); + private MethodDescriptor method = TestMethodDescriptors.voidMethod(); @Mock private ManagedClientTransport.Listener transportListener; diff --git a/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java b/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java index 5f2127a6fe..d4fc66b0a6 100644 --- a/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java +++ b/testing/src/main/java/io/grpc/testing/TestMethodDescriptors.java @@ -40,6 +40,8 @@ import java.io.InputStream; /** * A collection of method descriptor constructors useful for tests. These are useful if you need * a descriptor, but don't really care how it works. + * + * @since 1.1.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public final class TestMethodDescriptors { @@ -48,36 +50,63 @@ public final class TestMethodDescriptors { /** * Creates a new method descriptor that always creates zero length messages, and always parses to * null objects. + * + * @since 1.1.0 */ - public static MethodDescriptor noopMethod() { + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") + public static MethodDescriptor voidMethod() { + return TestMethodDescriptors.noopMethod(); + } + + /** + * Creates a new method descriptor that always creates zero length messages, and always parses to + * null objects. + * + * @since 1.1.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") + public static MethodDescriptor noopMethod() { return noopMethod("service_foo", "method_bar"); } - private static MethodDescriptor noopMethod( + private static MethodDescriptor noopMethod( String serviceName, String methodName) { - return MethodDescriptor.newBuilder() + return MethodDescriptor.newBuilder() .setType(MethodType.UNARY) .setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName)) - .setRequestMarshaller(noopMarshaller()) - .setResponseMarshaller(noopMarshaller()) + .setRequestMarshaller(TestMethodDescriptors.noopMarshaller()) + .setResponseMarshaller(TestMethodDescriptors.noopMarshaller()) .build(); } /** * Creates a new marshaller that does nothing. + * + * @since 1.1.0 */ - public static MethodDescriptor.Marshaller noopMarshaller() { - return new NoopMarshaller(); + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") + public static MethodDescriptor.Marshaller voidMarshaller() { + return TestMethodDescriptors.noopMarshaller(); } - private static final class NoopMarshaller implements MethodDescriptor.Marshaller { + /** + * Creates a new marshaller that does nothing. + * + * @since 1.1.0 + */ + @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") + public static MethodDescriptor.Marshaller noopMarshaller() { + return new NoopMarshaller(); + } + + private static final class NoopMarshaller implements MethodDescriptor.Marshaller { @Override - public InputStream stream(Void value) { + public InputStream stream(T value) { return new ByteArrayInputStream(new byte[]{}); } @Override - public Void parse(InputStream stream) { + public T parse(InputStream stream) { return null; } }