Search in sources :

Example 26 with StatusException

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;
}
Also used : Status(io.grpc.Status) StatusException(io.grpc.StatusException)

Example 27 with StatusException

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();
}
Also used : StatusException(io.grpc.StatusException) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.Test)

Example 28 with StatusException

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();
    }
}
Also used : StatusException(io.grpc.StatusException) ServingStatus(io.grpc.health.v1.HealthCheckResponse.ServingStatus) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse)

Example 29 with StatusException

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();
    }
}
Also used : StatusException(io.grpc.StatusException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 30 with StatusException

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());
    }
}
Also used : StatusException(io.grpc.StatusException) Test(org.junit.Test)

Aggregations

StatusException (io.grpc.StatusException)45 Test (org.junit.Test)20 Status (io.grpc.Status)9 IOException (java.io.IOException)9 StatusException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)9 ExecutionException (java.util.concurrent.ExecutionException)8 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)6 Metadata (io.grpc.Metadata)6 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)5 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)4 TrackingObjectPoolForTest (io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest)4 TimeoutException (java.util.concurrent.TimeoutException)4 StatusRuntimeException (io.grpc.StatusRuntimeException)3 InetSocketAddress (java.net.InetSocketAddress)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)2 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)2 PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)2