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);
}
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);
}
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);
}
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);
}
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());
}
}
Aggregations