Skip to content

Commit

Permalink
Regenerating SPI classes
Browse files Browse the repository at this point in the history
* Updating grpc to 1.0.1 and protobuf to 3.0.0
* Converting PageAccessor to PagedListResponse
* Adding auto-generated tests for logging
  • Loading branch information
garrettjonesgoogle committed Sep 21, 2016
1 parent 4fe00dd commit deee5a3
Show file tree
Hide file tree
Showing 66 changed files with 1,555 additions and 486 deletions.
8 changes: 4 additions & 4 deletions google-cloud-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.0.0-beta-3</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>0.0.16</version>
<version>0.0.18</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-common-protos</artifactId>
<version>0.0.9</version>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-iam-v1</artifactId>
<version>0.0.9</version>
<version>0.1.0</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions google-cloud-errorreporting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-devtools-clouderrorreporting-v1beta1</artifactId>
<version>0.0.7</version>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>0.15.0</version>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.google.cloud.errorreporting.spi.v1beta1;

import com.google.api.gax.core.PageAccessor;
import com.google.api.gax.core.PagedListResponse;
import com.google.api.gax.grpc.ApiCallable;
import com.google.api.gax.protobuf.PathTemplate;
import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsRequest;
Expand Down Expand Up @@ -93,10 +93,14 @@ public class ErrorStatsServiceApi implements AutoCloseable {
private final List<AutoCloseable> closeables = new ArrayList<>();

private final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGroupStatsCallable;
private final ApiCallable<ListGroupStatsRequest, PageAccessor<ErrorGroupStats>>
private final ApiCallable<
ListGroupStatsRequest,
PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>>
listGroupStatsPagedCallable;
private final ApiCallable<ListEventsRequest, ListEventsResponse> listEventsCallable;
private final ApiCallable<ListEventsRequest, PageAccessor<ErrorEvent>> listEventsPagedCallable;
private final ApiCallable<
ListEventsRequest, PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent>>
listEventsPagedCallable;
private final ApiCallable<DeleteEventsRequest, DeleteEventsResponse> deleteEventsCallable;

public final ErrorStatsServiceSettings getSettings() {
Expand Down Expand Up @@ -190,7 +194,7 @@ public void close() throws IOException {
* try (ErrorStatsServiceApi errorStatsServiceApi = ErrorStatsServiceApi.create()) {
* String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]");
* QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();
* for (ErrorGroupStats element : errorStatsServiceApi.listGroupStats(formattedProjectName, timeRange)) {
* for (ErrorGroupStats element : errorStatsServiceApi.listGroupStats(formattedProjectName, timeRange).iterateAllElements()) {
* // doThingsWith(element);
* }
* }
Expand All @@ -208,8 +212,8 @@ public void close() throws IOException {
* higher response times or in returning incomplete results.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PageAccessor<ErrorGroupStats> listGroupStats(
String projectName, QueryTimeRange timeRange) {
public final PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>
listGroupStats(String projectName, QueryTimeRange timeRange) {
PROJECT_PATH_TEMPLATE.validate(projectName, "listGroupStats");
ListGroupStatsRequest request =
ListGroupStatsRequest.newBuilder()
Expand All @@ -232,7 +236,7 @@ public final PageAccessor<ErrorGroupStats> listGroupStats(
* .setProjectName(formattedProjectName)
* .setTimeRange(timeRange)
* .build();
* for (ErrorGroupStats element : errorStatsServiceApi.listGroupStats(request)) {
* for (ErrorGroupStats element : errorStatsServiceApi.listGroupStats(request).iterateAllElements()) {
* // doThingsWith(element);
* }
* }
Expand All @@ -241,7 +245,8 @@ public final PageAccessor<ErrorGroupStats> listGroupStats(
* @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<ErrorGroupStats> listGroupStats(ListGroupStatsRequest request) {
public final PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>
listGroupStats(ListGroupStatsRequest request) {
return listGroupStatsPagedCallable().call(request);
}

Expand All @@ -258,15 +263,17 @@ public final PageAccessor<ErrorGroupStats> listGroupStats(ListGroupStatsRequest
* .setProjectName(formattedProjectName)
* .setTimeRange(timeRange)
* .build();
* ListenableFuture&lt;PageAccessor&lt;ErrorGroupStats&gt;&gt; future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request);
* ListenableFuture&lt;PagedListResponse&lt;ListGroupStatsRequest,ListGroupStatsResponse,ErrorGroupStats&gt;&gt; future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request);
* // Do something
* for (ErrorGroupStats element : future.get()) {
* for (ErrorGroupStats element : future.get().iterateAllElements()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*/
public final ApiCallable<ListGroupStatsRequest, PageAccessor<ErrorGroupStats>>
public final ApiCallable<
ListGroupStatsRequest,
PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>>
listGroupStatsPagedCallable() {
return listGroupStatsPagedCallable;
}
Expand Down Expand Up @@ -312,7 +319,7 @@ public final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGrou
* try (ErrorStatsServiceApi errorStatsServiceApi = ErrorStatsServiceApi.create()) {
* String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]");
* String groupId = "";
* for (ErrorEvent element : errorStatsServiceApi.listEvents(formattedProjectName, groupId)) {
* for (ErrorEvent element : errorStatsServiceApi.listEvents(formattedProjectName, groupId).iterateAllElements()) {
* // doThingsWith(element);
* }
* }
Expand All @@ -325,7 +332,8 @@ public final ApiCallable<ListGroupStatsRequest, ListGroupStatsResponse> listGrou
* @param groupId [Required] The group for which events shall be returned.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final PageAccessor<ErrorEvent> listEvents(String projectName, String groupId) {
public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent> listEvents(
String projectName, String groupId) {
PROJECT_PATH_TEMPLATE.validate(projectName, "listEvents");
ListEventsRequest request =
ListEventsRequest.newBuilder().setProjectName(projectName).setGroupId(groupId).build();
Expand All @@ -345,7 +353,7 @@ public final PageAccessor<ErrorEvent> listEvents(String projectName, String grou
* .setProjectName(formattedProjectName)
* .setGroupId(groupId)
* .build();
* for (ErrorEvent element : errorStatsServiceApi.listEvents(request)) {
* for (ErrorEvent element : errorStatsServiceApi.listEvents(request).iterateAllElements()) {
* // doThingsWith(element);
* }
* }
Expand All @@ -354,7 +362,8 @@ public final PageAccessor<ErrorEvent> listEvents(String projectName, String grou
* @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<ErrorEvent> listEvents(ListEventsRequest request) {
public final PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent> listEvents(
ListEventsRequest request) {
return listEventsPagedCallable().call(request);
}

Expand All @@ -371,15 +380,17 @@ public final PageAccessor<ErrorEvent> listEvents(ListEventsRequest request) {
* .setProjectName(formattedProjectName)
* .setGroupId(groupId)
* .build();
* ListenableFuture&lt;PageAccessor&lt;ErrorEvent&gt;&gt; future = errorStatsServiceApi.listEventsPagedCallable().futureCall(request);
* ListenableFuture&lt;PagedListResponse&lt;ListEventsRequest,ListEventsResponse,ErrorEvent&gt;&gt; future = errorStatsServiceApi.listEventsPagedCallable().futureCall(request);
* // Do something
* for (ErrorEvent element : future.get()) {
* for (ErrorEvent element : future.get().iterateAllElements()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*/
public final ApiCallable<ListEventsRequest, PageAccessor<ErrorEvent>> listEventsPagedCallable() {
public final ApiCallable<
ListEventsRequest, PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent>>
listEventsPagedCallable() {
return listEventsPagedCallable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ public ListGroupStatsRequest injectToken(ListGroupStatsRequest payload, Object t
return ListGroupStatsRequest.newBuilder(payload).setPageToken((String) token).build();
}

@Override
public ListGroupStatsRequest injectPageSize(
ListGroupStatsRequest payload, int pageSize) {
return ListGroupStatsRequest.newBuilder(payload).setPageSize(pageSize).build();
}

@Override
public Integer extractPageSize(ListGroupStatsRequest payload) {
return payload.getPageSize();
}

@Override
public Object extractNextToken(ListGroupStatsResponse payload) {
return payload.getNextPageToken();
Expand All @@ -222,6 +233,16 @@ public ListEventsRequest injectToken(ListEventsRequest payload, Object token) {
return ListEventsRequest.newBuilder(payload).setPageToken((String) token).build();
}

@Override
public ListEventsRequest injectPageSize(ListEventsRequest payload, int pageSize) {
return ListEventsRequest.newBuilder(payload).setPageSize(pageSize).build();
}

@Override
public Integer extractPageSize(ListEventsRequest payload) {
return payload.getPageSize();
}

@Override
public Object extractNextToken(ListEventsResponse payload) {
return payload.getNextPageToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

package com.google.cloud.errorreporting.spi.v1beta1;

import com.google.api.gax.core.PageAccessor;
import com.google.api.gax.core.PagedListResponse;
import com.google.api.gax.testing.MockGrpcService;
import com.google.api.gax.testing.MockServiceHelper;
import com.google.common.collect.Lists;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup;
import com.google.devtools.clouderrorreporting.v1beta1.GetGroupRequest;
import com.google.devtools.clouderrorreporting.v1beta1.UpdateGroupRequest;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void getGroupTest() {
String name = "name3373707";
String groupId = "groupId506361563";
ErrorGroup expectedResponse = ErrorGroup.newBuilder().setName(name).setGroupId(groupId).build();
List<GeneratedMessage> expectedResponses = new ArrayList<>();
List<GeneratedMessageV3> expectedResponses = new ArrayList<>();
expectedResponses.add(expectedResponse);
mockErrorGroupService.setResponses(expectedResponses);

Expand All @@ -89,7 +89,7 @@ public void getGroupTest() {
ErrorGroup actualResponse = api.getGroup(formattedGroupName);
Assert.assertEquals(expectedResponse, actualResponse);

List<GeneratedMessage> actualRequests = mockErrorGroupService.getRequests();
List<GeneratedMessageV3> actualRequests = mockErrorGroupService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetGroupRequest actualRequest = (GetGroupRequest) actualRequests.get(0);

Expand All @@ -102,7 +102,7 @@ public void updateGroupTest() {
String name = "name3373707";
String groupId = "groupId506361563";
ErrorGroup expectedResponse = ErrorGroup.newBuilder().setName(name).setGroupId(groupId).build();
List<GeneratedMessage> expectedResponses = new ArrayList<>();
List<GeneratedMessageV3> expectedResponses = new ArrayList<>();
expectedResponses.add(expectedResponse);
mockErrorGroupService.setResponses(expectedResponses);

Expand All @@ -111,7 +111,7 @@ public void updateGroupTest() {
ErrorGroup actualResponse = api.updateGroup(group);
Assert.assertEquals(expectedResponse, actualResponse);

List<GeneratedMessage> actualRequests = mockErrorGroupService.getRequests();
List<GeneratedMessageV3> actualRequests = mockErrorGroupService.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateGroupRequest actualRequest = (UpdateGroupRequest) actualRequests.get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package com.google.cloud.errorreporting.spi.v1beta1;

import com.google.api.gax.core.PageAccessor;
import com.google.api.gax.core.PagedListResponse;
import com.google.api.gax.testing.MockGrpcService;
import com.google.api.gax.testing.MockServiceHelper;
import com.google.common.collect.Lists;
Expand All @@ -27,7 +27,7 @@
import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest;
import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse;
import com.google.devtools.clouderrorreporting.v1beta1.QueryTimeRange;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.GeneratedMessageV3;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -83,31 +83,29 @@ public void tearDown() throws Exception {
@Test
@SuppressWarnings("all")
public void listGroupStatsTest() {
String nextPageToken = "";
ErrorGroupStats errorGroupStatsElement = ErrorGroupStats.newBuilder().build();
List<ErrorGroupStats> errorGroupStats = Arrays.asList(errorGroupStatsElement);
String nextPageToken = "nextPageToken-1530815211";
ListGroupStatsResponse expectedResponse =
ListGroupStatsResponse.newBuilder()
.addAllErrorGroupStats(errorGroupStats)
.setNextPageToken(nextPageToken)
.addAllErrorGroupStats(errorGroupStats)
.build();
List<GeneratedMessage> expectedResponses = new ArrayList<>();
List<GeneratedMessageV3> expectedResponses = new ArrayList<>();
expectedResponses.add(expectedResponse);
mockErrorStatsService.setResponses(expectedResponses);

String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]");
QueryTimeRange timeRange = QueryTimeRange.newBuilder().build();

PageAccessor<ErrorGroupStats> pageAccessor =
api.listGroupStats(formattedProjectName, timeRange);
PagedListResponse<ListGroupStatsRequest, ListGroupStatsResponse, ErrorGroupStats>
pagedListResponse = api.listGroupStats(formattedProjectName, timeRange);

// PageAccessor will not make actual request until it is being used.
// Add all the pages here in order to make grpc requests.
List<ErrorGroupStats> resources = Lists.newArrayList(pageAccessor.getPageValues());
List<ErrorGroupStats> resources = Lists.newArrayList(pagedListResponse.iterateAllElements());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getErrorGroupStatsList().get(0), resources.get(0));

List<GeneratedMessage> actualRequests = mockErrorStatsService.getRequests();
List<GeneratedMessageV3> actualRequests = mockErrorStatsService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListGroupStatsRequest actualRequest = (ListGroupStatsRequest) actualRequests.get(0);

Expand All @@ -118,30 +116,29 @@ public void listGroupStatsTest() {
@Test
@SuppressWarnings("all")
public void listEventsTest() {
String nextPageToken = "";
ErrorEvent errorEventsElement = ErrorEvent.newBuilder().build();
List<ErrorEvent> errorEvents = Arrays.asList(errorEventsElement);
String nextPageToken = "nextPageToken-1530815211";
ListEventsResponse expectedResponse =
ListEventsResponse.newBuilder()
.addAllErrorEvents(errorEvents)
.setNextPageToken(nextPageToken)
.addAllErrorEvents(errorEvents)
.build();
List<GeneratedMessage> expectedResponses = new ArrayList<>();
List<GeneratedMessageV3> expectedResponses = new ArrayList<>();
expectedResponses.add(expectedResponse);
mockErrorStatsService.setResponses(expectedResponses);

String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]");
String groupId = "groupId506361563";

PageAccessor<ErrorEvent> pageAccessor = api.listEvents(formattedProjectName, groupId);
PagedListResponse<ListEventsRequest, ListEventsResponse, ErrorEvent> pagedListResponse =
api.listEvents(formattedProjectName, groupId);

// PageAccessor will not make actual request until it is being used.
// Add all the pages here in order to make grpc requests.
List<ErrorEvent> resources = Lists.newArrayList(pageAccessor.getPageValues());
List<ErrorEvent> resources = Lists.newArrayList(pagedListResponse.iterateAllElements());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getErrorEventsList().get(0), resources.get(0));

List<GeneratedMessage> actualRequests = mockErrorStatsService.getRequests();
List<GeneratedMessageV3> actualRequests = mockErrorStatsService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListEventsRequest actualRequest = (ListEventsRequest) actualRequests.get(0);

Expand All @@ -153,7 +150,7 @@ public void listEventsTest() {
@SuppressWarnings("all")
public void deleteEventsTest() {
DeleteEventsResponse expectedResponse = DeleteEventsResponse.newBuilder().build();
List<GeneratedMessage> expectedResponses = new ArrayList<>();
List<GeneratedMessageV3> expectedResponses = new ArrayList<>();
expectedResponses.add(expectedResponse);
mockErrorStatsService.setResponses(expectedResponses);

Expand All @@ -162,7 +159,7 @@ public void deleteEventsTest() {
DeleteEventsResponse actualResponse = api.deleteEvents(formattedProjectName);
Assert.assertEquals(expectedResponse, actualResponse);

List<GeneratedMessage> actualRequests = mockErrorStatsService.getRequests();
List<GeneratedMessageV3> actualRequests = mockErrorStatsService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteEventsRequest actualRequest = (DeleteEventsRequest) actualRequests.get(0);

Expand Down
Loading

0 comments on commit deee5a3

Please sign in to comment.