diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index a5aab2b27ee1..13a1cc332ba1 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -111,7 +111,7 @@ com.google.api gax - 0.0.24 + 0.0.25 io.grpc diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java index 8ec434485d72..a3305d085f3f 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Client.java @@ -39,8 +39,8 @@ // AUTO-GENERATED DOCUMENTATION AND SERVICE /** - * Service Description: Service for configuring sinks used to export log entries outside Stackdriver - * Logging. + * Service Description: Service for configuring sinks used to export log entries outside of + * Stackdriver Logging. * *

This class provides the ability to make remote calls to the backing service through method * calls that map to API methods. Sample code to get started: @@ -218,12 +218,11 @@ public final ConfigServiceV2Settings getSettings() { * } * * - * @param parent Required. The cloud resource containing the sinks. Example: - * `"projects/my-logging-project"`. + * @param parent Required. The resource name where this sink was created: + *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListSinksPagedResponse listSinks(String parent) { - PARENT_PATH_TEMPLATE.validate(parent, "listSinks"); ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent).build(); return listSinks(request); } @@ -321,12 +320,13 @@ public final UnaryCallable listSinksCallabl * } * * - * @param sinkName Required. The resource name of the sink to return. Example: - * `"projects/my-project-id/sinks/my-sink-id"`. + * @param sinkName Required. The resource name of the sink to return: + *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" + * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogSink getSink(String sinkName) { - SINK_PATH_TEMPLATE.validate(sinkName, "getSink"); + GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(sinkName).build(); return getSink(request); } @@ -390,14 +390,14 @@ public final UnaryCallable getSinkCallable() { * } * * - * @param parent Required. The resource in which to create the sink. Example: - * `"projects/my-project-id"`. The new sink must be provided in the request. + * @param parent Required. The resource in which to create the sink: + *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * @param sink Required. The new sink, whose `name` parameter is a sink identifier that is not * already in use. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogSink createSink(String parent, LogSink sink) { - PARENT_PATH_TEMPLATE.validate(parent, "createSink"); + CreateSinkRequest request = CreateSinkRequest.newBuilder().setParent(parent).setSink(sink).build(); return createSink(request); @@ -467,14 +467,16 @@ public final UnaryCallable createSinkCallable() { * * * @param sinkName Required. The resource name of the sink to update, including the parent - * resource and the sink identifier. If the sink does not exist, this method creates the sink. - * Example: `"projects/my-project-id/sinks/my-sink-id"`. + * resource and the sink identifier: + *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" + * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" + *

