Search in sources :

Example 71 with StatusRuntimeException

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

the class Complete method execute.

@Override
public void execute(Context context) {
    BStruct connectionStruct = (BStruct) context.getRefArgument(0);
    StreamObserver requestSender = (StreamObserver) connectionStruct.getNativeData(REQUEST_SENDER);
    if (requestSender == null) {
        context.setError(MessageUtils.getConnectorError(context, new StatusRuntimeException(Status.fromCode(Status.INTERNAL.getCode()).withDescription("Error while initializing connector. " + "response sender doesnot exist"))));
    } else {
        try {
            requestSender.onCompleted();
        } catch (Throwable e) {
            LOG.error("Error while sending client response.", e);
            context.setError(MessageUtils.getConnectorError(context, e));
        }
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BStruct(org.ballerinalang.model.values.BStruct) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 72 with StatusRuntimeException

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

the class ErrorResponse method execute.

@Override
public void execute(Context context) {
    BStruct connectionStruct = (BStruct) context.getRefArgument(0);
    BValue responseValue = context.getRefArgument(1);
    if (responseValue instanceof BStruct) {
        BStruct responseStruct = (BStruct) responseValue;
        int statusCode = Integer.parseInt(String.valueOf(responseStruct.getIntField(0)));
        String errorMsg = responseStruct.getStringField(0);
        StreamObserver requestSender = (StreamObserver) connectionStruct.getNativeData(REQUEST_SENDER);
        if (requestSender == null) {
            context.setError(MessageUtils.getConnectorError(context, new StatusRuntimeException(Status.fromCode(Status.INTERNAL.getCode()).withDescription("Error while sending the error. Response" + " observer not found."))));
        } else {
            requestSender.onError(new StatusRuntimeException(Status.fromCodeValue(statusCode).withDescription(errorMsg)));
        }
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 73 with StatusRuntimeException

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

the class DgraphClientTest method testClientWithDeadline.

@Test
public void testClientWithDeadline() throws Exception {
    ManagedChannel channel = ManagedChannelBuilder.forAddress(TEST_HOSTNAME, TEST_PORT).usePlaintext(true).build();
    DgraphGrpc.DgraphBlockingStub blockingStub = DgraphGrpc.newBlockingStub(channel);
    dgraphClient = new DgraphClient(Collections.singletonList(blockingStub), 1);
    Operation op = Operation.newBuilder().setSchema("name: string @index(exact) @upsert .").build();
    // Alters schema without exceeding the given deadline.
    dgraphClient.alter(op);
    // Creates a blocking stub directly, in order to force a deadline to be exceeded.
    Method method = DgraphClient.class.getDeclaredMethod("anyClient");
    method.setAccessible(true);
    DgraphGrpc.DgraphBlockingStub client = (DgraphGrpc.DgraphBlockingStub) method.invoke(dgraphClient);
    Thread.sleep(1001);
    try {
        client.alter(op);
        fail("Deadline should have been exceeded");
    } catch (StatusRuntimeException sre) {
    // Expected.
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 74 with StatusRuntimeException

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

the class TestReadRowsHelper method testRetryOfSingleFailure.

@Test
void testRetryOfSingleFailure() {
    MockResponsesBatch batch1 = new MockResponsesBatch();
    batch1.addResponse(Storage.ReadRowsResponse.newBuilder().setRowCount(10).build());
    batch1.addException(new StatusRuntimeException(Status.INTERNAL.withDescription("Received unexpected EOS on DATA frame from server.")));
    MockResponsesBatch batch2 = new MockResponsesBatch();
    batch2.addResponse(Storage.ReadRowsResponse.newBuilder().setRowCount(11).build());
    ImmutableList<Storage.ReadRowsResponse> responses = ImmutableList.copyOf(new MockReadRowsHelper(client, request, 3, ImmutableList.of(batch1, batch2)).readRows());
    assertThat(responses.size()).isEqualTo(2);
    assertThat(responses.stream().mapToLong(Storage.ReadRowsResponse::getRowCount).sum()).isEqualTo(21);
}
Also used : Storage(com.google.cloud.bigquery.storage.v1beta1.Storage) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.testng.annotations.Test)

Example 75 with StatusRuntimeException

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

the class ClusterPointController method request.

private CheckConnectionStatusResult request(GrpcAgentConnection grpcAgentConnection, int checkCount) {
    logger.info("Ping  message will be sent. collector => {}.", grpcAgentConnection.getDestAgentInfo().getAgentKey());
    Future<ResponseMessage> response = null;
    try {
        response = request0(grpcAgentConnection, checkCount);
    } catch (StatusRuntimeException e) {
        logger.warn("Exception occurred while request message. message:{}", e.getMessage(), e);
        if (e.getStatus().getCode() == Status.CANCELLED.getCode()) {
            clearConnection(grpcAgentConnection);
            return CheckConnectionStatusResult.FAIL_AND_CLEAR_CONNECTION;
        }
        return CheckConnectionStatusResult.FAIL;
    } catch (PinpointSocketException e) {
        logger.warn("Exception occurred while request message. message:{}", e.getMessage(), e);
        clearConnection(grpcAgentConnection);
        return CheckConnectionStatusResult.FAIL_AND_CLEAR_CONNECTION;
    }
    if (!response.isSuccess()) {
        Throwable cause = response.getCause();
        logger.warn("Failed while request message. message:{}", cause.getMessage(), cause);
        return CheckConnectionStatusResult.FAIL;
    }
    try {
        ResponseMessage result = response.getResult();
        Message<TBase<?, ?>> deserialize = tBaseDeserializer.deserialize(result.getMessage());
        TBase<?, ?> data = deserialize.getData();
        if (data instanceof TCommandEcho) {
            if (CONNECTION_CHECK_COMMAND.getMessage().equals(((TCommandEcho) data).getMessage())) {
                return CheckConnectionStatusResult.SUCCESS;
            }
        }
        logger.warn("Receive unexpected response data.  data:{}", data);
    } catch (Exception e) {
        logger.warn("Exception occurred while handles response message. message:{}", e.getMessage(), e);
    }
    return CheckConnectionStatusResult.FAIL;
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho) TBase(org.apache.thrift.TBase) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StatusRuntimeException(io.grpc.StatusRuntimeException)

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