Search in sources :

Example 36 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpannerExceptionFactoryTest method abortWithoutRetryInfo.

@Test
public void abortWithoutRetryInfo() {
    Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
    SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status));
    assertThat(e).isInstanceOf(AbortedException.class);
    assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(-1L);
}
Also used : Status(io.grpc.Status) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 37 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class VideoIntelligenceServiceClientTest method annotateVideoExceptionTest.

@Test
@SuppressWarnings("all")
public void annotateVideoExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockVideoIntelligenceService.addException(exception);
    try {
        String inputUri = "inputUri1707300727";
        List<Feature> features = new ArrayList<>();
        VideoContext videoContext = VideoContext.newBuilder().build();
        String outputUri = "outputUri-1273518802";
        String locationId = "locationId552319461";
        client.annotateVideoAsync(inputUri, features, videoContext, outputUri, locationId).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(ApiException.class, e.getCause().getClass());
        ApiException apiException = (ApiException) e.getCause();
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), apiException.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) VideoContext(com.google.cloud.videointelligence.v1beta1.VideoContext) ExecutionException(java.util.concurrent.ExecutionException) Feature(com.google.cloud.videointelligence.v1beta1.Feature) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 38 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventExceptionTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockReportErrorsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
        client.reportErrorEvent(projectName, event);
        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) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 39 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method deleteGroupExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteGroupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
        client.deleteGroup(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : GroupName(com.google.monitoring.v3.GroupName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 40 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method listGroupMembersExceptionTest.

@Test
@SuppressWarnings("all")
public void listGroupMembersExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
        client.listGroupMembers(name);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : GroupName(com.google.monitoring.v3.GroupName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6