Search in sources :

Example 56 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method deleteEventsExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteEventsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorStatsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        client.deleteEvents(projectName);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 57 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listEventsExceptionTest.

@Test
@SuppressWarnings("all")
public void listEventsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorStatsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        String groupId = "groupId506361563";
        client.listEvents(projectName, groupId);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 58 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class ErrorStatsServiceClientTest method listGroupStatsExceptionTest.

@Test
@SuppressWarnings("all")
public void listGroupStatsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockErrorStatsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
        client.listGroupStats(projectName, timeRange);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) QueryTimeRange(com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 59 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method syncRecognizeExceptionTest.

@Test
@SuppressWarnings("all")
public void syncRecognizeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSpeech.addException(exception);
    try {
        RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
        int sampleRate = 44100;
        RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(encoding).setSampleRate(sampleRate).build();
        String uri = "gs://bucket_name/file_name.flac";
        RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();
        client.syncRecognize(config, audio);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : RecognitionAudio(com.google.cloud.speech.v1beta1.RecognitionAudio) AudioEncoding(com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding) StatusRuntimeException(io.grpc.StatusRuntimeException) RecognitionConfig(com.google.cloud.speech.v1beta1.RecognitionConfig) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 60 with ApiException

use of com.google.api.gax.grpc.ApiException in project google-cloud-java by GoogleCloudPlatform.

the class BaseGrpcServiceExceptionTest method testBaseServiceException.

@Test
public void testBaseServiceException() {
    BaseGrpcServiceException serviceException = null;
    IOException exception = new SocketTimeoutException();
    serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT);
    assertTrue(serviceException.isRetryable());
    assertNull(serviceException.getMessage());
    assertEquals(exception, serviceException.getCause());
    assertNull(serviceException.getReason());
    assertNull(serviceException.getLocation());
    assertNull(serviceException.getDebugInfo());
    exception = new SocketException();
    serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT);
    assertTrue(serviceException.isRetryable());
    assertNull(serviceException.getMessage());
    assertEquals(exception, serviceException.getCause());
    assertNull(serviceException.getReason());
    assertNull(serviceException.getLocation());
    assertNull(serviceException.getDebugInfo());
    exception = new IOException("insufficient data written");
    serviceException = new BaseGrpcServiceException(exception, IDEMPOTENT);
    assertTrue(serviceException.isRetryable());
    assertEquals("insufficient data written", serviceException.getMessage());
    assertEquals(exception, serviceException.getCause());
    assertNull(serviceException.getReason());
    assertNull(serviceException.getLocation());
    assertNull(serviceException.getDebugInfo());
    Exception cause = new IllegalArgumentException("bad arg");
    ApiException apiException = new ApiException(MESSAGE, cause, Code.INTERNAL, NOT_RETRYABLE);
    serviceException = new BaseGrpcServiceException(apiException);
    assertFalse(serviceException.isRetryable());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(apiException, serviceException.getCause());
    assertEquals(Code.INTERNAL.value(), serviceException.getCode());
    assertEquals(Code.INTERNAL.name(), serviceException.getReason());
    assertNull(serviceException.getLocation());
    assertNull(serviceException.getDebugInfo());
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) BaseServiceException(com.google.cloud.BaseServiceException) ApiException(com.google.api.gax.grpc.ApiException) IOException(java.io.IOException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

ApiException (com.google.api.gax.grpc.ApiException)75 Test (org.junit.Test)75 StatusRuntimeException (io.grpc.StatusRuntimeException)74 ByteString (com.google.protobuf.ByteString)9 ArrayList (java.util.ArrayList)9 SubscriptionName (com.google.pubsub.v1.SubscriptionName)8 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)4 EncodingType (com.google.cloud.language.v1.EncodingType)3 MetricNameOneof (com.google.logging.v2.MetricNameOneof)3 SinkNameOneof (com.google.logging.v2.SinkNameOneof)3 GroupName (com.google.monitoring.v3.GroupName)3 ProjectName (com.google.pubsub.v1.ProjectName)3 ExecutionException (java.util.concurrent.ExecutionException)3 RecognitionAudio (com.google.cloud.speech.v1.RecognitionAudio)2