From 33679dfa75eec622443b3b7d6a61e4071d2e8e4b Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 19 Aug 2016 11:30:27 -0700 Subject: [PATCH 1/5] Initial auto-generated gcloud-java-cloudtrace --- gcloud-java-cloudtrace/pom.xml | 126 ++++++ .../cloudtrace/spi/v1/TraceServiceApi.java | 422 ++++++++++++++++++ .../spi/v1/TraceServiceSettings.java | 384 ++++++++++++++++ .../cloudtrace/spi/v1/package-info.java | 42 ++ .../cloudtrace/spi/v1/MockTraceService.java | 50 +++ .../spi/v1/MockTraceServiceImpl.java | 79 ++++ .../cloudtrace/spi/v1/TraceServiceTest.java | 134 ++++++ gcloud-java-core/pom.xml | 2 +- pom.xml | 3 +- 9 files changed, 1240 insertions(+), 2 deletions(-) create mode 100644 gcloud-java-cloudtrace/pom.xml create mode 100644 gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java create mode 100644 gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java create mode 100644 gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java create mode 100644 gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java create mode 100644 gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java create mode 100644 gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java diff --git a/gcloud-java-cloudtrace/pom.xml b/gcloud-java-cloudtrace/pom.xml new file mode 100644 index 000000000000..62e234bc0a32 --- /dev/null +++ b/gcloud-java-cloudtrace/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + gcloud-java-cloudtrace + jar + GCloud Java Stackdriver Trace + https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-cloudtrace + + Java idiomatic client for Stackdriver Trace. + + + com.google.cloud + gcloud-java-pom + 0.2.8-SNAPSHOT + + + gcloud-java-cloudtrace + + + + io.netty + netty-tcnative-boringssl-static + 1.1.33.Fork17 + + + ${project.groupId} + gcloud-java-core + ${project.version} + + + com.google.api.grpc + grpc-google-devtools-cloudtrace-v1 + 0.0.7 + + + io.grpc + grpc-all + 0.15.0 + + + com.google.auto.value + auto-value + 1.1 + + + ${project.groupId} + gcloud-java-core + ${project.version} + test-jar + test + + + junit + junit + 4.12 + test + + + org.easymock + easymock + 3.4 + test + + + + + doclint-java8-disable + + [1.8,) + + + + -Xdoclint:none + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + generate-sources + add-source + + + generated/src/main/java + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + + jar + + + ${javadoc.opts} + + + + + + maven-compiler-plugin + + + + 3.1 + + 1.7 + 1.7 + UTF-8 + -Xlint:unchecked + + + + + diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java new file mode 100644 index 000000000000..43dc5c17608b --- /dev/null +++ b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java @@ -0,0 +1,422 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.devtools.cloudtrace.spi.v1; + +import com.google.api.gax.core.PageAccessor; +import com.google.api.gax.grpc.ApiCallable; +import com.google.api.gax.protobuf.PathTemplate; +import com.google.devtools.cloudtrace.v1.GetTraceRequest; +import com.google.devtools.cloudtrace.v1.ListTracesRequest; +import com.google.devtools.cloudtrace.v1.ListTracesResponse; +import com.google.devtools.cloudtrace.v1.PatchTracesRequest; +import com.google.devtools.cloudtrace.v1.Trace; +import com.google.devtools.cloudtrace.v1.Traces; +import com.google.protobuf.Empty; +import io.grpc.ManagedChannel; +import java.io.Closeable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: This file describes an API for collecting and viewing traces and spans + * within a trace. A Trace is a collection of spans corresponding to a single + * operation or set of operations for an application. A span is an individual + * timed event which forms a node of the trace tree. Spans for a single trace + * may span multiple services. + * + *

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: + * + *

+ * 
+ * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+ *   String projectId = "";
+ *   String traceId = "";
+ *   Trace response = traceServiceApi.getTrace(projectId, traceId);
+ * }
+ * 
+ * 
+ * + *

Note: close() needs to be called on the traceServiceApi object to clean up resources such + * as threads. In the example above, try-with-resources is used, which automatically calls + * close(). + * + *

The surface of this class includes several types of Java methods for each of the API's methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available + * as parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request + * object, which must be constructed before the call. Not every API method will have a request + * object method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable + * ApiCallable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist + * with these names, this class includes a format method for each type of name, and additionally + * a parse method to extract the individual identifiers contained within names that are + * returned. + * + *

This class can be customized by passing in a custom instance of TraceServiceSettings to + * create(). For example: + * + *

