use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project dubbo by alibaba.
the class GrpcInvoker method getErrorCode.
/**
* FIXME, convert gRPC exceptions to equivalent Dubbo exceptions.
*
* @param e
* @return
*/
private int getErrorCode(Throwable e) {
if (e instanceof StatusException) {
StatusException statusException = (StatusException) e;
Status status = statusException.getStatus();
if (status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
return RpcException.TIMEOUT_EXCEPTION;
}
}
return RpcException.UNKNOWN_EXCEPTION;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class HealthStatusManagerTest method notFoundForClearedStatus.
@Test
public void notFoundForClearedStatus() throws Exception {
//setup
manager.setStatus("", status);
manager.clearStatus("");
HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("").build();
@SuppressWarnings("unchecked") StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);
//test
health.check(request, observer);
//verify
ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
verify(observer, times(1)).onError(exception.capture());
assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
verify(observer, never()).onCompleted();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class HealthServiceImpl method check.
@Override
public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) {
ServingStatus status = getStatus(request.getService());
if (status == null) {
responseObserver.onError(new StatusException(Status.NOT_FOUND));
} else {
HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project google-cloud-java by GoogleCloudPlatform.
the class PublisherImplTest method testPublishFailureRetries_nonRetryableFailsImmediately.
@Test(expected = ExecutionException.class)
public void testPublishFailureRetries_nonRetryableFailsImmediately() throws Exception {
Publisher publisher = getTestPublisherBuilder().setExecutorProvider(SINGLE_THREAD_EXECUTOR).setRetrySettings(Publisher.Builder.DEFAULT_RETRY_SETTINGS.toBuilder().setTotalTimeout(Duration.ofSeconds(10)).build()).setBatchingSettings(Publisher.Builder.DEFAULT_BATCHING_SETTINGS.toBuilder().setElementCountThreshold(1L).setDelayThreshold(Duration.ofSeconds(5)).build()).build();
testPublisherServiceImpl.addPublishError(new StatusException(Status.INVALID_ARGUMENT));
ApiFuture<String> publishFuture1 = sendTestMessage(publisher, "A");
try {
publishFuture1.get();
} finally {
assertTrue(testPublisherServiceImpl.getCapturedRequests().size() >= 1);
publisher.shutdown();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project google-cloud-java by GoogleCloudPlatform.
the class SubscriberTest method testFailedChannel_fatalError_subscriberFails.
@Test(expected = IllegalStateException.class)
public void testFailedChannel_fatalError_subscriberFails() throws Exception {
if (!isStreamingTest) {
// This test is not applicable to polling.
throw new IllegalStateException("To fullfil test expectation");
}
Subscriber subscriber = startSubscriber(getTestSubscriberBuilder(testReceiver).setExecutorProvider(InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(10).build()));
// Fatal error
fakeSubscriberServiceImpl.sendError(new StatusException(Status.INVALID_ARGUMENT));
try {
subscriber.awaitTerminated();
} finally {
// The subscriber must finish with an state error because its FAILED status.
assertEquals(Subscriber.State.FAILED, subscriber.state());
assertEquals(Status.INVALID_ARGUMENT, ((StatusRuntimeException) subscriber.failureCause()).getStatus());
}
}
Aggregations