Search in sources :

Example 6 with Money

use of com.google.type.Money in project gax-java by googleapis.

the class GrpcDirectStreamingCallableTest method testBidiStreaming.

@Test
public void testBidiStreaming() throws Exception {
    BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable(GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE), null, clientContext);
    CountDownLatch latch = new CountDownLatch(1);
    GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
    Color request = Color.newBuilder().setRed(0.5f).build();
    ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
    stream.send(request);
    stream.closeSend();
    latch.await(20, TimeUnit.SECONDS);
    assertThat(moneyObserver.error).isNull();
    Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
    assertThat(moneyObserver.response).isEqualTo(expected);
    assertThat(moneyObserver.completed).isTrue();
}
Also used : Money(com.google.type.Money) Color(com.google.type.Color) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with Money

use of com.google.type.Money in project gax-java by googleapis.

the class GrpcDirectStreamingCallableTest method testBidiStreamingServerError.

@Test
public void testBidiStreamingServerError() throws Exception {
    BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable(GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE_ERROR), null, clientContext);
    CountDownLatch latch = new CountDownLatch(1);
    GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
    Color request = Color.newBuilder().setRed(0.5f).build();
    ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
    stream.send(request);
    latch.await(20, TimeUnit.SECONDS);
    assertThat(moneyObserver.error).isNotNull();
    assertThat(moneyObserver.error).isInstanceOf(ApiException.class);
    assertThat(moneyObserver.error.getCause()).isInstanceOf(StatusRuntimeException.class);
    assertThat(((StatusRuntimeException) moneyObserver.error.getCause()).getStatus()).isEqualTo(Status.INVALID_ARGUMENT);
    assertThat(moneyObserver.response).isNull();
}
Also used : Money(com.google.type.Money) Color(com.google.type.Color) StatusRuntimeException(io.grpc.StatusRuntimeException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 8 with Money

use of com.google.type.Money in project gax-java by googleapis.

the class GrpcDirectStreamingCallableTest method testClientStreaming.

@Test
public void testClientStreaming() throws Exception {
    ClientStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createClientStreamingCallable(GrpcCallSettings.create(METHOD_CLIENT_STREAMING_RECOGNIZE), null, clientContext);
    CountDownLatch latch = new CountDownLatch(1);
    MoneyObserver moneyObserver = new MoneyObserver(latch);
    Color request = Color.newBuilder().setRed(0.5f).build();
    ApiStreamObserver<Color> requestObserver = streamingCallable.clientStreamingCall(moneyObserver);
    requestObserver.onNext(request);
    requestObserver.onCompleted();
    latch.await(20, TimeUnit.SECONDS);
    assertThat(moneyObserver.error).isNull();
    Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
    assertThat(moneyObserver.response).isEqualTo(expected);
    assertThat(moneyObserver.completed).isTrue();
}
Also used : Money(com.google.type.Money) Color(com.google.type.Color) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 9 with Money

use of com.google.type.Money in project gax-java by googleapis.

the class ProtoOperationTransformersTest method testAnyResponseTransformer_mismatchedTypes.

@Test
public void testAnyResponseTransformer_mismatchedTypes() {
    ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
    Status status = Status.newBuilder().setCode(Code.OK.getNumber()).build();
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(Color.getDefaultInstance())).setError(status).build());
    Exception exception = assertThrows(UnknownException.class, () -> transformer.apply(operationSnapshot));
    Truth.assertThat(exception).hasMessageThat().contains("encountered a problem unpacking it");
}
Also used : Status(com.google.rpc.Status) Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) UnknownException(com.google.api.gax.rpc.UnknownException) UnavailableException(com.google.api.gax.rpc.UnavailableException) Test(org.junit.Test)

Example 10 with Money

use of com.google.type.Money in project gax-java by googleapis.

the class ProtoOperationTransformersTest method testAnyMetadataTransformer.

@Test
public void testAnyMetadataTransformer() {
    MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
    Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build());
    Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
}
Also used : Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Test(org.junit.Test)

Aggregations

Money (com.google.type.Money)35 Test (org.junit.Test)28 Color (com.google.type.Color)19 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)13 ManagedChannel (io.grpc.ManagedChannel)8 UnavailableException (com.google.api.gax.rpc.UnavailableException)6 UnknownException (com.google.api.gax.rpc.UnknownException)6 Status (com.google.rpc.Status)6 Metadata (io.grpc.Metadata)6 CallOptions (io.grpc.CallOptions)5 Channel (io.grpc.Channel)5 ClientCall (io.grpc.ClientCall)4 DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)3 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)3 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)3 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)3 LocationName (com.google.cloud.aiplatform.v1.LocationName)3 Value (com.google.protobuf.Value)3 Deadline (io.grpc.Deadline)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3