Search in sources :

Example 91 with StatusRuntimeException

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

the class HelloWorldClientTls 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 {
        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)

Example 92 with StatusRuntimeException

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

the class XdsHelloWorldClient 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 {
        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)

Example 93 with StatusRuntimeException

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

the class GoogleAuthClient method getTopics.

/**
 * Get topics (max 10) for our project ID: the topic list is logged to the logger.
 *
 * @param projectID  the GCP project ID to get the pubsub topics for. This is a string like
 *                   "projects/balmy-cirrus-225307" where "balmy-cirrus-225307" is
 *                   the project ID for the project you created.
 */
public void getTopics(String projectID) {
    logger.log(Level.INFO, "Will try to get topics for project {0} ...", projectID);
    ListTopicsRequest request = ListTopicsRequest.newBuilder().setPageSize(// get max 10 topics
    10).setProject(// for our projectID
    projectID).build();
    ListTopicsResponse response;
    try {
        response = blockingStub.listTopics(request);
    } catch (StatusRuntimeException e) {
        logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
        return;
    }
    logger.log(Level.INFO, "Topics list:\n {0}", response.getTopicsList());
}
Also used : ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse)

Example 94 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.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 95 with StatusRuntimeException

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

the class RouteGuideClientTest method getFeature_error.

/**
 * Example for testing blocking unary call.
 */
@Test
public void getFeature_error() {
    Point requestPoint = Point.newBuilder().setLatitude(-1).setLongitude(-1).build();
    final AtomicReference<Point> pointDelivered = new AtomicReference<Point>();
    final StatusRuntimeException fakeError = new StatusRuntimeException(Status.DATA_LOSS);
    // implement the fake service
    RouteGuideImplBase getFeatureImpl = new RouteGuideImplBase() {

        @Override
        public void getFeature(Point point, StreamObserver<Feature> responseObserver) {
            pointDelivered.set(point);
            responseObserver.onError(fakeError);
        }
    };
    serviceRegistry.addService(getFeatureImpl);
    client.getFeature(-1, -1);
    assertEquals(requestPoint, pointDelivered.get());
    ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
    verify(testHelper).onRpcError(errorCaptor.capture());
    assertEquals(fakeError.getStatus(), Status.fromThrowable(errorCaptor.getValue()));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) StatusRuntimeException(io.grpc.StatusRuntimeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) RouteGuideImplBase(io.grpc.examples.routeguide.RouteGuideGrpc.RouteGuideImplBase) 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