use of io.grpc.StatusException in project grpc-java by grpc.
the class OkHttpClientTransportTest method ping_failsIfTransportFails.
@Test
public void ping_failsIfTransportFails() throws Exception {
initTransport();
PingCallbackImpl callback = new PingCallbackImpl();
clientTransport.ping(callback, MoreExecutors.directExecutor());
assertEquals(0, callback.invocationCount);
clientTransport.onException(new IOException());
// ping failed on error
assertEquals(1, callback.invocationCount);
assertTrue(callback.failureCause instanceof StatusException);
assertEquals(Status.Code.UNAVAILABLE, ((StatusException) callback.failureCause).getStatus().getCode());
// now that handler is in terminal state, all future pings fail immediately
callback = new PingCallbackImpl();
clientTransport.ping(callback, MoreExecutors.directExecutor());
assertEquals(1, callback.invocationCount);
assertTrue(callback.failureCause instanceof StatusException);
assertEquals(Status.Code.UNAVAILABLE, ((StatusException) callback.failureCause).getStatus().getCode());
shutdownAndVerify();
}
use of 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 io.grpc.StatusException in project grpc-java by grpc.
the class NettyClientTransportTest method maxHeaderListSizeShouldBeEnforcedOnClient.
@Test
public void maxHeaderListSizeShouldBeEnforcedOnClient() throws Exception {
startServer();
NettyClientTransport transport = newTransport(newNegotiator(), DEFAULT_MAX_MESSAGE_SIZE, 1, null, true);
callMeMaybe(transport.start(clientTransportListener));
try {
// Send a single RPC and wait for the response.
new Rpc(transport, new Metadata()).halfClose().waitForResponse();
fail("The stream should have been failed due to client received header exceeds header list" + " size limit!");
} catch (Exception e) {
Throwable rootCause = getRootCause(e);
Status status = ((StatusException) rootCause).getStatus();
assertEquals(Status.Code.INTERNAL, status.getCode());
assertEquals("HTTP/2 error code: PROTOCOL_ERROR\nReceived Rst Stream", status.getDescription());
}
}
use of 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 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