Search in sources :

Example 51 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grakn by graknlabs.

the class GrpcGraknService method delete.

@Override
public void delete(DeleteRequest request, StreamObserver<DeleteResponse> responseObserver) {
    try {
        runAndConvertGraknExceptions(() -> {
            try (GraknTx tx = executor.execute(request.getOpen())) {
                tx.admin().delete();
            }
            responseObserver.onNext(GrpcUtil.deleteResponse());
            responseObserver.onCompleted();
        });
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 52 with StatusRuntimeException

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

the class HelloClient method greet.

// Call Greet Method in Hello server.
public String greet(String name) {
    StringValue stringValue = StringValue.newBuilder().setValue(name).build();
    StringValue response;
    try {
        response = blockingStub.hello(stringValue);
        log.info("gRPC >> Response Greetings : " + response);
        return response.getValue();
    } catch (StatusRuntimeException e) {
        log.error("Error sending events to blocking stub.", e);
    }
    return "";
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) StringValue(com.google.protobuf.StringValue)

Example 53 with StatusRuntimeException

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

the class TestLocationClientImpl method testLocateStorageContainersSucceedAfterRetried.

@Test
public void testLocateStorageContainersSucceedAfterRetried() throws Exception {
    serviceRegistry.removeService(locationServiceDefinition);
    final AtomicInteger retries = new AtomicInteger(3);
    StatusRuntimeException statusException = new StatusRuntimeException(Status.INTERNAL);
    StorageContainerServiceImplBase locationServiceWithFailures = new StorageContainerServiceImplBase() {

        @Override
        public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
            if (retries.decrementAndGet() == 0) {
                locationService.getStorageContainerEndpoint(request, responseObserver);
                return;
            }
            responseObserver.onError(statusException);
        }
    };
    serviceRegistry.addService(locationServiceWithFailures.bindService());
    testLocateStorageContainersSuccess();
    assertEquals(0, retries.get());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatusRuntimeException(io.grpc.StatusRuntimeException) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) Test(org.junit.Test)

Example 54 with StatusRuntimeException

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

the class FailRequestStorageContainer method failWrongGroupRequest.

private <T> CompletableFuture<T> failWrongGroupRequest(long scId) {
    CompletableFuture<T> future = FutureUtils.createFuture();
    scheduler.executeOrdered(scId, () -> {
        future.completeExceptionally(new StatusRuntimeException(Status.NOT_FOUND));
    });
    return future;
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 55 with StatusRuntimeException

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

the class TestMetaRangeClientImpl method testGetActiveStreamRangesFailure.

@Test
public void testGetActiveStreamRangesFailure() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    metaRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    MetaRangeServiceImplBase metaRangeService = new MetaRangeServiceImplBase() {

        @Override
        public void getActiveRanges(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            responseObserver.onError(new StatusRuntimeException(Status.INTERNAL));
        }
    };
    serviceRegistry.addService(metaRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    CompletableFuture<HashStreamRanges> getFuture = metaRangeClient.getActiveDataRanges();
    try {
        getFuture.get();
        fail("should fail on rpc failure");
    } catch (ExecutionException ee) {
        assertNotNull(ee.getCause());
        assertTrue(ee.getCause() instanceof StatusRuntimeException);
        StatusRuntimeException se = (StatusRuntimeException) ee.getCause();
        assertEquals(Status.INTERNAL, se.getStatus());
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) HashStreamRanges(org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) MetaRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase) 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