use of io.grpc.StatusRuntimeException in project grpc-java by grpc.
the class AbstractInteropTest method maxOutboundSize_tooBig.
@Test(timeout = 10000)
public void maxOutboundSize_tooBig() {
// warm up the channel and JVM
blockingStub.emptyCall(Empty.getDefaultInstance());
// set at least one field to ensure the size is non-zero.
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setSize(1)).build();
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel).withMaxOutboundMessageSize(request.getSerializedSize() - 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");
}
}
use of io.grpc.StatusRuntimeException in project grpc-java by grpc.
the class AbstractInteropTest method deadlineExceeded.
@Test(timeout = 10000)
public void deadlineExceeded() {
// warm up the channel and JVM
blockingStub.emptyCall(Empty.getDefaultInstance());
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel).withDeadlineAfter(10, TimeUnit.MILLISECONDS);
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setIntervalUs(20000)).build();
try {
stub.streamingOutputCall(request).next();
fail("Expected deadline to be exceeded");
} catch (StatusRuntimeException ex) {
assertEquals(Status.DEADLINE_EXCEEDED.getCode(), ex.getStatus().getCode());
}
if (metricsExpected()) {
assertMetrics("grpc.testing.TestService/EmptyCall", Status.Code.OK);
assertClientMetrics("grpc.testing.TestService/StreamingOutputCall", Status.Code.DEADLINE_EXCEEDED);
// Do not check server-side metrics, because the status on the server side is undetermined.
}
}
use of io.grpc.StatusRuntimeException in project grpc-java by grpc.
the class AbstractInteropTest method maxInboundSize_tooBig.
@Test(timeout = 10000)
public void maxInboundSize_tooBig() {
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder().addResponseParameters(ResponseParameters.newBuilder().setSize(1)).build();
int size = blockingStub.streamingOutputCall(request).next().getSerializedSize();
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel).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.INTERNAL);
assertThat(Throwables.getStackTraceAsString(ex)).contains("exceeds maximum");
}
}
use of io.grpc.StatusRuntimeException in project grpc-java by grpc.
the class CompressingHelloWorldClient method greet.
/** Say hello to server. */
public void greet(String name) {
logger.info("Will try to greet " + name + " ...");
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloReply response;
try {
// This enables compression for requests. Independent of this setting, servers choose whether
// to compress responses.
response = blockingStub.withCompression("gzip").sayHello(request);
} catch (StatusRuntimeException e) {
logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
return;
}
logger.info("Greeting: " + response.getMessage());
}
use of io.grpc.StatusRuntimeException in project grpc-java by grpc.
the class CustomHeaderClient method greet.
/**
* A simple client method that like {@link io.grpc.examples.helloworld.HelloWorldClient}.
*/
private void greet(String name) {
logger.info("Will try to greet " + name + " ...");
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloReply response;
try {
response = blockingStub.sayHello(request);
} catch (StatusRuntimeException e) {
logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
return;
}
logger.info("Greeting: " + response.getMessage());
}
Aggregations