Java Code Examples for io.grpc.MethodDescriptor#getRequestMarshaller()

The following examples show how to use io.grpc.MethodDescriptor#getRequestMarshaller() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInteropTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void maxOutboundSize_exact() {
  StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
      .addResponseParameters(ResponseParameters.newBuilder().setSize(1))
      .build();

  MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
      TestServiceGrpc.getStreamingOutputCallMethod();
  ByteSizeMarshaller<StreamingOutputCallRequest> mar =
      new ByteSizeMarshaller<>(md.getRequestMarshaller());
  blockingServerStreamingCall(
      blockingStub.getChannel(),
      md.toBuilder(mar, md.getResponseMarshaller()).build(),
      blockingStub.getCallOptions(),
      request)
      .next();

  int size = mar.lastOutSize;

  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withMaxOutboundMessageSize(size);

  stub.streamingOutputCall(request).next();
}
 
Example 2
Source File: GrpcMessageMarshaller.java    From armeria with Apache License 2.0 6 votes vote down vote up
public GrpcMessageMarshaller(ByteBufAllocator alloc,
                             SerializationFormat serializationFormat,
                             MethodDescriptor<I, O> method,
                             @Nullable GrpcJsonMarshaller jsonMarshaller,
                             boolean unsafeWrapDeserializedBuffer) {
    this.alloc = requireNonNull(alloc, "alloc");
    this.method = requireNonNull(method, "method");
    this.unsafeWrapDeserializedBuffer = unsafeWrapDeserializedBuffer;
    checkArgument(!GrpcSerializationFormats.isJson(serializationFormat) || jsonMarshaller != null,
                  "jsonMarshaller must be non-null when serializationFormat is JSON.");
    isProto = GrpcSerializationFormats.isProto(serializationFormat);
    this.jsonMarshaller = jsonMarshaller;
    requestMarshaller = method.getRequestMarshaller();
    responseMarshaller = method.getResponseMarshaller();
    requestType = marshallerType(requestMarshaller);
    responseType = marshallerType(responseMarshaller);
}
 
Example 3
Source File: AbstractInteropTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void maxOutboundSize_exact() {
  StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
      .addResponseParameters(ResponseParameters.newBuilder().setSize(1))
      .build();

  MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
      TestServiceGrpc.getStreamingOutputCallMethod();
  ByteSizeMarshaller<StreamingOutputCallRequest> mar =
      new ByteSizeMarshaller<>(md.getRequestMarshaller());
  blockingServerStreamingCall(
      blockingStub.getChannel(),
      md.toBuilder(mar, md.getResponseMarshaller()).build(),
      blockingStub.getCallOptions(),
      request)
      .next();

  int size = mar.lastOutSize;

  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withMaxOutboundMessageSize(size);

  stub.streamingOutputCall(request).next();
}
 
Example 4
Source File: AbstractInteropTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void maxInboundSize_tooBig() {
  StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
      .addResponseParameters(ResponseParameters.newBuilder().setSize(1))
      .build();

  MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
      TestServiceGrpc.getStreamingOutputCallMethod();
  ByteSizeMarshaller<StreamingOutputCallRequest> mar =
      new ByteSizeMarshaller<>(md.getRequestMarshaller());
  blockingServerStreamingCall(
      blockingStub.getChannel(),
      md.toBuilder(mar, md.getResponseMarshaller()).build(),
      blockingStub.getCallOptions(),
      request)
      .next();

  int size = mar.lastOutSize;

  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withMaxInboundMessageSize(size - 1);

  try {
    stub.streamingOutputCall(request).next();
    fail();
  } catch (StatusRuntimeException ex) {
    Status s = ex.getStatus();
    assertThat(s.getCode()).named(s.toString()).isEqualTo(Status.Code.RESOURCE_EXHAUSTED);
    assertThat(Throwables.getStackTraceAsString(ex)).contains("exceeds maximum");
  }
}
 
Example 5
Source File: AbstractInteropTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void maxOutboundSize_tooBig() {
  // set at least one field to ensure the size is non-zero.
  StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
      .addResponseParameters(ResponseParameters.newBuilder().setSize(1))
      .build();


  MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
      TestServiceGrpc.getStreamingOutputCallMethod();
  ByteSizeMarshaller<StreamingOutputCallRequest> mar =
      new ByteSizeMarshaller<>(md.getRequestMarshaller());
  blockingServerStreamingCall(
      blockingStub.getChannel(),
      md.toBuilder(mar, md.getResponseMarshaller()).build(),
      blockingStub.getCallOptions(),
      request)
      .next();

  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withMaxOutboundMessageSize(mar.lastOutSize - 1);
  try {
    stub.streamingOutputCall(request).next();
    fail();
  } catch (StatusRuntimeException ex) {
    Status s = ex.getStatus();
    assertThat(s.getCode()).named(s.toString()).isEqualTo(Status.Code.CANCELLED);
    assertThat(Throwables.getStackTraceAsString(ex)).contains("message too large");
  }
}
 
Example 6
Source File: AbstractInteropTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void maxInboundSize_tooBig() {
  StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
      .addResponseParameters(ResponseParameters.newBuilder().setSize(1))
      .build();

  MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
      TestServiceGrpc.getStreamingOutputCallMethod();
  ByteSizeMarshaller<StreamingOutputCallRequest> mar =
      new ByteSizeMarshaller<>(md.getRequestMarshaller());
  blockingServerStreamingCall(
      blockingStub.getChannel(),
      md.toBuilder(mar, md.getResponseMarshaller()).build(),
      blockingStub.getCallOptions(),
      request)
      .next();

  int size = mar.lastOutSize;

  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withMaxInboundMessageSize(size - 1);

  try {
    stub.streamingOutputCall(request).next();
    fail();
  } catch (StatusRuntimeException ex) {
    Status s = ex.getStatus();
    assertWithMessage(s.toString()).that(s.getCode()).isEqualTo(Status.Code.RESOURCE_EXHAUSTED);
    assertThat(Throwables.getStackTraceAsString(ex)).contains("exceeds maximum");
  }
}
 
Example 7
Source File: AbstractInteropTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void maxOutboundSize_tooBig() {
  // set at least one field to ensure the size is non-zero.
  StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
      .addResponseParameters(ResponseParameters.newBuilder().setSize(1))
      .build();


  MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
      TestServiceGrpc.getStreamingOutputCallMethod();
  ByteSizeMarshaller<StreamingOutputCallRequest> mar =
      new ByteSizeMarshaller<>(md.getRequestMarshaller());
  blockingServerStreamingCall(
      blockingStub.getChannel(),
      md.toBuilder(mar, md.getResponseMarshaller()).build(),
      blockingStub.getCallOptions(),
      request)
      .next();

  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withMaxOutboundMessageSize(mar.lastOutSize - 1);
  try {
    stub.streamingOutputCall(request).next();
    fail();
  } catch (StatusRuntimeException ex) {
    Status s = ex.getStatus();
    assertWithMessage(s.toString()).that(s.getCode()).isEqualTo(Status.Code.CANCELLED);
    assertThat(Throwables.getStackTraceAsString(ex)).contains("message too large");
  }
}