Search in sources :

Example 16 with StatusRuntimeException

use of 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 17 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project core-java by SpineEventEngine.

the class ValidationFilter method reportMissingTenantId.

private void reportMissingTenantId(Command command, StreamObserver<Response> responseObserver) {
    final CommandException noTenantDefined = InvalidCommandException.onMissingTenantId(command);
    commandBus.commandStore().storeWithError(command, noTenantDefined);
    final StatusRuntimeException exception = invalidArgumentWithCause(noTenantDefined, noTenantDefined.getError());
    responseObserver.onError(exception);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 18 with StatusRuntimeException

use of 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, cause.getError());
    responseObserver.onError(validationException);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 19 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project beam by apache.

the class BigtableServiceImpl method tableExists.

@Override
public boolean tableExists(String tableId) throws IOException {
    try (BigtableSession session = new BigtableSession(options)) {
        GetTableRequest getTable = GetTableRequest.newBuilder().setName(options.getInstanceName().toTableNameStr(tableId)).build();
        session.getTableAdminClient().getTable(getTable);
        return true;
    } catch (StatusRuntimeException e) {
        if (e.getStatus().getCode() == Code.NOT_FOUND) {
            return false;
        }
        String message = String.format("Error checking whether table %s (BigtableOptions %s) exists", tableId, options);
        LOG.error(message, e);
        throw new IOException(message, e);
    }
}
Also used : GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException)

Example 20 with StatusRuntimeException

use of 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)

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