+ * 
+ * TraceServiceSettings traceServiceSettings = TraceServiceSettings.defaultBuilder()
+ *     .provideChannelWith(myCredentials)
+ *     .build();
+ * TraceServiceApi traceServiceApi = TraceServiceApi.create(traceServiceSettings);
+ * 
+ * 
+ */ +@javax.annotation.Generated("by GAPIC") +public class TraceServiceApi implements AutoCloseable { + private final TraceServiceSettings settings; + private final ManagedChannel channel; + private final ScheduledExecutorService executor; + private final List closeables = new ArrayList<>(); + + private final ApiCallable listTracesCallable; + private final ApiCallable> listTracesPagedCallable; + private final ApiCallable getTraceCallable; + private final ApiCallable patchTracesCallable; + + public final TraceServiceSettings getSettings() { + return settings; + } + + /** + * Constructs an instance of TraceServiceApi with default settings. + */ + public static final TraceServiceApi create() throws IOException { + return create(TraceServiceSettings.defaultBuilder().build()); + } + + /** + * Constructs an instance of TraceServiceApi, using the given settings. + * The channels are created based on the settings passed in, or defaults for any + * settings that are not set. + */ + public static final TraceServiceApi create(TraceServiceSettings settings) throws IOException { + return new TraceServiceApi(settings); + } + + /** + * Constructs an instance of TraceServiceApi, using the given settings. + * This is protected so that it easy to make a subclass, but otherwise, the static + * factory methods should be preferred. + */ + protected TraceServiceApi(TraceServiceSettings settings) throws IOException { + this.settings = settings; + this.executor = settings.getExecutorProvider().getOrBuildExecutor(); + this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); + + this.listTracesCallable = + ApiCallable.create(settings.listTracesSettings(), this.channel, this.executor); + this.listTracesPagedCallable = + ApiCallable.createPagedVariant(settings.listTracesSettings(), this.channel, this.executor); + this.getTraceCallable = + ApiCallable.create(settings.getTraceSettings(), this.channel, this.executor); + this.patchTracesCallable = + ApiCallable.create(settings.patchTracesSettings(), this.channel, this.executor); + + if (settings.getChannelProvider().shouldAutoClose()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + channel.shutdown(); + } + }); + } + if (settings.getExecutorProvider().shouldAutoClose()) { + closeables.add( + new Closeable() { + @Override + public void close() throws IOException { + executor.shutdown(); + } + }); + } + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns of a list of traces that match the specified filter conditions. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   for (Trace element : traceServiceApi.listTraces(projectId)) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param projectId ID of the Cloud project where the trace data is stored. + * @throws com.google.api.gax.grpc.ApiException if the remote call fails + */ + public final PageAccessor listTraces(String projectId) { + ListTracesRequest request = ListTracesRequest.newBuilder().setProjectId(projectId).build(); + return listTraces(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns of a list of traces that match the specified filter conditions. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   ListTracesRequest request = ListTracesRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .build();
+   *   for (Trace element : traceServiceApi.listTraces(request)) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @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 PageAccessor listTraces(ListTracesRequest request) { + return listTracesPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns of a list of traces that match the specified filter conditions. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   ListTracesRequest request = ListTracesRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .build();
+   *   ListenableFuture<PageAccessor<Trace>> future = traceServiceApi.listTracesPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Trace element : future.get()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ */ + public final ApiCallable> listTracesPagedCallable() { + return listTracesPagedCallable; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns of a list of traces that match the specified filter conditions. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   ListTracesRequest request = ListTracesRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .build();
+   *   while (true) {
+   *     ListTracesResponse response = traceServiceApi.listTracesCallable().call(request);
+   *     for (Trace element : response.getTracesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ */ + public final ApiCallable listTracesCallable() { + return listTracesCallable; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a single trace by its ID. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   String traceId = "";
+   *   Trace response = traceServiceApi.getTrace(projectId, traceId);
+   * }
+   * 
+ * + * @param projectId ID of the Cloud project where the trace data is stored. + * @param traceId ID of the trace to return. + * @throws com.google.api.gax.grpc.ApiException if the remote call fails + */ + public final Trace getTrace(String projectId, String traceId) { + GetTraceRequest request = + GetTraceRequest.newBuilder().setProjectId(projectId).setTraceId(traceId).build(); + return getTrace(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a single trace by its ID. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   String traceId = "";
+   *   GetTraceRequest request = GetTraceRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .setTraceId(traceId)
+   *     .build();
+   *   Trace response = traceServiceApi.getTrace(request);
+   * }
+   * 
+ * + * @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 + */ + private final Trace getTrace(GetTraceRequest request) { + return getTraceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets a single trace by its ID. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   String traceId = "";
+   *   GetTraceRequest request = GetTraceRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .setTraceId(traceId)
+   *     .build();
+   *   ListenableFuture<Trace> future = traceServiceApi.getTraceCallable().futureCall(request);
+   *   // Do something
+   *   Trace response = future.get();
+   * }
+   * 
+ */ + public final ApiCallable getTraceCallable() { + return getTraceCallable; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Sends new traces to Cloud Trace or updates existing traces. If the ID of + * a trace that you send matches that of an existing trace, any fields + * in the existing trace and its spans are overwritten by the provided values, + * and any new fields provided are merged with the existing trace data. If the + * ID does not match, a new trace is created. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   Traces traces = Traces.newBuilder().build();
+   *   traceServiceApi.patchTraces(projectId, traces);
+   * }
+   * 
+ * + * @param projectId ID of the Cloud project where the trace data is stored. + * @param traces The body of the message. + * @throws com.google.api.gax.grpc.ApiException if the remote call fails + */ + public final void patchTraces(String projectId, Traces traces) { + PatchTracesRequest request = + PatchTracesRequest.newBuilder().setProjectId(projectId).setTraces(traces).build(); + patchTraces(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Sends new traces to Cloud Trace or updates existing traces. If the ID of + * a trace that you send matches that of an existing trace, any fields + * in the existing trace and its spans are overwritten by the provided values, + * and any new fields provided are merged with the existing trace data. If the + * ID does not match, a new trace is created. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   Traces traces = Traces.newBuilder().build();
+   *   PatchTracesRequest request = PatchTracesRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .setTraces(traces)
+   *     .build();
+   *   traceServiceApi.patchTraces(request);
+   * }
+   * 
+ * + * @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 void patchTraces(PatchTracesRequest request) { + patchTracesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Sends new traces to Cloud Trace or updates existing traces. If the ID of + * a trace that you send matches that of an existing trace, any fields + * in the existing trace and its spans are overwritten by the provided values, + * and any new fields provided are merged with the existing trace data. If the + * ID does not match, a new trace is created. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   Traces traces = Traces.newBuilder().build();
+   *   PatchTracesRequest request = PatchTracesRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .setTraces(traces)
+   *     .build();
+   *   ListenableFuture<Void> future = traceServiceApi.patchTracesCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + public final ApiCallable patchTracesCallable() { + return patchTracesCallable; + } + + /** + * Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately + * cancelled. + */ + @Override + public final void close() throws Exception { + for (AutoCloseable closeable : closeables) { + closeable.close(); + } + } +} diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java new file mode 100644 index 000000000000..65d56fd3766b --- /dev/null +++ b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java @@ -0,0 +1,384 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.cloud.devtools.cloudtrace.spi.v1; + +import com.google.api.gax.core.ConnectionSettings; +import com.google.api.gax.core.RetrySettings; +import com.google.api.gax.grpc.ApiCallSettings; +import com.google.api.gax.grpc.PageStreamingCallSettings; +import com.google.api.gax.grpc.PageStreamingDescriptor; +import com.google.api.gax.grpc.ServiceApiSettings; +import com.google.api.gax.grpc.SimpleCallSettings; +import com.google.auth.Credentials; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.google.devtools.cloudtrace.v1.GetTraceRequest; +import com.google.devtools.cloudtrace.v1.ListTracesRequest; +import com.google.devtools.cloudtrace.v1.ListTracesResponse; +import com.google.devtools.cloudtrace.v1.PatchTracesRequest; +import com.google.devtools.cloudtrace.v1.Trace; +import com.google.devtools.cloudtrace.v1.TraceServiceGrpc; +import com.google.protobuf.Empty; +import io.grpc.ManagedChannel; +import io.grpc.Status; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import org.joda.time.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link TraceServiceApi}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (cloudtrace.googleapis.com) and default port (443) + * are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. + * When build() is called, the tree of builders is called to create the complete settings + * object. For example, to set the total timeout of getTrace to 30 seconds: + * + *

+ * 
+ * TraceServiceSettings.Builder traceServiceSettingsBuilder =
+ *     TraceServiceSettings.defaultBuilder();
+ * traceServiceSettingsBuilder.getTraceSettings().getRetrySettingsBuilder()
+ *     .setTotalTimeout(Duration.standardSeconds(30));
+ * TraceServiceSettings traceServiceSettings = traceServiceSettingsBuilder.build();
+ * 
+ * 
+ */ +@javax.annotation.Generated("by GAPIC") +public class TraceServiceSettings extends ServiceApiSettings { + /** + * The default address of the service. + */ + private static final String DEFAULT_SERVICE_ADDRESS = "cloudtrace.googleapis.com"; + + /** + * The default port of the service. + */ + private static final int DEFAULT_SERVICE_PORT = 443; + + /** + * The default scopes of the service. + */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/trace.append") + .add("https://www.googleapis.com/auth/trace.readonly") + .build(); + + /** + * The default connection settings of the service. + */ + public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = + ConnectionSettings.newBuilder() + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) + .setPort(DEFAULT_SERVICE_PORT) + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) + .build(); + + private final PageStreamingCallSettings + listTracesSettings; + private final SimpleCallSettings getTraceSettings; + private final SimpleCallSettings patchTracesSettings; + + /** + * Returns the object with the settings used for calls to listTraces. + */ + public PageStreamingCallSettings + listTracesSettings() { + return listTracesSettings; + } + + /** + * Returns the object with the settings used for calls to getTrace. + */ + public SimpleCallSettings getTraceSettings() { + return getTraceSettings; + } + + /** + * Returns the object with the settings used for calls to patchTraces. + */ + public SimpleCallSettings patchTracesSettings() { + return patchTracesSettings; + } + + /** + * Returns the default service address. + */ + public static String getDefaultServiceAddress() { + return DEFAULT_SERVICE_ADDRESS; + } + + /** + * Returns the default service port. + */ + public static int getDefaultServicePort() { + return DEFAULT_SERVICE_PORT; + } + + /** + * Returns the default service scopes. + */ + public static ImmutableList getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** + * Returns a builder for this class with recommended defaults. + */ + public static Builder defaultBuilder() { + return Builder.createDefault(); + } + + /** + * Returns a new builder for this class. + */ + public static Builder newBuilder() { + return new Builder(); + } + + /** + * Returns a builder containing all the values of this settings class. + */ + public Builder toBuilder() { + return new Builder(this); + } + + private TraceServiceSettings(Builder settingsBuilder) throws IOException { + super( + settingsBuilder.getChannelProvider(), + settingsBuilder.getExecutorProvider(), + settingsBuilder.getGeneratorName(), + settingsBuilder.getGeneratorVersion(), + settingsBuilder.getClientLibName(), + settingsBuilder.getClientLibVersion()); + + listTracesSettings = settingsBuilder.listTracesSettings().build(); + getTraceSettings = settingsBuilder.getTraceSettings().build(); + patchTracesSettings = settingsBuilder.patchTracesSettings().build(); + } + + private static PageStreamingDescriptor + LIST_TRACES_PAGE_STR_DESC = + new PageStreamingDescriptor() { + @Override + public Object emptyToken() { + return ""; + } + + @Override + public ListTracesRequest injectToken(ListTracesRequest payload, Object token) { + return ListTracesRequest.newBuilder(payload).setPageToken((String) token).build(); + } + + @Override + public Object extractNextToken(ListTracesResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListTracesResponse payload) { + return payload.getTracesList(); + } + }; + + /** + * Builder for TraceServiceSettings. + */ + public static class Builder extends ServiceApiSettings.Builder { + private final ImmutableList methodSettingsBuilders; + + private PageStreamingCallSettings.Builder + listTracesSettings; + private SimpleCallSettings.Builder getTraceSettings; + private SimpleCallSettings.Builder patchTracesSettings; + + private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = ImmutableMap.builder(); + definitions.put( + "idempotent", + Sets.immutableEnumSet( + Lists.newArrayList( + Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE))); + definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings.Builder settingsBuilder = null; + settingsBuilder = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.millis(100L)) + .setRetryDelayMultiplier(1.2) + .setMaxRetryDelay(Duration.millis(1000L)) + .setInitialRpcTimeout(Duration.millis(20000L)) + .setRpcTimeoutMultiplier(1.5) + .setMaxRpcTimeout(Duration.millis(30000L)) + .setTotalTimeout(Duration.millis(45000L)); + definitions.put("default", settingsBuilder); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + private Builder() { + super(DEFAULT_CONNECTION_SETTINGS); + + listTracesSettings = + PageStreamingCallSettings.newBuilder( + TraceServiceGrpc.METHOD_LIST_TRACES, LIST_TRACES_PAGE_STR_DESC); + + getTraceSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_GET_TRACE); + + patchTracesSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_PATCH_TRACES); + + methodSettingsBuilders = + ImmutableList.of( + listTracesSettings, getTraceSettings, patchTracesSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(); + + builder + .listTracesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .getTraceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .patchTracesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) + .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); + + return builder; + } + + private Builder(TraceServiceSettings settings) { + super(settings); + + listTracesSettings = settings.listTracesSettings.toBuilder(); + getTraceSettings = settings.getTraceSettings.toBuilder(); + patchTracesSettings = settings.patchTracesSettings.toBuilder(); + + methodSettingsBuilders = + ImmutableList.of( + listTracesSettings, getTraceSettings, patchTracesSettings); + } + + @Override + protected ConnectionSettings getDefaultConnectionSettings() { + return DEFAULT_CONNECTION_SETTINGS; + } + + @Override + public Builder provideExecutorWith(ScheduledExecutorService executor, boolean shouldAutoClose) { + super.provideExecutorWith(executor, shouldAutoClose); + return this; + } + + @Override + public Builder provideChannelWith(ManagedChannel channel, boolean shouldAutoClose) { + super.provideChannelWith(channel, shouldAutoClose); + return this; + } + + @Override + public Builder provideChannelWith(ConnectionSettings settings) { + super.provideChannelWith(settings); + return this; + } + + @Override + public Builder provideChannelWith(Credentials credentials) { + super.provideChannelWith(credentials); + return this; + } + + @Override + public Builder provideChannelWith(List scopes) { + super.provideChannelWith(scopes); + return this; + } + + @Override + public Builder setGeneratorHeader(String name, String version) { + super.setGeneratorHeader(name, version); + return this; + } + + @Override + public Builder setClientLibHeader(String name, String version) { + super.setClientLibHeader(name, version); + return this; + } + + /** + * Applies the given settings to all of the API methods in this service. Only + * values that are non-null will be applied, so this method is not capable + * of un-setting any values. + */ + public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { + super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); + return this; + } + + /** + * Returns the builder for the settings used for calls to listTraces. + */ + public PageStreamingCallSettings.Builder + listTracesSettings() { + return listTracesSettings; + } + + /** + * Returns the builder for the settings used for calls to getTrace. + */ + public SimpleCallSettings.Builder getTraceSettings() { + return getTraceSettings; + } + + /** + * Returns the builder for the settings used for calls to patchTraces. + */ + public SimpleCallSettings.Builder patchTracesSettings() { + return patchTracesSettings; + } + + @Override + public TraceServiceSettings build() throws IOException { + return new TraceServiceSettings(this); + } + } +} diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java new file mode 100644 index 000000000000..72348fd07474 --- /dev/null +++ b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * A client to Google Cloud Trace API. + * + * The interfaces provided are listed below, along with a usage sample + * + * =============== + * TraceServiceApi + * =============== + * + * Service Description: This file describes an API for collecting and viewing traces and spans + * within a trace. A Trace is a collection of spans corresponding to a single + * operation or set of operations for an application. A span is an individual + * timed event which forms a node of the trace tree. Spans for a single trace + * may span multiple services. + * + * Sample for TraceServiceApi: + *
+ * 
+ * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+ *   String projectId = "";
+ *   String traceId = "";
+ *   Trace response = traceServiceApi.getTrace(projectId, traceId);
+ * }
+ * 
+ * 
+ * + */ +package com.google.cloud.devtools.cloudtrace.spi.v1; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java new file mode 100644 index 000000000000..bb1666db72db --- /dev/null +++ b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java @@ -0,0 +1,50 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.devtools.cloudtrace.spi.v1; + +import com.google.api.gax.testing.MockGrpcService; +import com.google.devtools.cloudtrace.v1.TraceServiceGrpc; +import com.google.protobuf.GeneratedMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +public class MockTraceService implements MockGrpcService { + private MockTraceServiceImpl serviceImpl; + + public MockTraceService() { + serviceImpl = new MockTraceServiceImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void setResponses(List responses) { + serviceImpl.setResponses(responses); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return TraceServiceGrpc.bindService(serviceImpl); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java new file mode 100644 index 000000000000..7484b19a9c36 --- /dev/null +++ b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.devtools.cloudtrace.spi.v1; + +import com.google.common.collect.Lists; +import com.google.devtools.cloudtrace.v1.GetTraceRequest; +import com.google.devtools.cloudtrace.v1.ListTracesRequest; +import com.google.devtools.cloudtrace.v1.ListTracesResponse; +import com.google.devtools.cloudtrace.v1.PatchTracesRequest; +import com.google.devtools.cloudtrace.v1.Trace; +import com.google.devtools.cloudtrace.v1.TraceServiceGrpc.TraceService; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessage; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +public class MockTraceServiceImpl implements TraceService { + private ArrayList requests; + private Queue responses; + + public MockTraceServiceImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void setResponses(List responses) { + this.responses = Lists.newLinkedList(responses); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void listTraces( + ListTracesRequest request, StreamObserver responseObserver) { + ListTracesResponse response = (ListTracesResponse) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void getTrace(GetTraceRequest request, StreamObserver responseObserver) { + Trace response = (Trace) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void patchTraces(PatchTracesRequest request, StreamObserver responseObserver) { + Empty response = (Empty) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } +} diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java new file mode 100644 index 000000000000..2fe514511909 --- /dev/null +++ b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.cloud.devtools.cloudtrace.spi.v1; + +import com.google.api.gax.core.PageAccessor; +import com.google.api.gax.testing.MockGrpcService; +import com.google.api.gax.testing.MockServiceHelper; +import com.google.common.collect.Lists; +import com.google.devtools.cloudtrace.v1.GetTraceRequest; +import com.google.devtools.cloudtrace.v1.ListTracesRequest; +import com.google.devtools.cloudtrace.v1.ListTracesResponse; +import com.google.devtools.cloudtrace.v1.PatchTracesRequest; +import com.google.devtools.cloudtrace.v1.Trace; +import com.google.devtools.cloudtrace.v1.Traces; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessage; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import junit.framework.Assert; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class TraceServiceTest { + private static MockServiceHelper serviceHelper; + private TraceServiceApi api; + + @BeforeClass + public static void startStaticServer() { + MockTraceService mockService = new MockTraceService(); + serviceHelper = new MockServiceHelper("in-process-1", mockService); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + TraceServiceSettings settings = + TraceServiceSettings.defaultBuilder() + .provideChannelWith(serviceHelper.createChannel(), true) + .build(); + api = TraceServiceApi.create(settings); + } + + @After + public void tearDown() throws Exception { + api.close(); + } + + @Test + @SuppressWarnings("all") + public void listTracesTest() { + ListTracesResponse expectedResponse = ListTracesResponse.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + serviceHelper.getService().setResponses(expectedResponses); + + String projectId = ""; + PageAccessor pageAccessor = api.listTraces(projectId); + + // PageAccessor will not make actual request until it is being used. + // Add all the pages here in order to make grpc requests. + List resources = Lists.newArrayList(pageAccessor.getPageValues()); + Assert.assertEquals(0, resources.size()); + + List actualRequests = serviceHelper.getService().getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0); + + Assert.assertEquals(actualRequest.getProjectId(), projectId); + } + + @Test + @SuppressWarnings("all") + public void getTraceTest() { + Trace expectedResponse = Trace.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + serviceHelper.getService().setResponses(expectedResponses); + + String projectId = ""; + String traceId = ""; + Trace actualResponse = api.getTrace(projectId, traceId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = serviceHelper.getService().getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetTraceRequest actualRequest = (GetTraceRequest) actualRequests.get(0); + + Assert.assertEquals(actualRequest.getProjectId(), projectId); + Assert.assertEquals(actualRequest.getTraceId(), traceId); + } + + @Test + @SuppressWarnings("all") + public void patchTracesTest() { + Empty expectedResponse = Empty.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + serviceHelper.getService().setResponses(expectedResponses); + + String projectId = ""; + Traces traces = Traces.newBuilder().build(); + api.patchTraces(projectId, traces); + + List actualRequests = serviceHelper.getService().getRequests(); + Assert.assertEquals(1, actualRequests.size()); + PatchTracesRequest actualRequest = (PatchTracesRequest) actualRequests.get(0); + + Assert.assertEquals(actualRequest.getProjectId(), projectId); + Assert.assertEquals(actualRequest.getTraces(), traces); + } +} diff --git a/gcloud-java-core/pom.xml b/gcloud-java-core/pom.xml index 0a426d50a21b..7dee8be38b68 100644 --- a/gcloud-java-core/pom.xml +++ b/gcloud-java-core/pom.xml @@ -106,7 +106,7 @@ com.google.api gax - 0.0.14 + 0.0.15 com.google.api.grpc diff --git a/pom.xml b/pom.xml index 8002ac3338d1..4239a75bce22 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ gcloud-java gcloud-java-bigquery + gcloud-java-cloudtrace gcloud-java-compute gcloud-java-contrib gcloud-java-core @@ -323,7 +324,7 @@ error true true - com/google/cloud/*/spi/v*/** + com/google/cloud/**/spi/v*/** From c47243e9a822d49f10b36469ac786690c65698a2 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Fri, 26 Aug 2016 16:44:36 -0700 Subject: [PATCH 2/5] Removing devtools from package, refreshing tests --- gcloud-java-cloudtrace/pom.xml | 2 +- .../cloudtrace/spi/v1/TraceServiceApi.java | 192 +++++++++--------- .../spi/v1/TraceServiceSettings.java | 70 +++---- .../cloudtrace/spi/v1/package-info.java | 6 +- .../cloudtrace/spi/v1/MockTraceService.java | 2 +- .../spi/v1/MockTraceServiceImpl.java | 2 +- .../cloudtrace/spi/v1/TraceServiceTest.java | 83 +++++--- gcloud-java-core/pom.xml | 2 +- 8 files changed, 188 insertions(+), 171 deletions(-) rename gcloud-java-cloudtrace/src/main/java/com/google/cloud/{devtools => }/cloudtrace/spi/v1/TraceServiceApi.java (99%) rename gcloud-java-cloudtrace/src/main/java/com/google/cloud/{devtools => }/cloudtrace/spi/v1/TraceServiceSettings.java (97%) rename gcloud-java-cloudtrace/src/main/java/com/google/cloud/{devtools => }/cloudtrace/spi/v1/package-info.java (90%) rename gcloud-java-cloudtrace/src/test/java/com/google/cloud/{devtools => }/cloudtrace/spi/v1/MockTraceService.java (96%) rename gcloud-java-cloudtrace/src/test/java/com/google/cloud/{devtools => }/cloudtrace/spi/v1/MockTraceServiceImpl.java (98%) rename gcloud-java-cloudtrace/src/test/java/com/google/cloud/{devtools => }/cloudtrace/spi/v1/TraceServiceTest.java (65%) diff --git a/gcloud-java-cloudtrace/pom.xml b/gcloud-java-cloudtrace/pom.xml index 62e234bc0a32..e2a4bd79b504 100644 --- a/gcloud-java-cloudtrace/pom.xml +++ b/gcloud-java-cloudtrace/pom.xml @@ -11,7 +11,7 @@ com.google.cloud gcloud-java-pom - 0.2.8-SNAPSHOT + 0.2.9-SNAPSHOT gcloud-java-cloudtrace diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceApi.java similarity index 99% rename from gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java rename to gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceApi.java index 43dc5c17608b..da0acec67b71 100644 --- a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceApi.java +++ b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceApi.java @@ -11,7 +11,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package com.google.cloud.devtools.cloudtrace.spi.v1; +package com.google.cloud.cloudtrace.spi.v1; import com.google.api.gax.core.PageAccessor; import com.google.api.gax.grpc.ApiCallable; @@ -45,8 +45,8 @@ * * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) { * String projectId = ""; - * String traceId = ""; - * Trace response = traceServiceApi.getTrace(projectId, traceId); + * Traces traces = Traces.newBuilder().build(); + * traceServiceApi.patchTraces(projectId, traces); * } * * @@ -94,10 +94,10 @@ public class TraceServiceApi implements AutoCloseable { private final ScheduledExecutorService executor; private final List closeables = new ArrayList<>(); + private final ApiCallable patchTracesCallable; + private final ApiCallable getTraceCallable; private final ApiCallable listTracesCallable; private final ApiCallable> listTracesPagedCallable; - private final ApiCallable getTraceCallable; - private final ApiCallable patchTracesCallable; public final TraceServiceSettings getSettings() { return settings; @@ -129,14 +129,14 @@ protected TraceServiceApi(TraceServiceSettings settings) throws IOException { this.executor = settings.getExecutorProvider().getOrBuildExecutor(); this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor); + this.patchTracesCallable = + ApiCallable.create(settings.patchTracesSettings(), this.channel, this.executor); + this.getTraceCallable = + ApiCallable.create(settings.getTraceSettings(), this.channel, this.executor); this.listTracesCallable = ApiCallable.create(settings.listTracesSettings(), this.channel, this.executor); this.listTracesPagedCallable = ApiCallable.createPagedVariant(settings.listTracesSettings(), this.channel, this.executor); - this.getTraceCallable = - ApiCallable.create(settings.getTraceSettings(), this.channel, this.executor); - this.patchTracesCallable = - ApiCallable.create(settings.patchTracesSettings(), this.channel, this.executor); if (settings.getChannelProvider().shouldAutoClose()) { closeables.add( @@ -160,101 +160,84 @@ public void close() throws IOException { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Returns of a list of traces that match the specified filter conditions. + * Sends new traces to Cloud Trace or updates existing traces. If the ID of + * a trace that you send matches that of an existing trace, any fields + * in the existing trace and its spans are overwritten by the provided values, + * and any new fields provided are merged with the existing trace data. If the + * ID does not match, a new trace is created. * * Sample code: *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   for (Trace element : traceServiceApi.listTraces(projectId)) {
-   *     // doThingsWith(element);
-   *   }
+   *   Traces traces = Traces.newBuilder().build();
+   *   traceServiceApi.patchTraces(projectId, traces);
    * }
    * 
* * @param projectId ID of the Cloud project where the trace data is stored. + * @param traces The body of the message. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listTraces(String projectId) { - ListTracesRequest request = ListTracesRequest.newBuilder().setProjectId(projectId).build(); - return listTraces(request); + public final void patchTraces(String projectId, Traces traces) { + PatchTracesRequest request = + PatchTracesRequest.newBuilder().setProjectId(projectId).setTraces(traces).build(); + patchTraces(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Returns of a list of traces that match the specified filter conditions. + * Sends new traces to Cloud Trace or updates existing traces. If the ID of + * a trace that you send matches that of an existing trace, any fields + * in the existing trace and its spans are overwritten by the provided values, + * and any new fields provided are merged with the existing trace data. If the + * ID does not match, a new trace is created. * * Sample code: *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   ListTracesRequest request = ListTracesRequest.newBuilder()
+   *   Traces traces = Traces.newBuilder().build();
+   *   PatchTracesRequest request = PatchTracesRequest.newBuilder()
    *     .setProjectId(projectId)
+   *     .setTraces(traces)
    *     .build();
-   *   for (Trace element : traceServiceApi.listTraces(request)) {
-   *     // doThingsWith(element);
-   *   }
+   *   traceServiceApi.patchTraces(request);
    * }
    * 
* * @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 PageAccessor listTraces(ListTracesRequest request) { - return listTracesPagedCallable().call(request); + public final void patchTraces(PatchTracesRequest request) { + patchTracesCallable().call(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Returns of a list of traces that match the specified filter conditions. + * Sends new traces to Cloud Trace or updates existing traces. If the ID of + * a trace that you send matches that of an existing trace, any fields + * in the existing trace and its spans are overwritten by the provided values, + * and any new fields provided are merged with the existing trace data. If the + * ID does not match, a new trace is created. * * Sample code: *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   ListTracesRequest request = ListTracesRequest.newBuilder()
+   *   Traces traces = Traces.newBuilder().build();
+   *   PatchTracesRequest request = PatchTracesRequest.newBuilder()
    *     .setProjectId(projectId)
+   *     .setTraces(traces)
    *     .build();
-   *   ListenableFuture<PageAccessor<Trace>> future = traceServiceApi.listTracesPagedCallable().futureCall(request);
+   *   ListenableFuture<Void> future = traceServiceApi.patchTracesCallable().futureCall(request);
    *   // Do something
-   *   for (Trace element : future.get()) {
-   *     // doThingsWith(element);
-   *   }
-   * }
-   * 
- */ - public final ApiCallable> listTracesPagedCallable() { - return listTracesPagedCallable; - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Returns of a list of traces that match the specified filter conditions. - * - * Sample code: - *

-   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
-   *   String projectId = "";
-   *   ListTracesRequest request = ListTracesRequest.newBuilder()
-   *     .setProjectId(projectId)
-   *     .build();
-   *   while (true) {
-   *     ListTracesResponse response = traceServiceApi.listTracesCallable().call(request);
-   *     for (Trace element : response.getTracesList()) {
-   *       // doThingsWith(element);
-   *     }
-   *     String nextPageToken = response.getNextPageToken();
-   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
-   *       request = request.toBuilder().setPageToken(nextPageToken).build();
-   *     } else {
-   *       break;
-   *     }
-   *   }
+   *   future.get();
    * }
    * 
*/ - public final ApiCallable listTracesCallable() { - return listTracesCallable; + public final ApiCallable patchTracesCallable() { + return patchTracesCallable; } // AUTO-GENERATED DOCUMENTATION AND METHOD @@ -329,84 +312,101 @@ public final ApiCallable getTraceCallable() { // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Sends new traces to Cloud Trace or updates existing traces. If the ID of - * a trace that you send matches that of an existing trace, any fields - * in the existing trace and its spans are overwritten by the provided values, - * and any new fields provided are merged with the existing trace data. If the - * ID does not match, a new trace is created. + * Returns of a list of traces that match the specified filter conditions. * * Sample code: *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   Traces traces = Traces.newBuilder().build();
-   *   traceServiceApi.patchTraces(projectId, traces);
+   *   for (Trace element : traceServiceApi.listTraces(projectId)) {
+   *     // doThingsWith(element);
+   *   }
    * }
    * 
* * @param projectId ID of the Cloud project where the trace data is stored. - * @param traces The body of the message. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final void patchTraces(String projectId, Traces traces) { - PatchTracesRequest request = - PatchTracesRequest.newBuilder().setProjectId(projectId).setTraces(traces).build(); - patchTraces(request); + public final PageAccessor listTraces(String projectId) { + ListTracesRequest request = ListTracesRequest.newBuilder().setProjectId(projectId).build(); + return listTraces(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Sends new traces to Cloud Trace or updates existing traces. If the ID of - * a trace that you send matches that of an existing trace, any fields - * in the existing trace and its spans are overwritten by the provided values, - * and any new fields provided are merged with the existing trace data. If the - * ID does not match, a new trace is created. + * Returns of a list of traces that match the specified filter conditions. * * Sample code: *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   Traces traces = Traces.newBuilder().build();
-   *   PatchTracesRequest request = PatchTracesRequest.newBuilder()
+   *   ListTracesRequest request = ListTracesRequest.newBuilder()
    *     .setProjectId(projectId)
-   *     .setTraces(traces)
    *     .build();
-   *   traceServiceApi.patchTraces(request);
+   *   for (Trace element : traceServiceApi.listTraces(request)) {
+   *     // doThingsWith(element);
+   *   }
    * }
    * 
* * @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 void patchTraces(PatchTracesRequest request) { - patchTracesCallable().call(request); + public final PageAccessor listTraces(ListTracesRequest request) { + return listTracesPagedCallable().call(request); } // AUTO-GENERATED DOCUMENTATION AND METHOD /** - * Sends new traces to Cloud Trace or updates existing traces. If the ID of - * a trace that you send matches that of an existing trace, any fields - * in the existing trace and its spans are overwritten by the provided values, - * and any new fields provided are merged with the existing trace data. If the - * ID does not match, a new trace is created. + * Returns of a list of traces that match the specified filter conditions. * * Sample code: *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   Traces traces = Traces.newBuilder().build();
-   *   PatchTracesRequest request = PatchTracesRequest.newBuilder()
+   *   ListTracesRequest request = ListTracesRequest.newBuilder()
    *     .setProjectId(projectId)
-   *     .setTraces(traces)
    *     .build();
-   *   ListenableFuture<Void> future = traceServiceApi.patchTracesCallable().futureCall(request);
+   *   ListenableFuture<PageAccessor<Trace>> future = traceServiceApi.listTracesPagedCallable().futureCall(request);
    *   // Do something
-   *   future.get();
+   *   for (Trace element : future.get()) {
+   *     // doThingsWith(element);
+   *   }
    * }
    * 
*/ - public final ApiCallable patchTracesCallable() { - return patchTracesCallable; + public final ApiCallable> listTracesPagedCallable() { + return listTracesPagedCallable; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Returns of a list of traces that match the specified filter conditions. + * + * Sample code: + *

+   * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
+   *   String projectId = "";
+   *   ListTracesRequest request = ListTracesRequest.newBuilder()
+   *     .setProjectId(projectId)
+   *     .build();
+   *   while (true) {
+   *     ListTracesResponse response = traceServiceApi.listTracesCallable().call(request);
+   *     for (Trace element : response.getTracesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ */ + public final ApiCallable listTracesCallable() { + return listTracesCallable; } /** diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceSettings.java similarity index 97% rename from gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java rename to gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceSettings.java index 65d56fd3766b..640c805c3b50 100644 --- a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceSettings.java +++ b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceSettings.java @@ -11,7 +11,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package com.google.cloud.devtools.cloudtrace.spi.v1; +package com.google.cloud.cloudtrace.spi.v1; import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; @@ -55,13 +55,13 @@ * *

The builder of this class is recursive, so contained classes are themselves builders. * When build() is called, the tree of builders is called to create the complete settings - * object. For example, to set the total timeout of getTrace to 30 seconds: + * object. For example, to set the total timeout of patchTraces to 30 seconds: * *

  * 
  * TraceServiceSettings.Builder traceServiceSettingsBuilder =
  *     TraceServiceSettings.defaultBuilder();
- * traceServiceSettingsBuilder.getTraceSettings().getRetrySettingsBuilder()
+ * traceServiceSettingsBuilder.patchTracesSettings().getRetrySettingsBuilder()
  *     .setTotalTimeout(Duration.standardSeconds(30));
  * TraceServiceSettings traceServiceSettings = traceServiceSettingsBuilder.build();
  * 
@@ -99,17 +99,16 @@ public class TraceServiceSettings extends ServiceApiSettings {
           .provideCredentialsWith(DEFAULT_SERVICE_SCOPES)
           .build();
 
+  private final SimpleCallSettings patchTracesSettings;
+  private final SimpleCallSettings getTraceSettings;
   private final PageStreamingCallSettings
       listTracesSettings;
-  private final SimpleCallSettings getTraceSettings;
-  private final SimpleCallSettings patchTracesSettings;
 
   /**
-   * Returns the object with the settings used for calls to listTraces.
+   * Returns the object with the settings used for calls to patchTraces.
    */
-  public PageStreamingCallSettings
-      listTracesSettings() {
-    return listTracesSettings;
+  public SimpleCallSettings patchTracesSettings() {
+    return patchTracesSettings;
   }
 
   /**
@@ -120,10 +119,11 @@ public SimpleCallSettings getTraceSettings() {
   }
 
   /**
-   * Returns the object with the settings used for calls to patchTraces.
+   * Returns the object with the settings used for calls to listTraces.
    */
-  public SimpleCallSettings patchTracesSettings() {
-    return patchTracesSettings;
+  public PageStreamingCallSettings
+      listTracesSettings() {
+    return listTracesSettings;
   }
 
   /**
@@ -177,9 +177,9 @@ private TraceServiceSettings(Builder settingsBuilder) throws IOException {
         settingsBuilder.getClientLibName(),
         settingsBuilder.getClientLibVersion());
 
-    listTracesSettings = settingsBuilder.listTracesSettings().build();
-    getTraceSettings = settingsBuilder.getTraceSettings().build();
     patchTracesSettings = settingsBuilder.patchTracesSettings().build();
+    getTraceSettings = settingsBuilder.getTraceSettings().build();
+    listTracesSettings = settingsBuilder.listTracesSettings().build();
   }
 
   private static PageStreamingDescriptor
@@ -212,10 +212,10 @@ public Iterable extractResources(ListTracesResponse payload) {
   public static class Builder extends ServiceApiSettings.Builder {
     private final ImmutableList methodSettingsBuilders;
 
+    private SimpleCallSettings.Builder patchTracesSettings;
+    private SimpleCallSettings.Builder getTraceSettings;
     private PageStreamingCallSettings.Builder
         listTracesSettings;
-    private SimpleCallSettings.Builder getTraceSettings;
-    private SimpleCallSettings.Builder patchTracesSettings;
 
     private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS;
 
@@ -251,25 +251,25 @@ public static class Builder extends ServiceApiSettings.Builder {
     private Builder() {
       super(DEFAULT_CONNECTION_SETTINGS);
 
-      listTracesSettings =
-          PageStreamingCallSettings.newBuilder(
-              TraceServiceGrpc.METHOD_LIST_TRACES, LIST_TRACES_PAGE_STR_DESC);
+      patchTracesSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_PATCH_TRACES);
 
       getTraceSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_GET_TRACE);
 
-      patchTracesSettings = SimpleCallSettings.newBuilder(TraceServiceGrpc.METHOD_PATCH_TRACES);
+      listTracesSettings =
+          PageStreamingCallSettings.newBuilder(
+              TraceServiceGrpc.METHOD_LIST_TRACES, LIST_TRACES_PAGE_STR_DESC);
 
       methodSettingsBuilders =
           ImmutableList.of(
-              listTracesSettings, getTraceSettings, patchTracesSettings);
+              patchTracesSettings, getTraceSettings, listTracesSettings);
     }
 
     private static Builder createDefault() {
       Builder builder = new Builder();
 
       builder
-          .listTracesSettings()
-          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
+          .patchTracesSettings()
+          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
           .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default"));
 
       builder
@@ -278,8 +278,8 @@ private static Builder createDefault() {
           .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default"));
 
       builder
-          .patchTracesSettings()
-          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
+          .listTracesSettings()
+          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
           .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default"));
 
       return builder;
@@ -288,13 +288,13 @@ private static Builder createDefault() {
     private Builder(TraceServiceSettings settings) {
       super(settings);
 
-      listTracesSettings = settings.listTracesSettings.toBuilder();
-      getTraceSettings = settings.getTraceSettings.toBuilder();
       patchTracesSettings = settings.patchTracesSettings.toBuilder();
+      getTraceSettings = settings.getTraceSettings.toBuilder();
+      listTracesSettings = settings.listTracesSettings.toBuilder();
 
       methodSettingsBuilders =
           ImmutableList.of(
-              listTracesSettings, getTraceSettings, patchTracesSettings);
+              patchTracesSettings, getTraceSettings, listTracesSettings);
     }
 
     @Override
@@ -355,11 +355,10 @@ public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) thr
     }
 
     /**
-     * Returns the builder for the settings used for calls to listTraces.
+     * Returns the builder for the settings used for calls to patchTraces.
      */
-    public PageStreamingCallSettings.Builder
-        listTracesSettings() {
-      return listTracesSettings;
+    public SimpleCallSettings.Builder patchTracesSettings() {
+      return patchTracesSettings;
     }
 
     /**
@@ -370,10 +369,11 @@ public SimpleCallSettings.Builder getTraceSettings() {
     }
 
     /**
-     * Returns the builder for the settings used for calls to patchTraces.
+     * Returns the builder for the settings used for calls to listTraces.
      */
-    public SimpleCallSettings.Builder patchTracesSettings() {
-      return patchTracesSettings;
+    public PageStreamingCallSettings.Builder
+        listTracesSettings() {
+      return listTracesSettings;
     }
 
     @Override
diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/package-info.java
similarity index 90%
rename from gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java
rename to gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/package-info.java
index 72348fd07474..253fa31d1724 100644
--- a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/devtools/cloudtrace/spi/v1/package-info.java
+++ b/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/package-info.java
@@ -32,11 +32,11 @@
  * 
  * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
  *   String projectId = "";
- *   String traceId = "";
- *   Trace response = traceServiceApi.getTrace(projectId, traceId);
+ *   Traces traces = Traces.newBuilder().build();
+ *   traceServiceApi.patchTraces(projectId, traces);
  * }
  * 
  * 
* */ -package com.google.cloud.devtools.cloudtrace.spi.v1; +package com.google.cloud.cloudtrace.spi.v1; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceService.java similarity index 96% rename from gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java rename to gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceService.java index bb1666db72db..be94ee8e1170 100644 --- a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceService.java +++ b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceService.java @@ -12,7 +12,7 @@ * the License. */ -package com.google.cloud.devtools.cloudtrace.spi.v1; +package com.google.cloud.cloudtrace.spi.v1; import com.google.api.gax.testing.MockGrpcService; import com.google.devtools.cloudtrace.v1.TraceServiceGrpc; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceServiceImpl.java similarity index 98% rename from gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java rename to gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceServiceImpl.java index 7484b19a9c36..98992f1d849d 100644 --- a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/MockTraceServiceImpl.java +++ b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceServiceImpl.java @@ -12,7 +12,7 @@ * the License. */ -package com.google.cloud.devtools.cloudtrace.spi.v1; +package com.google.cloud.cloudtrace.spi.v1; import com.google.common.collect.Lists; import com.google.devtools.cloudtrace.v1.GetTraceRequest; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceTest.java similarity index 65% rename from gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java rename to gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceTest.java index 2fe514511909..074ffe18e5c5 100644 --- a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/devtools/cloudtrace/spi/v1/TraceServiceTest.java +++ b/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceTest.java @@ -12,7 +12,7 @@ * the License. */ -package com.google.cloud.devtools.cloudtrace.spi.v1; +package com.google.cloud.cloudtrace.spi.v1; import com.google.api.gax.core.PageAccessor; import com.google.api.gax.testing.MockGrpcService; @@ -28,23 +28,26 @@ import com.google.protobuf.GeneratedMessage; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import junit.framework.Assert; import org.junit.After; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @javax.annotation.Generated("by GAPIC") public class TraceServiceTest { + private static MockTraceService mockTraceService; private static MockServiceHelper serviceHelper; private TraceServiceApi api; @BeforeClass public static void startStaticServer() { - MockTraceService mockService = new MockTraceService(); - serviceHelper = new MockServiceHelper("in-process-1", mockService); + mockTraceService = new MockTraceService(); + serviceHelper = + new MockServiceHelper("in-process-1", Arrays.asList(mockTraceService)); serviceHelper.start(); } @@ -70,65 +73,79 @@ public void tearDown() throws Exception { @Test @SuppressWarnings("all") - public void listTracesTest() { - ListTracesResponse expectedResponse = ListTracesResponse.newBuilder().build(); + public void patchTracesTest() { + Empty expectedResponse = Empty.newBuilder().build(); List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); - serviceHelper.getService().setResponses(expectedResponses); + mockTraceService.setResponses(expectedResponses); - String projectId = ""; - PageAccessor pageAccessor = api.listTraces(projectId); + String projectId = "projectId-1969970175"; + Traces traces = Traces.newBuilder().build(); - // PageAccessor will not make actual request until it is being used. - // Add all the pages here in order to make grpc requests. - List resources = Lists.newArrayList(pageAccessor.getPageValues()); - Assert.assertEquals(0, resources.size()); + api.patchTraces(projectId, traces); - List actualRequests = serviceHelper.getService().getRequests(); + List actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); - ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0); + PatchTracesRequest actualRequest = (PatchTracesRequest) actualRequests.get(0); - Assert.assertEquals(actualRequest.getProjectId(), projectId); + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(traces, actualRequest.getTraces()); } @Test @SuppressWarnings("all") public void getTraceTest() { - Trace expectedResponse = Trace.newBuilder().build(); + String projectId2 = "projectId2939242356"; + String traceId2 = "traceId2987826376"; + Trace expectedResponse = + Trace.newBuilder().setProjectId(projectId2).setTraceId(traceId2).build(); List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); - serviceHelper.getService().setResponses(expectedResponses); + mockTraceService.setResponses(expectedResponses); + + String projectId = "projectId-1969970175"; + String traceId = "traceId1270300245"; - String projectId = ""; - String traceId = ""; Trace actualResponse = api.getTrace(projectId, traceId); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = serviceHelper.getService().getRequests(); + List actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTraceRequest actualRequest = (GetTraceRequest) actualRequests.get(0); - Assert.assertEquals(actualRequest.getProjectId(), projectId); - Assert.assertEquals(actualRequest.getTraceId(), traceId); + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(traceId, actualRequest.getTraceId()); } @Test @SuppressWarnings("all") - public void patchTracesTest() { - Empty expectedResponse = Empty.newBuilder().build(); + public void listTracesTest() { + Trace tracesElement = Trace.newBuilder().build(); + List traces = Arrays.asList(tracesElement); + String nextPageToken = "nextPageToken-1530815211"; + ListTracesResponse expectedResponse = + ListTracesResponse.newBuilder() + .addAllTraces(traces) + .setNextPageToken(nextPageToken) + .build(); List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); - serviceHelper.getService().setResponses(expectedResponses); + mockTraceService.setResponses(expectedResponses); - String projectId = ""; - Traces traces = Traces.newBuilder().build(); - api.patchTraces(projectId, traces); + String projectId = "projectId-1969970175"; + + PageAccessor pageAccessor = api.listTraces(projectId); - List actualRequests = serviceHelper.getService().getRequests(); + // PageAccessor will not make actual request until it is being used. + // Add all the pages here in order to make grpc requests. + List resources = Lists.newArrayList(pageAccessor.getPageValues()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTracesList().get(0), resources.get(0)); + + List actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); - PatchTracesRequest actualRequest = (PatchTracesRequest) actualRequests.get(0); + ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0); - Assert.assertEquals(actualRequest.getProjectId(), projectId); - Assert.assertEquals(actualRequest.getTraces(), traces); + Assert.assertEquals(projectId, actualRequest.getProjectId()); } } diff --git a/gcloud-java-core/pom.xml b/gcloud-java-core/pom.xml index 7dee8be38b68..50155634bd11 100644 --- a/gcloud-java-core/pom.xml +++ b/gcloud-java-core/pom.xml @@ -106,7 +106,7 @@ com.google.api gax - 0.0.15 + 0.0.16 com.google.api.grpc From 45cfd5634bb47c5e82a6ebb1dae56f8fc4238479 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Mon, 29 Aug 2016 15:45:10 -0700 Subject: [PATCH 3/5] Reverting directory pattern change for checkstyle --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4239a75bce22..bc5197cc16f1 100644 --- a/pom.xml +++ b/pom.xml @@ -324,7 +324,7 @@ error true true - com/google/cloud/**/spi/v*/** + com/google/cloud/*/spi/v*/** From 167d18ddf3df9e842063d64229ebffc48b5265aa Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 30 Aug 2016 10:24:47 -0700 Subject: [PATCH 4/5] Renaming 'cloudtrace' to 'trace' --- {gcloud-java-cloudtrace => gcloud-java-trace}/pom.xml | 0 .../java/com/google/cloud/trace}/spi/v1/TraceServiceApi.java | 2 +- .../com/google/cloud/trace}/spi/v1/TraceServiceSettings.java | 2 +- .../main/java/com/google/cloud/trace}/spi/v1/package-info.java | 2 +- .../java/com/google/cloud/trace}/spi/v1/MockTraceService.java | 2 +- .../com/google/cloud/trace}/spi/v1/MockTraceServiceImpl.java | 2 +- .../java/com/google/cloud/trace}/spi/v1/TraceServiceTest.java | 2 +- pom.xml | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename {gcloud-java-cloudtrace => gcloud-java-trace}/pom.xml (100%) rename {gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace => gcloud-java-trace/src/main/java/com/google/cloud/trace}/spi/v1/TraceServiceApi.java (99%) rename {gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace => gcloud-java-trace/src/main/java/com/google/cloud/trace}/spi/v1/TraceServiceSettings.java (99%) rename {gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace => gcloud-java-trace/src/main/java/com/google/cloud/trace}/spi/v1/package-info.java (97%) rename {gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace => gcloud-java-trace/src/test/java/com/google/cloud/trace}/spi/v1/MockTraceService.java (97%) rename {gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace => gcloud-java-trace/src/test/java/com/google/cloud/trace}/spi/v1/MockTraceServiceImpl.java (98%) rename {gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace => gcloud-java-trace/src/test/java/com/google/cloud/trace}/spi/v1/TraceServiceTest.java (99%) diff --git a/gcloud-java-cloudtrace/pom.xml b/gcloud-java-trace/pom.xml similarity index 100% rename from gcloud-java-cloudtrace/pom.xml rename to gcloud-java-trace/pom.xml diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceApi.java b/gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java similarity index 99% rename from gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceApi.java rename to gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java index da0acec67b71..0e94787987e7 100644 --- a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceApi.java +++ b/gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java @@ -11,7 +11,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package com.google.cloud.cloudtrace.spi.v1; +package com.google.cloud.trace.spi.v1; import com.google.api.gax.core.PageAccessor; import com.google.api.gax.grpc.ApiCallable; diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceSettings.java b/gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java similarity index 99% rename from gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceSettings.java rename to gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java index 640c805c3b50..145adeffed56 100644 --- a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceSettings.java +++ b/gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java @@ -11,7 +11,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package com.google.cloud.cloudtrace.spi.v1; +package com.google.cloud.trace.spi.v1; import com.google.api.gax.core.ConnectionSettings; import com.google.api.gax.core.RetrySettings; diff --git a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/package-info.java b/gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java similarity index 97% rename from gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/package-info.java rename to gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java index 253fa31d1724..32b3625ef678 100644 --- a/gcloud-java-cloudtrace/src/main/java/com/google/cloud/cloudtrace/spi/v1/package-info.java +++ b/gcloud-java-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java @@ -39,4 +39,4 @@ * * */ -package com.google.cloud.cloudtrace.spi.v1; +package com.google.cloud.trace.spi.v1; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceService.java b/gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java similarity index 97% rename from gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceService.java rename to gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java index be94ee8e1170..dab3938d506f 100644 --- a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceService.java +++ b/gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java @@ -12,7 +12,7 @@ * the License. */ -package com.google.cloud.cloudtrace.spi.v1; +package com.google.cloud.trace.spi.v1; import com.google.api.gax.testing.MockGrpcService; import com.google.devtools.cloudtrace.v1.TraceServiceGrpc; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceServiceImpl.java b/gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java similarity index 98% rename from gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceServiceImpl.java rename to gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java index 98992f1d849d..e1d2ea4929f0 100644 --- a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/MockTraceServiceImpl.java +++ b/gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java @@ -12,7 +12,7 @@ * the License. */ -package com.google.cloud.cloudtrace.spi.v1; +package com.google.cloud.trace.spi.v1; import com.google.common.collect.Lists; import com.google.devtools.cloudtrace.v1.GetTraceRequest; diff --git a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceTest.java b/gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java similarity index 99% rename from gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceTest.java rename to gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java index 074ffe18e5c5..9af39602f843 100644 --- a/gcloud-java-cloudtrace/src/test/java/com/google/cloud/cloudtrace/spi/v1/TraceServiceTest.java +++ b/gcloud-java-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java @@ -12,7 +12,7 @@ * the License. */ -package com.google.cloud.cloudtrace.spi.v1; +package com.google.cloud.trace.spi.v1; import com.google.api.gax.core.PageAccessor; import com.google.api.gax.testing.MockGrpcService; diff --git a/pom.xml b/pom.xml index bc5197cc16f1..172ae71777cf 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ gcloud-java gcloud-java-bigquery - gcloud-java-cloudtrace + gcloud-java-trace gcloud-java-compute gcloud-java-contrib gcloud-java-core From 3448e66e67fdeb3878faf52d575304a8deee7e97 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 30 Aug 2016 10:26:40 -0700 Subject: [PATCH 5/5] Updating missed instances of cloud trace -> trace --- gcloud-java-trace/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcloud-java-trace/pom.xml b/gcloud-java-trace/pom.xml index e2a4bd79b504..6796dc36415a 100644 --- a/gcloud-java-trace/pom.xml +++ b/gcloud-java-trace/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - gcloud-java-cloudtrace + gcloud-java-trace jar GCloud Java Stackdriver Trace - https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-cloudtrace + https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-trace Java idiomatic client for Stackdriver Trace. @@ -14,7 +14,7 @@ 0.2.9-SNAPSHOT - gcloud-java-cloudtrace + gcloud-java-trace