Search in sources :

Example 41 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeEntitiesExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeEntitiesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeEntities(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 42 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSyntaxExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSyntaxExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeSyntax(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1.EncodingType) Document(com.google.cloud.language.v1.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 43 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSentimentExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSentimentExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        client.analyzeSentiment(document);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Document(com.google.cloud.language.v1.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 44 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class TransactionRunnerImplTest method runAbortNoRetryInfo.

@Test
public void runAbortNoRetryInfo() {
    runTransaction(new StatusRuntimeException(Status.fromCodeValue(Status.Code.ABORTED.value())));
    ArgumentCaptor<Long> backoffMillis = ArgumentCaptor.forClass(Long.class);
    verify(sleeper, times(1)).backoffSleep(Mockito.<Context>any(), backoffMillis.capture());
    assertThat(backoffMillis.getValue()).isGreaterThan(0L);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 45 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpannerExceptionFactoryTest method connectionClosedIsRetryable.

@Test
public void connectionClosedIsRetryable() {
    Status status = Status.fromCodeValue(Status.Code.INTERNAL.value()).withDescription("Connection closed with unknown cause");
    SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status));
    assertThat(e.isRetryable()).isTrue();
}
Also used : Status(io.grpc.Status) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)131 Test (org.junit.Test)110 ApiException (com.google.api.gax.grpc.ApiException)74 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 ArrayList (java.util.ArrayList)11 Metadata (io.grpc.Metadata)10 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 StreamObserver (io.grpc.stub.StreamObserver)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 HelloReply (io.grpc.examples.helloworld.HelloReply)4 HelloRequest (io.grpc.examples.helloworld.HelloRequest)4