Search in sources :

Example 11 with Money

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

the class ProtoOperationTransformersTest method testResponseTransformer.

@Test
public void testResponseTransformer() {
    ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
    Money inputMoney = Money.newBuilder().setCurrencyCode("UAH").build();
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("Madrid").setMetadata(2).setDone(true).setResponse(inputMoney).setError(0, "no error").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)

Example 12 with Money

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

the class HttpJsonDirectServerStreamingCallableTest method testBlockingServerStreaming.

@Test
public void testBlockingServerStreaming() {
    MOCK_SERVICE.addResponse(new Money[] { DEFAULT_RESPONSE });
    Color request = Color.newBuilder().setRed(0.5f).build();
    ServerStream<Money> response = streamingCallable.call(request);
    List<Money> responseData = Lists.newArrayList(response);
    Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
    Truth.assertThat(responseData).containsExactly(expected);
}
Also used : Money(com.google.type.Money) Color(com.google.type.Color) Test(org.junit.Test)

Example 13 with Money

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

the class GrpcClientCallsTest method testTimeoutBeforeDeadline.

@Test
public void testTimeoutBeforeDeadline() {
    MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE;
    @SuppressWarnings("unchecked") ClientCall<Color, Money> mockClientCall = Mockito.mock(ClientCall.class);
    @SuppressWarnings("unchecked") ClientCall.Listener<Money> mockListener = Mockito.mock(ClientCall.Listener.class);
    Channel mockChannel = Mockito.mock(ManagedChannel.class);
    ArgumentCaptor<CallOptions> capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class);
    Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())).thenReturn(mockClientCall);
    // Configure a timeout that occurs before the grpc deadline
    Duration timeout = Duration.ofSeconds(5);
    Deadline subsequentDeadline = Deadline.after(10, TimeUnit.SECONDS);
    Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
    GrpcCallContext context = GrpcCallContext.createDefault().withChannel(mockChannel).withCallOptions(CallOptions.DEFAULT.withDeadline(subsequentDeadline)).withTimeout(timeout);
    GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata());
    // Verify that the timeout is ignored
    Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
    Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
    Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}
Also used : Color(com.google.type.Color) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Deadline(io.grpc.Deadline) Metadata(io.grpc.Metadata) Duration(org.threeten.bp.Duration) CallOptions(io.grpc.CallOptions) Money(com.google.type.Money) ClientCall(io.grpc.ClientCall) Test(org.junit.Test)

Example 14 with Money

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

the class GrpcClientCallsTest method testTimeoutToDeadlineConversion.

@Test
public void testTimeoutToDeadlineConversion() {
    MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE;
    @SuppressWarnings("unchecked") ClientCall<Color, Money> mockClientCall = Mockito.mock(ClientCall.class);
    @SuppressWarnings("unchecked") ClientCall.Listener<Money> mockListener = Mockito.mock(ClientCall.Listener.class);
    Channel mockChannel = Mockito.mock(ManagedChannel.class);
    ArgumentCaptor<CallOptions> capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class);
    Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())).thenReturn(mockClientCall);
    Duration timeout = Duration.ofSeconds(10);
    Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
    GrpcCallContext context = GrpcCallContext.createDefault().withChannel(mockChannel).withTimeout(timeout);
    GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata());
    Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
    Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
    Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}
Also used : Color(com.google.type.Color) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Deadline(io.grpc.Deadline) Metadata(io.grpc.Metadata) Duration(org.threeten.bp.Duration) CallOptions(io.grpc.CallOptions) Money(com.google.type.Money) ClientCall(io.grpc.ClientCall) Test(org.junit.Test)

Example 15 with Money

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

the class CreateDataLabelingJobVideoSample method createDataLabelingJobVideo.

static void createDataLabelingJobVideo(String project, String displayName, String datasetId, String instructionUri, String annotationSpec) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
        Value.Builder annotationSpecValue = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, annotationSpecValue);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri("gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/" + "video_classification.yaml").addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
        DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
        System.out.println("Create Data Labeling Job Video Response");
        System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
        System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
        System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
        System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
        System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
        System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
        System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
        System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
        System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
        System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
        System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
        for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
            System.out.println("\tAnnotation Level");
            System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
            System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
        }
        Money money = dataLabelingJobResponse.getCurrentSpend();
        System.out.println("\tCurrent Spend");
        System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
        System.out.format("\t\tUnits: %s\n", money.getUnits());
        System.out.format("\t\tNanos: %s\n", money.getNanos());
    }
}
Also used : Money(com.google.type.Money) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) Map(java.util.Map) LocationName(com.google.cloud.aiplatform.v1.LocationName)

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