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));
}
}
}
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)));
}
}
}
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.
}
}
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);
}
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;
}
Aggregations