Search in sources :

Example 6 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.

the class ProtoUtilsTest method testJsonIoException.

@Test
public void testJsonIoException() throws Exception {
    Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
    final IOException ioe = new IOException();
    try {
        marshaller.parse(new ByteArrayInputStream("{}".getBytes("UTF-8")) {

            @Override
            public void close() throws IOException {
                throw ioe;
            }
        });
        fail("Exception expected");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
        assertEquals(ioe, ex.getCause());
    }
}
Also used : Type(com.google.protobuf.Type) ByteArrayInputStream(java.io.ByteArrayInputStream) StatusRuntimeException(io.grpc.StatusRuntimeException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.

the class ThriftUtilsTest method parseInvalid.

@Test
public void parseInvalid() throws Exception {
    InputStream is = new ByteArrayInputStream(new byte[] { -127 });
    try {
        marshaller.parse(is);
        fail("Expected exception");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
        assertTrue(ex.getCause() instanceof TException);
    }
}
Also used : TException(org.apache.thrift.TException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 8 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project core-java by SpineEventEngine.

the class RequestValidator method feedToResponse.

private static void feedToResponse(InvalidRequestException cause, StreamObserver<?> responseObserver) {
    final StatusRuntimeException validationException = invalidArgumentWithCause(cause);
    responseObserver.onError(validationException);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 9 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method getIamPolicyExceptionTest.

@Test
@SuppressWarnings("all")
public void getIamPolicyExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockIAMPolicy.addException(exception);
    try {
        String formattedResource = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]").toString();
        client.getIamPolicy(formattedResource);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 10 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method pullExceptionTest.

@Test
@SuppressWarnings("all")
public void pullExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
        boolean returnImmediately = false;
        int maxMessages = 496131527;
        client.pull(subscription, returnImmediately, maxMessages);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6