Search in sources :

Example 1 with StatusRuntimeException

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");
    }
}
Also used : Status(io.grpc.Status) EchoStatus(io.grpc.testing.integration.Messages.EchoStatus) StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) Test(org.junit.Test)

Example 2 with StatusRuntimeException

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.
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) Test(org.junit.Test)

Example 3 with StatusRuntimeException

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");
    }
}
Also used : Status(io.grpc.Status) EchoStatus(io.grpc.testing.integration.Messages.EchoStatus) StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingOutputCallRequest(io.grpc.testing.integration.Messages.StreamingOutputCallRequest) Test(org.junit.Test)

Example 4 with StatusRuntimeException

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());
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloReply(io.grpc.examples.helloworld.HelloReply)

Example 5 with StatusRuntimeException

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());
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloReply(io.grpc.examples.helloworld.HelloReply)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)125 Test (org.junit.Test)108 ApiException (com.google.api.gax.grpc.ApiException)74 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 ArrayList (java.util.ArrayList)11 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 Metadata (io.grpc.Metadata)7 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 StreamObserver (io.grpc.stub.StreamObserver)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 ExecutionException (java.util.concurrent.ExecutionException)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 HelloReply (io.grpc.examples.helloworld.HelloReply)4 HelloRequest (io.grpc.examples.helloworld.HelloRequest)4 IOException (java.io.IOException)4