Example: `"projects/my-project-id/sinks/my-sink-id"`. * @param sink Required. The updated sink, whose name is the same identifier that appears as part * of `sinkName`. If `sinkName` does not exist, then this method creates a new sink. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogSink updateSink(String sinkName, LogSink sink) { - SINK_PATH_TEMPLATE.validate(sinkName, "updateSink"); + UpdateSinkRequest request = UpdateSinkRequest.newBuilder().setSinkName(sinkName).setSink(sink).build(); return updateSink(request); @@ -543,12 +545,14 @@ public final UnaryCallable updateSinkCallable() { * * * @param sinkName Required. The resource name of the sink to delete, including the parent - * resource and the sink identifier. Example: `"projects/my-project-id/sinks/my-sink-id"`. It - * is an error if the sink does not exist. + * resource and the sink identifier: + *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" + * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" + *

It is an error if the sink does not exist. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteSink(String sinkName) { - SINK_PATH_TEMPLATE.validate(sinkName, "deleteSink"); + DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(sinkName).build(); deleteSink(request); } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java index cd9ec9d59a81..47708abf8aa6 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Client.java @@ -218,7 +218,7 @@ public final LoggingServiceV2Settings getSettings() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes a log and all its log entries. The log will reappear if it receives new entries. + * Deletes all the log entries in a log. The log reappears if it receives new entries. * *

Sample code: * @@ -229,19 +229,22 @@ public final LoggingServiceV2Settings getSettings() { * } * * - * @param logName Required. The resource name of the log to delete. Example: - * `"projects/my-project/logs/syslog"`. + * @param logName Required. The resource name of the log to delete: + *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" + *

`[LOG_ID]` must be URL-encoded. For example, `"projects/my-project-id/logs/syslog"`, + * `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. For more + * information about log names, see [LogEntry][google.logging.v2.LogEntry]. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteLog(String logName) { - LOG_PATH_TEMPLATE.validate(logName, "deleteLog"); + DeleteLogRequest request = DeleteLogRequest.newBuilder().setLogName(logName).build(); deleteLog(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes a log and all its log entries. The log will reappear if it receives new entries. + * Deletes all the log entries in a log. The log reappears if it receives new entries. * *

Sample code: * @@ -264,7 +267,7 @@ private final void deleteLog(DeleteLogRequest request) { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Deletes a log and all its log entries. The log will reappear if it receives new entries. + * Deletes all the log entries in a log. The log reappears if it receives new entries. * *

Sample code: * @@ -301,8 +304,11 @@ public final UnaryCallable deleteLogCallable() { * * * @param logName Optional. A default log resource name that is assigned to all log entries in - * `entries` that do not specify a value for `log_name`. Example: - * `"projects/my-project/logs/syslog"`. See [LogEntry][google.logging.v2.LogEntry]. + * `entries` that do not specify a value for `log_name`: + *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" + *

`[LOG_ID]` must be URL-encoded. For example, `"projects/my-project-id/logs/syslog"` or + * `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. For more + * information about log names, see [LogEntry][google.logging.v2.LogEntry]. * @param resource Optional. A default monitored resource object that is assigned to all log * entries in `entries` that do not specify a value for `resource`. Example: *

{ "type": "gce_instance", "labels": { "zone": "us-central1-a", "instance_id": @@ -325,9 +331,7 @@ public final WriteLogEntriesResponse writeLogEntries( MonitoredResource resource, Map labels, List entries) { - if (!logName.isEmpty()) { - LOG_PATH_TEMPLATE.validate(logName, "writeLogEntries"); - } + WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder() .setLogName(logName) @@ -402,12 +406,13 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * } * * - * @param resourceNames Optional. One or more cloud resources from which to retrieve log entries. - * Example: `"projects/my-project-1A"`, `"projects/1234567890"`. Projects listed in - * `projectIds` are added to this list. + * @param resourceNames Required. One or more cloud resources from which to retrieve log entries: + *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" + *

Projects listed in the `project_ids` field are added to this list. * @param filter Optional. A filter that chooses which log entries to return. See [Advanced Logs * Filters](/logging/docs/view/advanced_filters). Only log entries that match the filter are - * returned. An empty filter matches all log entries. + * returned. An empty filter matches all log entries. The maximum length of the filter is + * 20000 characters. * @param orderBy Optional. How the results should be sorted. Presently, the only permitted values * are `"timestamp asc"` (default) and `"timestamp desc"`. The first option returns entries in * order of increasing values of `LogEntry.timestamp` (oldest first), and the second option diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Client.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Client.java index 9f7bac8500e3..d97e03d42cc9 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Client.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Client.java @@ -220,12 +220,11 @@ public final MetricsServiceV2Settings getSettings() { * } * * - * @param parent Required. The resource name containing the metrics. Example: - * `"projects/my-project-id"`. + * @param parent Required. The name of the project containing the metrics: + *

"projects/[PROJECT_ID]" * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final ListLogMetricsPagedResponse listLogMetrics(String parent) { - PARENT_PATH_TEMPLATE.validate(parent, "listLogMetrics"); ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(parent).build(); return listLogMetrics(request); } @@ -325,8 +324,8 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re * } * * - * @param metricName The resource name of the desired metric. Example: - * `"projects/my-project-id/metrics/my-metric-id"`. + * @param metricName The resource name of the desired metric: + *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogMetric getLogMetric(String metricName) { @@ -395,14 +394,14 @@ public final UnaryCallable getLogMetricCallable( * } * * - * @param parent The resource name of the project in which to create the metric. Example: - * `"projects/my-project-id"`. + * @param parent The resource name of the project in which to create the metric: + *

"projects/[PROJECT_ID]" *

The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that already exists. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogMetric createLogMetric(String parent, LogMetric metric) { - PARENT_PATH_TEMPLATE.validate(parent, "createLogMetric"); + CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(parent).setMetric(metric).build(); return createLogMetric(request); @@ -471,12 +470,12 @@ public final UnaryCallable createLogMetricCal * } * * - * @param metricName The resource name of the metric to update. Example: - * `"projects/my-project-id/metrics/my-metric-id"`. - *

The updated metric must be provided in the request and have the same identifier that is - * specified in `metricName`. If the metric does not exist, it is created. - * @param metric The updated metric, whose name must be the same as the metric identifier in - * `metricName`. If `metricName` does not exist, then a new metric is created. + * @param metricName The resource name of the metric to update: + *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" + *

The updated metric must be provided in the request and it's `name` field must be the + * same as `[METRIC_ID]` If the metric does not exist in `[PROJECT_ID]`, then a new metric is + * created. + * @param metric The updated metric. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final LogMetric updateLogMetric(String metricName, LogMetric metric) { @@ -548,8 +547,8 @@ public final UnaryCallable updateLogMetricCal * } * * - * @param metricName The resource name of the metric to delete. Example: - * `"projects/my-project-id/metrics/my-metric-id"`. + * @param metricName The resource name of the metric to delete: + *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ public final void deleteLogMetric(String metricName) { diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java index 107417286814..f6b160b6ed87 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java @@ -36,7 +36,7 @@ * * ===================== ConfigServiceV2Client ===================== * - *

Service Description: Service for configuring sinks used to export log entries outside + *

Service Description: Service for configuring sinks used to export log entries outside of * Stackdriver Logging. * *

Sample for ConfigServiceV2Client: diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechClient.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechClient.java index 79263fe898c1..c7a95d6c4734 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechClient.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechClient.java @@ -16,9 +16,14 @@ package com.google.cloud.speech.spi.v1beta1; import com.google.api.gax.grpc.ChannelAndExecutor; +import com.google.api.gax.grpc.FixedChannelProvider; +import com.google.api.gax.grpc.FixedExecutorProvider; +import com.google.api.gax.grpc.OperationCallable; +import com.google.api.gax.grpc.OperationFuture; import com.google.api.gax.grpc.StreamingCallable; import com.google.api.gax.grpc.UnaryCallable; import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; +import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse; import com.google.cloud.speech.v1beta1.RecognitionAudio; import com.google.cloud.speech.v1beta1.RecognitionConfig; import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; @@ -26,6 +31,8 @@ import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.longrunning.Operation; +import com.google.longrunning.OperationsClient; +import com.google.longrunning.OperationsSettings; import com.google.protobuf.ExperimentalApi; import io.grpc.ManagedChannel; import java.io.Closeable; @@ -97,10 +104,13 @@ public class SpeechClient implements AutoCloseable { private final SpeechSettings settings; private final ScheduledExecutorService executor; private final ManagedChannel channel; + private final OperationsClient operationsClient; private final List closeables = new ArrayList<>(); private final UnaryCallable syncRecognizeCallable; private final UnaryCallable asyncRecognizeCallable; + private final OperationCallable + asyncRecognizeOperationCallable; private final StreamingCallable streamingRecognizeCallable; @@ -127,10 +137,25 @@ protected SpeechClient(SpeechSettings settings) throws IOException { this.executor = channelAndExecutor.getExecutor(); this.channel = channelAndExecutor.getChannel(); + FixedExecutorProvider executorProvider = FixedExecutorProvider.create(this.executor); + FixedChannelProvider channelProvider = FixedChannelProvider.create(this.channel); + OperationsSettings operationsSettings = + OperationsSettings.defaultBuilder() + .setExecutorProvider(executorProvider) + .setChannelProvider(channelProvider) + .build(); + this.operationsClient = OperationsClient.create(operationsSettings); + this.syncRecognizeCallable = UnaryCallable.create(settings.syncRecognizeSettings(), this.channel, this.executor); this.asyncRecognizeCallable = - UnaryCallable.create(settings.asyncRecognizeSettings(), this.channel, this.executor); + UnaryCallable.create( + settings.asyncRecognizeSettings().getInitialCallSettings(), + this.channel, + this.executor); + this.asyncRecognizeOperationCallable = + OperationCallable.create( + settings.asyncRecognizeSettings(), this.channel, this.executor, this.operationsClient); this.streamingRecognizeCallable = StreamingCallable.create(settings.streamingRecognizeSettings(), this.channel); @@ -158,6 +183,14 @@ public final SpeechSettings getSettings() { return settings; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getOperationsClient() { + return operationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD /** * Perform synchronous speech-recognition: receive results after all audio has been sent and @@ -249,7 +282,7 @@ public final UnaryCallable syncReco * try (SpeechClient speechClient = SpeechClient.create()) { * RecognitionConfig config = RecognitionConfig.newBuilder().build(); * RecognitionAudio audio = RecognitionAudio.newBuilder().build(); - * Operation response = speechClient.asyncRecognize(config, audio); + * AsyncRecognizeResponse response = speechClient.asyncRecognizeAsync(config, audio).get(); * } * * @@ -258,11 +291,12 @@ public final UnaryCallable syncReco * @param audio [Required] The audio data to be recognized. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Operation asyncRecognize(RecognitionConfig config, RecognitionAudio audio) { + public final OperationFuture asyncRecognizeAsync( + RecognitionConfig config, RecognitionAudio audio) { AsyncRecognizeRequest request = AsyncRecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); - return asyncRecognize(request); + return asyncRecognizeAsync(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD @@ -281,15 +315,43 @@ public final Operation asyncRecognize(RecognitionConfig config, RecognitionAudio * .setConfig(config) * .setAudio(audio) * .build(); - * Operation response = speechClient.asyncRecognize(request); + * AsyncRecognizeResponse response = speechClient.asyncRecognizeAsync(request).get(); * } * * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final Operation asyncRecognize(AsyncRecognizeRequest request) { - return asyncRecognizeCallable().call(request); + public final OperationFuture asyncRecognizeAsync( + AsyncRecognizeRequest request) { + return asyncRecognizeOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Perform asynchronous speech-recognition: receive results via the google.longrunning.Operations + * interface. Returns either an `Operation.error` or an `Operation.response` which contains an + * `AsyncRecognizeResponse` message. + * + *

Sample code: + * + *


+   * try (SpeechClient speechClient = SpeechClient.create()) {
+   *   RecognitionConfig config = RecognitionConfig.newBuilder().build();
+   *   RecognitionAudio audio = RecognitionAudio.newBuilder().build();
+   *   AsyncRecognizeRequest request = AsyncRecognizeRequest.newBuilder()
+   *     .setConfig(config)
+   *     .setAudio(audio)
+   *     .build();
+   *   OperationFuture<Operation> future = speechClient.asyncRecognizeOperationCallable().futureCall(request);
+   *   // Do something
+   *   AsyncRecognizeResponse response = future.get();
+   * }
+   * 
+ */ + public final OperationCallable + asyncRecognizeOperationCallable() { + return asyncRecognizeOperationCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD diff --git a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java index b9a853e841f9..f1e38b260328 100644 --- a/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java +++ b/google-cloud-speech/src/main/java/com/google/cloud/speech/spi/v1beta1/SpeechSettings.java @@ -22,10 +22,12 @@ import com.google.api.gax.grpc.ExecutorProvider; import com.google.api.gax.grpc.InstantiatingChannelProvider; import com.google.api.gax.grpc.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.OperationCallSettings; import com.google.api.gax.grpc.SimpleCallSettings; import com.google.api.gax.grpc.StreamingCallSettings; import com.google.api.gax.grpc.UnaryCallSettings; import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; +import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse; import com.google.cloud.speech.v1beta1.SpeechGrpc; import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; import com.google.cloud.speech.v1beta1.StreamingRecognizeResponse; @@ -36,7 +38,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.longrunning.Operation; import com.google.protobuf.ExperimentalApi; import io.grpc.Status; import java.io.IOException; @@ -84,7 +85,8 @@ public class SpeechSettings extends ClientSettings { private final SimpleCallSettings syncRecognizeSettings; - private final SimpleCallSettings asyncRecognizeSettings; + private final OperationCallSettings + asyncRecognizeSettings; private final StreamingCallSettings streamingRecognizeSettings; @@ -94,7 +96,8 @@ public SimpleCallSettings syncRecog } /** Returns the object with the settings used for calls to asyncRecognize. */ - public SimpleCallSettings asyncRecognizeSettings() { + public OperationCallSettings + asyncRecognizeSettings() { return asyncRecognizeSettings; } @@ -166,7 +169,7 @@ public static class Builder extends ClientSettings.Builder { private final SimpleCallSettings.Builder syncRecognizeSettings; - private final SimpleCallSettings.Builder + private final OperationCallSettings.Builder asyncRecognizeSettings; private final StreamingCallSettings.Builder< StreamingRecognizeRequest, StreamingRecognizeResponse> @@ -208,14 +211,15 @@ private Builder() { syncRecognizeSettings = SimpleCallSettings.newBuilder(SpeechGrpc.METHOD_SYNC_RECOGNIZE); - asyncRecognizeSettings = SimpleCallSettings.newBuilder(SpeechGrpc.METHOD_ASYNC_RECOGNIZE); + asyncRecognizeSettings = + OperationCallSettings.newBuilder( + SpeechGrpc.METHOD_ASYNC_RECOGNIZE, AsyncRecognizeResponse.class); streamingRecognizeSettings = StreamingCallSettings.newBuilder(SpeechGrpc.METHOD_STREAMING_RECOGNIZE); unaryMethodSettingsBuilders = - ImmutableList.of( - syncRecognizeSettings, asyncRecognizeSettings); + ImmutableList.of(syncRecognizeSettings); } private static Builder createDefault() { @@ -225,9 +229,9 @@ private static Builder createDefault() { .syncRecognizeSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); - builder .asyncRecognizeSettings() + .getInitialCallSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); @@ -242,8 +246,7 @@ private Builder(SpeechSettings settings) { streamingRecognizeSettings = settings.streamingRecognizeSettings.toBuilder(); unaryMethodSettingsBuilders = - ImmutableList.of( - syncRecognizeSettings, asyncRecognizeSettings); + ImmutableList.of(syncRecognizeSettings); } @Override @@ -277,7 +280,8 @@ public Builder applyToAllUnaryMethods(UnaryCallSettings.Builder unaryCallSetting } /** Returns the builder for the settings used for calls to asyncRecognize. */ - public SimpleCallSettings.Builder asyncRecognizeSettings() { + public OperationCallSettings.Builder + asyncRecognizeSettings() { return asyncRecognizeSettings; } diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java index 801801999ae2..3c2eb75ff6be 100644 --- a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java @@ -21,6 +21,7 @@ import com.google.api.gax.testing.MockServiceHelper; import com.google.api.gax.testing.MockStreamObserver; import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; +import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse; import com.google.cloud.speech.v1beta1.RecognitionAudio; import com.google.cloud.speech.v1beta1.RecognitionConfig; import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; @@ -28,6 +29,7 @@ import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.longrunning.Operation; +import com.google.protobuf.Any; import com.google.protobuf.GeneratedMessageV3; import io.grpc.Status; import io.grpc.StatusRuntimeException; @@ -116,16 +118,20 @@ public void syncRecognizeExceptionTest() throws Exception { @Test @SuppressWarnings("all") - public void asyncRecognizeTest() { - String name = "name3373707"; - boolean done = true; - Operation expectedResponse = Operation.newBuilder().setName(name).setDone(done).build(); - mockSpeech.addResponse(expectedResponse); + public void asyncRecognizeTest() throws Exception { + AsyncRecognizeResponse expectedResponse = AsyncRecognizeResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("asyncRecognizeTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockSpeech.addResponse(resultOperation); RecognitionConfig config = RecognitionConfig.newBuilder().build(); RecognitionAudio audio = RecognitionAudio.newBuilder().build(); - Operation actualResponse = client.asyncRecognize(config, audio); + AsyncRecognizeResponse actualResponse = client.asyncRecognizeAsync(config, audio).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockSpeech.getRequests(); @@ -146,10 +152,12 @@ public void asyncRecognizeExceptionTest() throws Exception { RecognitionConfig config = RecognitionConfig.newBuilder().build(); RecognitionAudio audio = RecognitionAudio.newBuilder().build(); - client.asyncRecognize(config, audio); + client.asyncRecognizeAsync(config, audio).get(); Assert.fail("No exception raised"); - } catch (ApiException e) { - Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); + } catch (ExecutionException e) { + Assert.assertEquals(ApiException.class, e.getCause().getClass()); + ApiException apiException = (ApiException) e.getCause(); + Assert.assertEquals(Status.INTERNAL.getCode(), apiException.getStatusCode()); } }