mirror of https://github.com/grpc/grpc-java.git
testing: favor voidMethod and deprecate noopMethod
This commit is contained in:
parent
e1fd615df8
commit
9a06c4eb0e
|
|
@ -42,12 +42,12 @@ import org.junit.runners.JUnit4;
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class UtilServerInterceptorsTest {
|
public class UtilServerInterceptorsTest {
|
||||||
private MethodDescriptor<String, Integer> flowMethod = TestMethodDescriptors.noopMethod();
|
private MethodDescriptor<Void, Void> flowMethod = TestMethodDescriptors.voidMethod();
|
||||||
private final Metadata headers = new Metadata();
|
private final Metadata headers = new Metadata();
|
||||||
private ServerCallHandler<String, Integer> handler = new ServerCallHandler<String, Integer>() {
|
private ServerCallHandler<Void, Void> handler = new ServerCallHandler<Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
public ServerCall.Listener<String> startCall(
|
public ServerCall.Listener<Void> startCall(
|
||||||
ServerCall<String, Integer> call, Metadata headers) {
|
ServerCall<Void, Void> call, Metadata headers) {
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -55,28 +55,28 @@ public class UtilServerInterceptorsTest {
|
||||||
ServerServiceDefinition.builder(new ServiceDescriptor("service_foo", flowMethod))
|
ServerServiceDefinition.builder(new ServiceDescriptor("service_foo", flowMethod))
|
||||||
.addMethod(flowMethod, handler)
|
.addMethod(flowMethod, handler)
|
||||||
.build();
|
.build();
|
||||||
private ServerCall.Listener<String> listener;
|
private ServerCall.Listener<Void> listener;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static ServerMethodDefinition<String, Integer> getSoleMethod(
|
private static ServerMethodDefinition<Void, Void> getSoleMethod(
|
||||||
ServerServiceDefinition serviceDef) {
|
ServerServiceDefinition serviceDef) {
|
||||||
if (serviceDef.getMethods().size() != 1) {
|
if (serviceDef.getMethods().size() != 1) {
|
||||||
throw new AssertionError("Not exactly one method present");
|
throw new AssertionError("Not exactly one method present");
|
||||||
}
|
}
|
||||||
return (ServerMethodDefinition<String, Integer>) getOnlyElement(serviceDef.getMethods());
|
return (ServerMethodDefinition<Void, Void>) getOnlyElement(serviceDef.getMethods());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusRuntimeExceptionTransmitter() {
|
public void statusRuntimeExceptionTransmitter() {
|
||||||
final Status expectedStatus = Status.UNAVAILABLE;
|
final Status expectedStatus = Status.UNAVAILABLE;
|
||||||
final Metadata expectedMetadata = new Metadata();
|
final Metadata expectedMetadata = new Metadata();
|
||||||
FakeServerCall<String, Integer> call =
|
FakeServerCall<Void, Void> call =
|
||||||
new FakeServerCall<String, Integer>(expectedStatus, expectedMetadata);
|
new FakeServerCall<Void, Void>(expectedStatus, expectedMetadata);
|
||||||
final StatusRuntimeException exception =
|
final StatusRuntimeException exception =
|
||||||
new StatusRuntimeException(expectedStatus, expectedMetadata);
|
new StatusRuntimeException(expectedStatus, expectedMetadata);
|
||||||
listener = new ServerCall.Listener<String>() {
|
listener = new ServerCall.Listener<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String message) {
|
public void onMessage(Void message) {
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ public class UtilServerInterceptorsTest {
|
||||||
Arrays.asList(TransmitStatusRuntimeExceptionInterceptor.instance()));
|
Arrays.asList(TransmitStatusRuntimeExceptionInterceptor.instance()));
|
||||||
// The interceptor should have handled the error by directly closing the ServerCall
|
// The interceptor should have handled the error by directly closing the ServerCall
|
||||||
// and the exception should not propagate to the method's caller
|
// 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).onCancel();
|
||||||
getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onComplete();
|
getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onComplete();
|
||||||
getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onHalfClose();
|
getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers).onHalfClose();
|
||||||
|
|
|
||||||
|
|
@ -40,20 +40,29 @@ public final class TestMethodDescriptors {
|
||||||
*/
|
*/
|
||||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
||||||
public static MethodDescriptor<Void, Void> voidMethod() {
|
public static MethodDescriptor<Void, Void> voidMethod() {
|
||||||
return TestMethodDescriptors.<Void, Void>noopMethod();
|
return MethodDescriptor.<Void, Void>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
|
* Creates a new method descriptor that always creates zero length messages, and always parses to
|
||||||
* null objects.
|
* 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
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
||||||
public static <ReqT, RespT> MethodDescriptor<ReqT, RespT> noopMethod() {
|
public static <ReqT, RespT> MethodDescriptor<ReqT, RespT> noopMethod() {
|
||||||
return noopMethod("service_foo", "method_bar");
|
return noopMethod("service_foo", "method_bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private static <ReqT, RespT> MethodDescriptor<ReqT, RespT> noopMethod(
|
private static <ReqT, RespT> MethodDescriptor<ReqT, RespT> noopMethod(
|
||||||
String serviceName, String methodName) {
|
String serviceName, String methodName) {
|
||||||
return MethodDescriptor.<ReqT, RespT>newBuilder()
|
return MethodDescriptor.<ReqT, RespT>newBuilder()
|
||||||
|
|
@ -71,14 +80,16 @@ public final class TestMethodDescriptors {
|
||||||
*/
|
*/
|
||||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
||||||
public static MethodDescriptor.Marshaller<Void> voidMarshaller() {
|
public static MethodDescriptor.Marshaller<Void> voidMarshaller() {
|
||||||
return TestMethodDescriptors.<Void>noopMarshaller();
|
return new NoopMarshaller<Void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new marshaller that does nothing.
|
* Creates a new marshaller that does nothing.
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link #voidMarshaller()} instead or implement/mock one
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600")
|
||||||
public static <T> MethodDescriptor.Marshaller<T> noopMarshaller() {
|
public static <T> MethodDescriptor.Marshaller<T> noopMarshaller() {
|
||||||
return new NoopMarshaller<T>();
|
return new NoopMarshaller<T>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue