diff --git a/google-cloud-core/pom.xml b/google-cloud-core/pom.xml index 248eaa925fed..b1781b323813 100644 --- a/google-cloud-core/pom.xml +++ b/google-cloud-core/pom.xml @@ -101,22 +101,22 @@ com.google.protobuf protobuf-java - 3.0.0-beta-3 + 3.0.0 com.google.api gax - 0.0.16 + 0.0.18 com.google.api.grpc grpc-google-common-protos - 0.0.9 + 0.1.0 com.google.api.grpc grpc-google-iam-v1 - 0.0.9 + 0.1.0 diff --git a/google-cloud-datastore/pom.xml b/google-cloud-datastore/pom.xml index 7c36fdb405a8..f5252e62f6ad 100644 --- a/google-cloud-datastore/pom.xml +++ b/google-cloud-datastore/pom.xml @@ -25,12 +25,12 @@ com.google.cloud.datastore datastore-v1-protos - 1.0.1 + 1.2.0 com.google.cloud.datastore datastore-v1-proto-client - 1.1.0 + 1.2.0 ${project.groupId} diff --git a/google-cloud-errorreporting/pom.xml b/google-cloud-errorreporting/pom.xml index cd57c6eb3da3..1cef83845056 100644 --- a/google-cloud-errorreporting/pom.xml +++ b/google-cloud-errorreporting/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-devtools-clouderrorreporting-v1beta1 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java index 6f60aa7ebf70..a1efc7a1ff53 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceApi.java @@ -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; @@ -93,10 +93,14 @@ public class ErrorStatsServiceApi implements AutoCloseable { private final List closeables = new ArrayList<>(); private final ApiCallable listGroupStatsCallable; - private final ApiCallable> + private final ApiCallable< + ListGroupStatsRequest, + PagedListResponse> listGroupStatsPagedCallable; private final ApiCallable listEventsCallable; - private final ApiCallable> listEventsPagedCallable; + private final ApiCallable< + ListEventsRequest, PagedListResponse> + listEventsPagedCallable; private final ApiCallable deleteEventsCallable; public final ErrorStatsServiceSettings getSettings() { @@ -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); * } * } @@ -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 listGroupStats( - String projectName, QueryTimeRange timeRange) { + public final PagedListResponse + listGroupStats(String projectName, QueryTimeRange timeRange) { PROJECT_PATH_TEMPLATE.validate(projectName, "listGroupStats"); ListGroupStatsRequest request = ListGroupStatsRequest.newBuilder() @@ -232,7 +236,7 @@ public final PageAccessor listGroupStats( * .setProjectName(formattedProjectName) * .setTimeRange(timeRange) * .build(); - * for (ErrorGroupStats element : errorStatsServiceApi.listGroupStats(request)) { + * for (ErrorGroupStats element : errorStatsServiceApi.listGroupStats(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -241,7 +245,8 @@ public final PageAccessor 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 listGroupStats(ListGroupStatsRequest request) { + public final PagedListResponse + listGroupStats(ListGroupStatsRequest request) { return listGroupStatsPagedCallable().call(request); } @@ -258,15 +263,17 @@ public final PageAccessor listGroupStats(ListGroupStatsRequest * .setProjectName(formattedProjectName) * .setTimeRange(timeRange) * .build(); - * ListenableFuture<PageAccessor<ErrorGroupStats>> future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListGroupStatsRequest,ListGroupStatsResponse,ErrorGroupStats>> future = errorStatsServiceApi.listGroupStatsPagedCallable().futureCall(request); * // Do something - * for (ErrorGroupStats element : future.get()) { + * for (ErrorGroupStats element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ - public final ApiCallable> + public final ApiCallable< + ListGroupStatsRequest, + PagedListResponse> listGroupStatsPagedCallable() { return listGroupStatsPagedCallable; } @@ -312,7 +319,7 @@ public final ApiCallable 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); * } * } @@ -325,7 +332,8 @@ public final ApiCallable 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 listEvents(String projectName, String groupId) { + public final PagedListResponse listEvents( + String projectName, String groupId) { PROJECT_PATH_TEMPLATE.validate(projectName, "listEvents"); ListEventsRequest request = ListEventsRequest.newBuilder().setProjectName(projectName).setGroupId(groupId).build(); @@ -345,7 +353,7 @@ public final PageAccessor 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); * } * } @@ -354,7 +362,8 @@ public final PageAccessor 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 listEvents(ListEventsRequest request) { + public final PagedListResponse listEvents( + ListEventsRequest request) { return listEventsPagedCallable().call(request); } @@ -371,15 +380,17 @@ public final PageAccessor listEvents(ListEventsRequest request) { * .setProjectName(formattedProjectName) * .setGroupId(groupId) * .build(); - * ListenableFuture<PageAccessor<ErrorEvent>> future = errorStatsServiceApi.listEventsPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListEventsRequest,ListEventsResponse,ErrorEvent>> future = errorStatsServiceApi.listEventsPagedCallable().futureCall(request); * // Do something - * for (ErrorEvent element : future.get()) { + * for (ErrorEvent element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ - public final ApiCallable> listEventsPagedCallable() { + public final ApiCallable< + ListEventsRequest, PagedListResponse> + listEventsPagedCallable() { return listEventsPagedCallable; } diff --git a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java index 69fc9c5e2f39..992c5b1a1bab 100644 --- a/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java +++ b/google-cloud-errorreporting/src/main/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceSettings.java @@ -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(); @@ -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(); diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java index cdc572b8d62b..7ef1423e0800 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorGroupServiceTest.java @@ -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; @@ -80,7 +80,7 @@ public void getGroupTest() { String name = "name3373707"; String groupId = "groupId506361563"; ErrorGroup expectedResponse = ErrorGroup.newBuilder().setName(name).setGroupId(groupId).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockErrorGroupService.setResponses(expectedResponses); @@ -89,7 +89,7 @@ public void getGroupTest() { ErrorGroup actualResponse = api.getGroup(formattedGroupName); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockErrorGroupService.getRequests(); + List actualRequests = mockErrorGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetGroupRequest actualRequest = (GetGroupRequest) actualRequests.get(0); @@ -102,7 +102,7 @@ public void updateGroupTest() { String name = "name3373707"; String groupId = "groupId506361563"; ErrorGroup expectedResponse = ErrorGroup.newBuilder().setName(name).setGroupId(groupId).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockErrorGroupService.setResponses(expectedResponses); @@ -111,7 +111,7 @@ public void updateGroupTest() { ErrorGroup actualResponse = api.updateGroup(group); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockErrorGroupService.getRequests(); + List actualRequests = mockErrorGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); UpdateGroupRequest actualRequest = (UpdateGroupRequest) actualRequests.get(0); diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java index 51bf8f5a038e..df94dfc07b04 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ErrorStatsServiceTest.java @@ -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; @@ -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; @@ -83,31 +83,29 @@ public void tearDown() throws Exception { @Test @SuppressWarnings("all") public void listGroupStatsTest() { + String nextPageToken = ""; ErrorGroupStats errorGroupStatsElement = ErrorGroupStats.newBuilder().build(); List errorGroupStats = Arrays.asList(errorGroupStatsElement); - String nextPageToken = "nextPageToken-1530815211"; ListGroupStatsResponse expectedResponse = ListGroupStatsResponse.newBuilder() - .addAllErrorGroupStats(errorGroupStats) .setNextPageToken(nextPageToken) + .addAllErrorGroupStats(errorGroupStats) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockErrorStatsService.setResponses(expectedResponses); String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]"); QueryTimeRange timeRange = QueryTimeRange.newBuilder().build(); - PageAccessor pageAccessor = - api.listGroupStats(formattedProjectName, timeRange); + PagedListResponse + 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 resources = Lists.newArrayList(pageAccessor.getPageValues()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getErrorGroupStatsList().get(0), resources.get(0)); - List actualRequests = mockErrorStatsService.getRequests(); + List actualRequests = mockErrorStatsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListGroupStatsRequest actualRequest = (ListGroupStatsRequest) actualRequests.get(0); @@ -118,30 +116,29 @@ public void listGroupStatsTest() { @Test @SuppressWarnings("all") public void listEventsTest() { + String nextPageToken = ""; ErrorEvent errorEventsElement = ErrorEvent.newBuilder().build(); List errorEvents = Arrays.asList(errorEventsElement); - String nextPageToken = "nextPageToken-1530815211"; ListEventsResponse expectedResponse = ListEventsResponse.newBuilder() - .addAllErrorEvents(errorEvents) .setNextPageToken(nextPageToken) + .addAllErrorEvents(errorEvents) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockErrorStatsService.setResponses(expectedResponses); String formattedProjectName = ErrorStatsServiceApi.formatProjectName("[PROJECT]"); String groupId = "groupId506361563"; - PageAccessor pageAccessor = api.listEvents(formattedProjectName, groupId); + PagedListResponse 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 resources = Lists.newArrayList(pageAccessor.getPageValues()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getErrorEventsList().get(0), resources.get(0)); - List actualRequests = mockErrorStatsService.getRequests(); + List actualRequests = mockErrorStatsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListEventsRequest actualRequest = (ListEventsRequest) actualRequests.get(0); @@ -153,7 +150,7 @@ public void listEventsTest() { @SuppressWarnings("all") public void deleteEventsTest() { DeleteEventsResponse expectedResponse = DeleteEventsResponse.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockErrorStatsService.setResponses(expectedResponses); @@ -162,7 +159,7 @@ public void deleteEventsTest() { DeleteEventsResponse actualResponse = api.deleteEvents(formattedProjectName); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockErrorStatsService.getRequests(); + List actualRequests = mockErrorStatsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteEventsRequest actualRequest = (DeleteEventsRequest) actualRequests.get(0); diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupService.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupService.java index 92c6a61ea67d..90ae067c4c37 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupService.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockErrorGroupService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return ErrorGroupServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupServiceImpl.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupServiceImpl.java index 3678153cb933..c29fd57915ea 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupServiceImpl.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorGroupServiceImpl.java @@ -16,10 +16,10 @@ import com.google.common.collect.Lists; import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup; -import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupServiceGrpc.ErrorGroupService; +import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroupServiceGrpc.ErrorGroupServiceImplBase; 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 io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -27,20 +27,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockErrorGroupServiceImpl implements ErrorGroupService { - private ArrayList requests; - private Queue responses; +public class MockErrorGroupServiceImpl extends ErrorGroupServiceImplBase { + private ArrayList requests; + private Queue responses; public MockErrorGroupServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsService.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsService.java index 82ce45740c39..d3769a4d44ff 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsService.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.devtools.clouderrorreporting.v1beta1.ErrorStatsServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockErrorStatsService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return ErrorStatsServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsServiceImpl.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsServiceImpl.java index 52d1368bf09f..ef65d501f573 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsServiceImpl.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockErrorStatsServiceImpl.java @@ -17,12 +17,12 @@ import com.google.common.collect.Lists; import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsRequest; import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsResponse; -import com.google.devtools.clouderrorreporting.v1beta1.ErrorStatsServiceGrpc.ErrorStatsService; +import com.google.devtools.clouderrorreporting.v1beta1.ErrorStatsServiceGrpc.ErrorStatsServiceImplBase; import com.google.devtools.clouderrorreporting.v1beta1.ListEventsRequest; import com.google.devtools.clouderrorreporting.v1beta1.ListEventsResponse; import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest; import com.google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -30,20 +30,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockErrorStatsServiceImpl implements ErrorStatsService { - private ArrayList requests; - private Queue responses; +public class MockErrorStatsServiceImpl extends ErrorStatsServiceImplBase { + private ArrayList requests; + private Queue responses; public MockErrorStatsServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsService.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsService.java index 5e75dfaaa7ef..c519f91b52ac 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsService.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorsServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockReportErrorsService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return ReportErrorsServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsServiceImpl.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsServiceImpl.java index 82a35b178599..c1140f5d197e 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsServiceImpl.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/MockReportErrorsServiceImpl.java @@ -17,8 +17,8 @@ import com.google.common.collect.Lists; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse; -import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorsServiceGrpc.ReportErrorsService; -import com.google.protobuf.GeneratedMessage; +import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorsServiceGrpc.ReportErrorsServiceImplBase; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -26,20 +26,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockReportErrorsServiceImpl implements ReportErrorsService { - private ArrayList requests; - private Queue responses; +public class MockReportErrorsServiceImpl extends ReportErrorsServiceImplBase { + private ArrayList requests; + private Queue responses; public MockReportErrorsServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java index 618f46af081e..ff909ae74914 100644 --- a/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java +++ b/google-cloud-errorreporting/src/test/java/com/google/cloud/errorreporting/spi/v1beta1/ReportErrorsServiceTest.java @@ -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.ReportErrorEventRequest; import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse; import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -78,7 +78,7 @@ public void tearDown() throws Exception { @SuppressWarnings("all") public void reportErrorEventTest() { ReportErrorEventResponse expectedResponse = ReportErrorEventResponse.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockReportErrorsService.setResponses(expectedResponses); @@ -88,7 +88,7 @@ public void reportErrorEventTest() { ReportErrorEventResponse actualResponse = api.reportErrorEvent(formattedProjectName, event); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockReportErrorsService.getRequests(); + List actualRequests = mockReportErrorsService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ReportErrorEventRequest actualRequest = (ReportErrorEventRequest) actualRequests.get(0); diff --git a/google-cloud-language/pom.xml b/google-cloud-language/pom.xml index 030f70ba7497..298281d787f0 100644 --- a/google-cloud-language/pom.xml +++ b/google-cloud-language/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-cloud-language-v1beta1 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/LanguageServiceTest.java b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/LanguageServiceTest.java index 1e593e8c2e15..b52a92850f2c 100644 --- a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/LanguageServiceTest.java +++ b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/LanguageServiceTest.java @@ -14,7 +14,7 @@ package com.google.cloud.language.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.cloud.language.v1beta1.AnalyzeEntitiesRequest; @@ -27,7 +27,7 @@ import com.google.cloud.language.v1beta1.Document; import com.google.cloud.language.v1beta1.EncodingType; import com.google.common.collect.Lists; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -79,7 +79,7 @@ public void analyzeSentimentTest() { String language = "language-1613589672"; AnalyzeSentimentResponse expectedResponse = AnalyzeSentimentResponse.newBuilder().setLanguage(language).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockLanguageService.setResponses(expectedResponses); @@ -88,7 +88,7 @@ public void analyzeSentimentTest() { AnalyzeSentimentResponse actualResponse = api.analyzeSentiment(document); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockLanguageService.getRequests(); + List actualRequests = mockLanguageService.getRequests(); Assert.assertEquals(1, actualRequests.size()); AnalyzeSentimentRequest actualRequest = (AnalyzeSentimentRequest) actualRequests.get(0); @@ -101,7 +101,7 @@ public void analyzeEntitiesTest() { String language = "language-1613589672"; AnalyzeEntitiesResponse expectedResponse = AnalyzeEntitiesResponse.newBuilder().setLanguage(language).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockLanguageService.setResponses(expectedResponses); @@ -111,7 +111,7 @@ public void analyzeEntitiesTest() { AnalyzeEntitiesResponse actualResponse = api.analyzeEntities(document, encodingType); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockLanguageService.getRequests(); + List actualRequests = mockLanguageService.getRequests(); Assert.assertEquals(1, actualRequests.size()); AnalyzeEntitiesRequest actualRequest = (AnalyzeEntitiesRequest) actualRequests.get(0); @@ -125,7 +125,7 @@ public void annotateTextTest() { String language = "language-1613589672"; AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockLanguageService.setResponses(expectedResponses); @@ -136,7 +136,7 @@ public void annotateTextTest() { AnnotateTextResponse actualResponse = api.annotateText(document, features, encodingType); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockLanguageService.getRequests(); + List actualRequests = mockLanguageService.getRequests(); Assert.assertEquals(1, actualRequests.size()); AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0); diff --git a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageService.java b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageService.java index eeb79bcd52a7..24f01c0acb9b 100644 --- a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageService.java +++ b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.cloud.language.v1beta1.LanguageServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockLanguageService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return LanguageServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageServiceImpl.java b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageServiceImpl.java index 13379ee13b2b..ad228c216195 100644 --- a/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageServiceImpl.java +++ b/google-cloud-language/src/test/java/com/google/cloud/language/spi/v1beta1/MockLanguageServiceImpl.java @@ -20,9 +20,9 @@ import com.google.cloud.language.v1beta1.AnalyzeSentimentResponse; import com.google.cloud.language.v1beta1.AnnotateTextRequest; import com.google.cloud.language.v1beta1.AnnotateTextResponse; -import com.google.cloud.language.v1beta1.LanguageServiceGrpc.LanguageService; +import com.google.cloud.language.v1beta1.LanguageServiceGrpc.LanguageServiceImplBase; import com.google.common.collect.Lists; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -30,20 +30,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockLanguageServiceImpl implements LanguageService { - private ArrayList requests; - private Queue responses; +public class MockLanguageServiceImpl extends LanguageServiceImplBase { + private ArrayList requests; + private Queue responses; public MockLanguageServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-logging/pom.xml b/google-cloud-logging/pom.xml index bdd837e3f0a0..3686bc3fea7a 100644 --- a/google-cloud-logging/pom.xml +++ b/google-cloud-logging/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-logging-v2 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java index 8352fff2b838..10ed2502a01f 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Api.java @@ -13,7 +13,7 @@ */ package com.google.cloud.logging.spi.v2; -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.logging.v2.CreateSinkRequest; @@ -92,7 +92,9 @@ public class ConfigServiceV2Api implements AutoCloseable { private final List closeables = new ArrayList<>(); private final ApiCallable listSinksCallable; - private final ApiCallable> listSinksPagedCallable; + private final ApiCallable< + ListSinksRequest, PagedListResponse> + listSinksPagedCallable; private final ApiCallable getSinkCallable; private final ApiCallable createSinkCallable; private final ApiCallable updateSinkCallable; @@ -218,7 +220,7 @@ public void close() throws IOException { *

    * try (ConfigServiceV2Api configServiceV2Api = ConfigServiceV2Api.create()) {
    *   String formattedParent = ConfigServiceV2Api.formatParentName("[PROJECT]");
-   *   for (LogSink element : configServiceV2Api.listSinks(formattedParent)) {
+   *   for (LogSink element : configServiceV2Api.listSinks(formattedParent).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -228,7 +230,8 @@ public void close() throws IOException {
    * Example: `"projects/my-logging-project"`.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final PageAccessor listSinks(String parent) {
+  public final PagedListResponse listSinks(
+      String parent) {
     PARENT_PATH_TEMPLATE.validate(parent, "listSinks");
     ListSinksRequest request = ListSinksRequest.newBuilder().setParent(parent).build();
     return listSinks(request);
@@ -245,7 +248,7 @@ public final PageAccessor listSinks(String parent) {
    *   ListSinksRequest request = ListSinksRequest.newBuilder()
    *     .setParent(formattedParent)
    *     .build();
-   *   for (LogSink element : configServiceV2Api.listSinks(request)) {
+   *   for (LogSink element : configServiceV2Api.listSinks(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -254,7 +257,8 @@ public final PageAccessor listSinks(String parent) {
    * @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 listSinks(ListSinksRequest request) {
+  public final PagedListResponse listSinks(
+      ListSinksRequest request) {
     return listSinksPagedCallable().call(request);
   }
 
@@ -269,15 +273,17 @@ public final PageAccessor listSinks(ListSinksRequest request) {
    *   ListSinksRequest request = ListSinksRequest.newBuilder()
    *     .setParent(formattedParent)
    *     .build();
-   *   ListenableFuture<PageAccessor<LogSink>> future = configServiceV2Api.listSinksPagedCallable().futureCall(request);
+   *   ListenableFuture<PagedListResponse<ListSinksRequest,ListSinksResponse,LogSink>> future = configServiceV2Api.listSinksPagedCallable().futureCall(request);
    *   // Do something
-   *   for (LogSink element : future.get()) {
+   *   for (LogSink element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ - public final ApiCallable> listSinksPagedCallable() { + public final ApiCallable< + ListSinksRequest, PagedListResponse> + listSinksPagedCallable() { return listSinksPagedCallable; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java index 39215faeef26..db0dc45cf200 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Settings.java @@ -217,6 +217,16 @@ public ListSinksRequest injectToken(ListSinksRequest payload, Object token) { return ListSinksRequest.newBuilder(payload).setPageToken((String) token).build(); } + @Override + public ListSinksRequest injectPageSize(ListSinksRequest payload, int pageSize) { + return ListSinksRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListSinksRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListSinksResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java index be62409e99a9..ee24b1012771 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Api.java @@ -15,7 +15,7 @@ import com.google.api.MonitoredResource; import com.google.api.MonitoredResourceDescriptor; -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.logging.v2.DeleteLogRequest; @@ -31,7 +31,6 @@ import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledExecutorService; @@ -99,13 +98,18 @@ public class LoggingServiceV2Api implements AutoCloseable { private final ApiCallable writeLogEntriesCallable; private final ApiCallable listLogEntriesCallable; - private final ApiCallable> + private final ApiCallable< + ListLogEntriesRequest, + PagedListResponse> listLogEntriesPagedCallable; private final ApiCallable< ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable; private final ApiCallable< - ListMonitoredResourceDescriptorsRequest, PageAccessor> + ListMonitoredResourceDescriptorsRequest, + PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsPagedCallable; public final LoggingServiceV2Settings getSettings() { @@ -299,11 +303,11 @@ public final ApiCallable deleteLogCallable() { * Sample code: *

    * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
-   *   String logName = "";
+   *   String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]");
    *   MonitoredResource resource = MonitoredResource.newBuilder().build();
    *   Map<String, String> labels = new HashMap<>();
    *   List<LogEntry> entries = new ArrayList<>();
-   *   WriteLogEntriesResponse response = loggingServiceV2Api.writeLogEntries(logName, resource, labels, entries);
+   *   WriteLogEntriesResponse response = loggingServiceV2Api.writeLogEntries(formattedLogName, resource, labels, entries);
    * }
    * 
* @@ -330,7 +334,9 @@ public final WriteLogEntriesResponse writeLogEntries( MonitoredResource resource, Map labels, List entries) { - LOG_PATH_TEMPLATE.validate(logName, "writeLogEntries"); + if (!logName.isEmpty()) { + LOG_PATH_TEMPLATE.validate(logName, "writeLogEntries"); + } WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder() .setLogName(logName) @@ -399,7 +405,7 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * List<String> projectIds = new ArrayList<>(); * String filter = ""; * String orderBy = ""; - * for (LogEntry element : loggingServiceV2Api.listLogEntries(projectIds, filter, orderBy)) { + * for (LogEntry element : loggingServiceV2Api.listLogEntries(projectIds, filter, orderBy).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -419,8 +425,8 @@ public final WriteLogEntriesResponse writeLogEntries(WriteLogEntriesRequest requ * timestamps are returned in order of `LogEntry.insertId`. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listLogEntries( - List projectIds, String filter, String orderBy) { + public final PagedListResponse + listLogEntries(List projectIds, String filter, String orderBy) { ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() .addAllProjectIds(projectIds) @@ -443,7 +449,7 @@ public final PageAccessor listLogEntries( * ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() * .addAllProjectIds(projectIds) * .build(); - * for (LogEntry element : loggingServiceV2Api.listLogEntries(request)) { + * for (LogEntry element : loggingServiceV2Api.listLogEntries(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -452,7 +458,8 @@ public final PageAccessor listLogEntries( * @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 listLogEntries(ListLogEntriesRequest request) { + public final PagedListResponse + listLogEntries(ListLogEntriesRequest request) { return listLogEntriesPagedCallable().call(request); } @@ -469,15 +476,17 @@ public final PageAccessor listLogEntries(ListLogEntriesRequest request * ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() * .addAllProjectIds(projectIds) * .build(); - * ListenableFuture<PageAccessor<LogEntry>> future = loggingServiceV2Api.listLogEntriesPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListLogEntriesRequest,ListLogEntriesResponse,LogEntry>> future = loggingServiceV2Api.listLogEntriesPagedCallable().futureCall(request); * // Do something - * for (LogEntry element : future.get()) { + * for (LogEntry element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ - public final ApiCallable> + public final ApiCallable< + ListLogEntriesRequest, + PagedListResponse> listLogEntriesPagedCallable() { return listLogEntriesPagedCallable; } @@ -521,9 +530,8 @@ public final ApiCallable listLogE * Sample code: *

    * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
-   *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
-   *     .build();
-   *   for (MonitoredResourceDescriptor element : loggingServiceV2Api.listMonitoredResourceDescriptors(request)) {
+   *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
+   *   for (MonitoredResourceDescriptor element : loggingServiceV2Api.listMonitoredResourceDescriptors(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -532,8 +540,10 @@ public final ApiCallable listLogE
    * @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 listMonitoredResourceDescriptors(
-      ListMonitoredResourceDescriptorsRequest request) {
+  public final PagedListResponse<
+          ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse,
+          MonitoredResourceDescriptor>
+      listMonitoredResourceDescriptors(ListMonitoredResourceDescriptorsRequest request) {
     return listMonitoredResourceDescriptorsPagedCallable().call(request);
   }
 
@@ -544,18 +554,20 @@ public final PageAccessor listMonitoredResourceDesc
    * Sample code:
    * 

    * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
-   *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
-   *     .build();
-   *   ListenableFuture<PageAccessor<MonitoredResourceDescriptor>> future = loggingServiceV2Api.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
+   *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
+   *   ListenableFuture<PagedListResponse<ListMonitoredResourceDescriptorsRequest,ListMonitoredResourceDescriptorsResponse,MonitoredResourceDescriptor>> future = loggingServiceV2Api.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
    *   // Do something
-   *   for (MonitoredResourceDescriptor element : future.get()) {
+   *   for (MonitoredResourceDescriptor element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ public final ApiCallable< - ListMonitoredResourceDescriptorsRequest, PageAccessor> + ListMonitoredResourceDescriptorsRequest, + PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsPagedCallable() { return listMonitoredResourceDescriptorsPagedCallable; } @@ -567,8 +579,7 @@ public final PageAccessor listMonitoredResourceDesc * Sample code: *

    * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
-   *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
-   *     .build();
+   *   ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
    *   while (true) {
    *     ListMonitoredResourceDescriptorsResponse response = loggingServiceV2Api.listMonitoredResourceDescriptorsCallable().call(request);
    *     for (MonitoredResourceDescriptor element : response.getResourceDescriptorsList()) {
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java
index 0e0f4da5e345..360c5970b0c0 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Settings.java
@@ -219,6 +219,17 @@ public ListLogEntriesRequest injectToken(ListLogEntriesRequest payload, Object t
               return ListLogEntriesRequest.newBuilder(payload).setPageToken((String) token).build();
             }
 
+            @Override
+            public ListLogEntriesRequest injectPageSize(
+                ListLogEntriesRequest payload, int pageSize) {
+              return ListLogEntriesRequest.newBuilder(payload).setPageSize(pageSize).build();
+            }
+
+            @Override
+            public Integer extractPageSize(ListLogEntriesRequest payload) {
+              return payload.getPageSize();
+            }
+
             @Override
             public Object extractNextToken(ListLogEntriesResponse payload) {
               return payload.getNextPageToken();
@@ -250,6 +261,19 @@ public ListMonitoredResourceDescriptorsRequest injectToken(
                   .build();
             }
 
+            @Override
+            public ListMonitoredResourceDescriptorsRequest injectPageSize(
+                ListMonitoredResourceDescriptorsRequest payload, int pageSize) {
+              return ListMonitoredResourceDescriptorsRequest.newBuilder(payload)
+                  .setPageSize(pageSize)
+                  .build();
+            }
+
+            @Override
+            public Integer extractPageSize(ListMonitoredResourceDescriptorsRequest payload) {
+              return payload.getPageSize();
+            }
+
             @Override
             public Object extractNextToken(ListMonitoredResourceDescriptorsResponse payload) {
               return payload.getNextPageToken();
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java
index 8d76a2579dba..5a1b16237a76 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Api.java
@@ -13,7 +13,7 @@
  */
 package com.google.cloud.logging.spi.v2;
 
-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.logging.v2.CreateLogMetricRequest;
@@ -91,7 +91,9 @@ public class MetricsServiceV2Api implements AutoCloseable {
   private final List closeables = new ArrayList<>();
 
   private final ApiCallable listLogMetricsCallable;
-  private final ApiCallable>
+  private final ApiCallable<
+          ListLogMetricsRequest,
+          PagedListResponse>
       listLogMetricsPagedCallable;
   private final ApiCallable getLogMetricCallable;
   private final ApiCallable createLogMetricCallable;
@@ -219,7 +221,7 @@ public void close() throws IOException {
    * 

    * try (MetricsServiceV2Api metricsServiceV2Api = MetricsServiceV2Api.create()) {
    *   String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]");
-   *   for (LogMetric element : metricsServiceV2Api.listLogMetrics(formattedParent)) {
+   *   for (LogMetric element : metricsServiceV2Api.listLogMetrics(formattedParent).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -229,7 +231,8 @@ public void close() throws IOException {
    * Example: `"projects/my-project-id"`.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final PageAccessor listLogMetrics(String parent) {
+  public final PagedListResponse
+      listLogMetrics(String parent) {
     PARENT_PATH_TEMPLATE.validate(parent, "listLogMetrics");
     ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(parent).build();
     return listLogMetrics(request);
@@ -246,7 +249,7 @@ public final PageAccessor listLogMetrics(String parent) {
    *   ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
    *     .setParent(formattedParent)
    *     .build();
-   *   for (LogMetric element : metricsServiceV2Api.listLogMetrics(request)) {
+   *   for (LogMetric element : metricsServiceV2Api.listLogMetrics(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -255,7 +258,8 @@ public final PageAccessor listLogMetrics(String parent) {
    * @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 listLogMetrics(ListLogMetricsRequest request) {
+  public final PagedListResponse
+      listLogMetrics(ListLogMetricsRequest request) {
     return listLogMetricsPagedCallable().call(request);
   }
 
@@ -270,15 +274,17 @@ public final PageAccessor listLogMetrics(ListLogMetricsRequest reques
    *   ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder()
    *     .setParent(formattedParent)
    *     .build();
-   *   ListenableFuture<PageAccessor<LogMetric>> future = metricsServiceV2Api.listLogMetricsPagedCallable().futureCall(request);
+   *   ListenableFuture<PagedListResponse<ListLogMetricsRequest,ListLogMetricsResponse,LogMetric>> future = metricsServiceV2Api.listLogMetricsPagedCallable().futureCall(request);
    *   // Do something
-   *   for (LogMetric element : future.get()) {
+   *   for (LogMetric element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ - public final ApiCallable> + public final ApiCallable< + ListLogMetricsRequest, + PagedListResponse> listLogMetricsPagedCallable() { return listLogMetricsPagedCallable; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java index 9667eca31176..e48680230dcf 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Settings.java @@ -217,6 +217,17 @@ public ListLogMetricsRequest injectToken(ListLogMetricsRequest payload, Object t return ListLogMetricsRequest.newBuilder(payload).setPageToken((String) token).build(); } + @Override + public ListLogMetricsRequest injectPageSize( + ListLogMetricsRequest payload, int pageSize) { + return ListLogMetricsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListLogMetricsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListLogMetricsResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java index d683ce334a24..e16b370463dc 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/package-info.java @@ -17,6 +17,22 @@ * * The interfaces provided are listed below, along with a usage sample * + * =================== + * LoggingServiceV2Api + * =================== + * + * Service Description: Service for ingesting and querying logs. + * + * Sample for LoggingServiceV2Api: + *
+ * 
+ * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
+ *   String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]");
+ *   loggingServiceV2Api.deleteLog(formattedLogName);
+ * }
+ * 
+ * 
+ * * ================== * ConfigServiceV2Api * ================== @@ -50,21 +66,5 @@ *
*
* - * =================== - * LoggingServiceV2Api - * =================== - * - * Service Description: Service for ingesting and querying logs. - * - * Sample for LoggingServiceV2Api: - *
- * 
- * try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create()) {
- *   String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]");
- *   loggingServiceV2Api.deleteLog(formattedLogName);
- * }
- * 
- * 
- * */ package com.google.cloud.logging.spi.v2; diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingHelper.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingHelper.java index 21c6a7bbecfa..015b31ac6e1c 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingHelper.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingHelper.java @@ -49,7 +49,7 @@ public LocalLoggingHelper(String addressString) { NettyServerBuilder.forAddress(address) .flowControlWindow(FLOW_CONTROL_WINDOW) .channelType(LocalServerChannel.class); - builder.addService(LoggingServiceV2Grpc.bindService(loggingImpl)); + builder.addService(loggingImpl.bindService()); server = builder.build(); } /** diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingImpl.java index 81e09944f935..044af5d1b257 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingImpl.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/testing/LocalLoggingImpl.java @@ -33,7 +33,7 @@ import java.util.List; import java.util.Map; -public class LocalLoggingImpl implements LoggingServiceV2Grpc.LoggingServiceV2 { +public class LocalLoggingImpl extends LoggingServiceV2Grpc.LoggingServiceV2ImplBase { private Map> logs = new HashMap<>(); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java new file mode 100644 index 000000000000..4ea8363a0dd8 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/ConfigServiceV2Test.java @@ -0,0 +1,204 @@ +/* + * 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.logging.spi.v2; + +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.logging.v2.CreateSinkRequest; +import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.ListSinksRequest; +import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.LogSink; +import com.google.logging.v2.UpdateSinkRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +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 ConfigServiceV2Test { + private static MockLoggingServiceV2 mockLoggingServiceV2; + private static MockConfigServiceV2 mockConfigServiceV2; + private static MockMetricsServiceV2 mockMetricsServiceV2; + private static MockServiceHelper serviceHelper; + private ConfigServiceV2Api api; + + @BeforeClass + public static void startStaticServer() { + mockLoggingServiceV2 = new MockLoggingServiceV2(); + mockConfigServiceV2 = new MockConfigServiceV2(); + mockMetricsServiceV2 = new MockMetricsServiceV2(); + serviceHelper = + new MockServiceHelper( + "in-process-1", + Arrays.asList( + mockLoggingServiceV2, mockConfigServiceV2, mockMetricsServiceV2)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + ConfigServiceV2Settings settings = + ConfigServiceV2Settings.defaultBuilder() + .provideChannelWith(serviceHelper.createChannel(), true) + .build(); + api = ConfigServiceV2Api.create(settings); + } + + @After + public void tearDown() throws Exception { + api.close(); + } + + @Test + @SuppressWarnings("all") + public void listSinksTest() { + String nextPageToken = ""; + LogSink sinksElement = LogSink.newBuilder().build(); + List sinks = Arrays.asList(sinksElement); + ListSinksResponse expectedResponse = + ListSinksResponse.newBuilder().setNextPageToken(nextPageToken).addAllSinks(sinks).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockConfigServiceV2.setResponses(expectedResponses); + + String formattedParent = ConfigServiceV2Api.formatParentName("[PROJECT]"); + + PagedListResponse pagedListResponse = + api.listSinks(formattedParent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSinksRequest actualRequest = (ListSinksRequest) actualRequests.get(0); + + Assert.assertEquals(formattedParent, actualRequest.getParent()); + } + + @Test + @SuppressWarnings("all") + public void getSinkTest() { + String name = "name3373707"; + String destination = "destination-1429847026"; + String filter = "filter-1274492040"; + LogSink expectedResponse = + LogSink.newBuilder().setName(name).setDestination(destination).setFilter(filter).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockConfigServiceV2.setResponses(expectedResponses); + + String formattedSinkName = ConfigServiceV2Api.formatSinkName("[PROJECT]", "[SINK]"); + + LogSink actualResponse = api.getSink(formattedSinkName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetSinkRequest actualRequest = (GetSinkRequest) actualRequests.get(0); + + Assert.assertEquals(formattedSinkName, actualRequest.getSinkName()); + } + + @Test + @SuppressWarnings("all") + public void createSinkTest() { + String name = "name3373707"; + String destination = "destination-1429847026"; + String filter = "filter-1274492040"; + LogSink expectedResponse = + LogSink.newBuilder().setName(name).setDestination(destination).setFilter(filter).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockConfigServiceV2.setResponses(expectedResponses); + + String formattedParent = ConfigServiceV2Api.formatParentName("[PROJECT]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = api.createSink(formattedParent, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSinkRequest actualRequest = (CreateSinkRequest) actualRequests.get(0); + + Assert.assertEquals(formattedParent, actualRequest.getParent()); + Assert.assertEquals(sink, actualRequest.getSink()); + } + + @Test + @SuppressWarnings("all") + public void updateSinkTest() { + String name = "name3373707"; + String destination = "destination-1429847026"; + String filter = "filter-1274492040"; + LogSink expectedResponse = + LogSink.newBuilder().setName(name).setDestination(destination).setFilter(filter).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockConfigServiceV2.setResponses(expectedResponses); + + String formattedSinkName = ConfigServiceV2Api.formatSinkName("[PROJECT]", "[SINK]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = api.updateSink(formattedSinkName, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateSinkRequest actualRequest = (UpdateSinkRequest) actualRequests.get(0); + + Assert.assertEquals(formattedSinkName, actualRequest.getSinkName()); + Assert.assertEquals(sink, actualRequest.getSink()); + } + + @Test + @SuppressWarnings("all") + public void deleteSinkTest() { + Empty expectedResponse = Empty.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockConfigServiceV2.setResponses(expectedResponses); + + String formattedSinkName = ConfigServiceV2Api.formatSinkName("[PROJECT]", "[SINK]"); + + api.deleteSink(formattedSinkName); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteSinkRequest actualRequest = (DeleteSinkRequest) actualRequests.get(0); + + Assert.assertEquals(formattedSinkName, actualRequest.getSinkName()); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2ApiTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2ApiTest.java deleted file mode 100644 index a463cc1c69a3..000000000000 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2ApiTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2015 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.logging.spi.v2; - -import com.google.api.MonitoredResource; -import com.google.api.gax.core.PageAccessor; -import com.google.cloud.logging.spi.v2.testing.LocalLoggingHelper; -import com.google.common.collect.Iterables; -import com.google.logging.v2.LogEntry; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class LoggingServiceV2ApiTest { - private static LocalLoggingHelper loggingHelper; - private LoggingServiceV2Api loggingApi; - - @BeforeClass - public static void startStaticServer() { - loggingHelper = new LocalLoggingHelper("in-process-1"); - loggingHelper.start(); - } - - @AfterClass - public static void stopServer() { - loggingHelper.shutdownNow(); - } - - @Before - public void setUp() throws IOException { - loggingHelper.reset(); - LoggingServiceV2Settings settings = LoggingServiceV2Settings.defaultBuilder() - .provideChannelWith(loggingHelper.createChannel(), true) - .build(); - loggingApi = LoggingServiceV2Api.create(settings); - } - - @After - public void tearDown() throws Exception { - loggingApi.close(); - } - - @Test - public void testWriteLog() { - String logName = LoggingServiceV2Api.formatLogName("my-project", "my-log"); - MonitoredResource resource = MonitoredResource.newBuilder().build(); - List entries = new ArrayList<>(); - entries.add(LogEntry.newBuilder().setLogName(logName).setTextPayload("foobar").build()); - loggingApi.writeLogEntries(logName, resource, Collections.emptyMap(), entries); - } - - @Test - public void testListLog() { - String logName = LoggingServiceV2Api.formatLogName("my-project", "my-log"); - MonitoredResource resource = MonitoredResource.newBuilder().build(); - List entries = new ArrayList<>(); - entries.add(LogEntry.newBuilder().setLogName(logName).setTextPayload("foobar").build()); - loggingApi.writeLogEntries(logName, resource, Collections.emptyMap(), entries); - - PageAccessor gotEntries = - loggingApi.listLogEntries(Collections.singletonList("my-project"), "", ""); - Assert.assertTrue(Iterables.elementsEqual(entries, gotEntries)); - } - - @Test - public void testListNoLog() { - PageAccessor entries = - loggingApi.listLogEntries(Collections.singletonList("my-project"), "", ""); - Assert.assertTrue(Iterables.isEmpty(entries)); - } - - @Test - public void testDeleteLog() { - String logName = LoggingServiceV2Api.formatLogName("my-project", "my-log"); - MonitoredResource resource = MonitoredResource.newBuilder().build(); - List entries = new ArrayList<>(); - entries.add(LogEntry.newBuilder().setLogName(logName).setTextPayload("foobar").build()); - loggingApi.writeLogEntries(logName, resource, Collections.emptyMap(), entries); - - loggingApi.deleteLog(logName); - - PageAccessor gotEntries = - loggingApi.listLogEntries(Collections.singletonList("my-project"), "", ""); - Assert.assertTrue(Iterables.isEmpty(gotEntries)); - } -} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java new file mode 100644 index 000000000000..24e7dcd5d64e --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/LoggingServiceV2Test.java @@ -0,0 +1,164 @@ +/* + * 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.logging.spi.v2; + +import com.google.api.MonitoredResource; +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.logging.v2.DeleteLogRequest; +import com.google.logging.v2.ListLogEntriesRequest; +import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.LogEntry; +import com.google.logging.v2.WriteLogEntriesRequest; +import com.google.logging.v2.WriteLogEntriesResponse; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +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 LoggingServiceV2Test { + private static MockLoggingServiceV2 mockLoggingServiceV2; + private static MockConfigServiceV2 mockConfigServiceV2; + private static MockMetricsServiceV2 mockMetricsServiceV2; + private static MockServiceHelper serviceHelper; + private LoggingServiceV2Api api; + + @BeforeClass + public static void startStaticServer() { + mockLoggingServiceV2 = new MockLoggingServiceV2(); + mockConfigServiceV2 = new MockConfigServiceV2(); + mockMetricsServiceV2 = new MockMetricsServiceV2(); + serviceHelper = + new MockServiceHelper( + "in-process-1", + Arrays.asList( + mockLoggingServiceV2, mockConfigServiceV2, mockMetricsServiceV2)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + LoggingServiceV2Settings settings = + LoggingServiceV2Settings.defaultBuilder() + .provideChannelWith(serviceHelper.createChannel(), true) + .build(); + api = LoggingServiceV2Api.create(settings); + } + + @After + public void tearDown() throws Exception { + api.close(); + } + + @Test + @SuppressWarnings("all") + public void deleteLogTest() { + Empty expectedResponse = Empty.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockLoggingServiceV2.setResponses(expectedResponses); + + String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]"); + + api.deleteLog(formattedLogName); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteLogRequest actualRequest = (DeleteLogRequest) actualRequests.get(0); + + Assert.assertEquals(formattedLogName, actualRequest.getLogName()); + } + + @Test + @SuppressWarnings("all") + public void writeLogEntriesTest() { + WriteLogEntriesResponse expectedResponse = WriteLogEntriesResponse.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockLoggingServiceV2.setResponses(expectedResponses); + + String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]"); + MonitoredResource resource = MonitoredResource.newBuilder().build(); + Map labels = new HashMap<>(); + List entries = new ArrayList<>(); + + WriteLogEntriesResponse actualResponse = + api.writeLogEntries(formattedLogName, resource, labels, entries); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + WriteLogEntriesRequest actualRequest = (WriteLogEntriesRequest) actualRequests.get(0); + + Assert.assertEquals(formattedLogName, actualRequest.getLogName()); + Assert.assertEquals(resource, actualRequest.getResource()); + Assert.assertEquals(labels, actualRequest.getLabels()); + Assert.assertEquals(entries, actualRequest.getEntriesList()); + } + + @Test + @SuppressWarnings("all") + public void listLogEntriesTest() { + String nextPageToken = ""; + LogEntry entriesElement = LogEntry.newBuilder().build(); + List entries = Arrays.asList(entriesElement); + ListLogEntriesResponse expectedResponse = + ListLogEntriesResponse.newBuilder() + .setNextPageToken(nextPageToken) + .addAllEntries(entries) + .build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockLoggingServiceV2.setResponses(expectedResponses); + + List projectIds = new ArrayList<>(); + String filter = "filter-1274492040"; + String orderBy = "orderBy1234304744"; + + PagedListResponse pagedListResponse = + api.listLogEntries(projectIds, filter, orderBy); + + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getEntriesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogEntriesRequest actualRequest = (ListLogEntriesRequest) actualRequests.get(0); + + Assert.assertEquals(projectIds, actualRequest.getProjectIdsList()); + Assert.assertEquals(filter, actualRequest.getFilter()); + Assert.assertEquals(orderBy, actualRequest.getOrderBy()); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java new file mode 100644 index 000000000000..a497c5570804 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MetricsServiceV2Test.java @@ -0,0 +1,207 @@ +/* + * 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.logging.spi.v2; + +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.logging.v2.CreateLogMetricRequest; +import com.google.logging.v2.DeleteLogMetricRequest; +import com.google.logging.v2.GetLogMetricRequest; +import com.google.logging.v2.ListLogMetricsRequest; +import com.google.logging.v2.ListLogMetricsResponse; +import com.google.logging.v2.LogMetric; +import com.google.logging.v2.UpdateLogMetricRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +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 MetricsServiceV2Test { + private static MockLoggingServiceV2 mockLoggingServiceV2; + private static MockConfigServiceV2 mockConfigServiceV2; + private static MockMetricsServiceV2 mockMetricsServiceV2; + private static MockServiceHelper serviceHelper; + private MetricsServiceV2Api api; + + @BeforeClass + public static void startStaticServer() { + mockLoggingServiceV2 = new MockLoggingServiceV2(); + mockConfigServiceV2 = new MockConfigServiceV2(); + mockMetricsServiceV2 = new MockMetricsServiceV2(); + serviceHelper = + new MockServiceHelper( + "in-process-1", + Arrays.asList( + mockLoggingServiceV2, mockConfigServiceV2, mockMetricsServiceV2)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + MetricsServiceV2Settings settings = + MetricsServiceV2Settings.defaultBuilder() + .provideChannelWith(serviceHelper.createChannel(), true) + .build(); + api = MetricsServiceV2Api.create(settings); + } + + @After + public void tearDown() throws Exception { + api.close(); + } + + @Test + @SuppressWarnings("all") + public void listLogMetricsTest() { + String nextPageToken = ""; + LogMetric metricsElement = LogMetric.newBuilder().build(); + List metrics = Arrays.asList(metricsElement); + ListLogMetricsResponse expectedResponse = + ListLogMetricsResponse.newBuilder() + .setNextPageToken(nextPageToken) + .addAllMetrics(metrics) + .build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockMetricsServiceV2.setResponses(expectedResponses); + + String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]"); + + PagedListResponse pagedListResponse = + api.listLogMetrics(formattedParent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMetricsList().get(0), resources.get(0)); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogMetricsRequest actualRequest = (ListLogMetricsRequest) actualRequests.get(0); + + Assert.assertEquals(formattedParent, actualRequest.getParent()); + } + + @Test + @SuppressWarnings("all") + public void getLogMetricTest() { + String name = "name3373707"; + String description = "description-1724546052"; + String filter = "filter-1274492040"; + LogMetric expectedResponse = + LogMetric.newBuilder().setName(name).setDescription(description).setFilter(filter).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockMetricsServiceV2.setResponses(expectedResponses); + + String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]"); + + LogMetric actualResponse = api.getLogMetric(formattedMetricName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetLogMetricRequest actualRequest = (GetLogMetricRequest) actualRequests.get(0); + + Assert.assertEquals(formattedMetricName, actualRequest.getMetricName()); + } + + @Test + @SuppressWarnings("all") + public void createLogMetricTest() { + String name = "name3373707"; + String description = "description-1724546052"; + String filter = "filter-1274492040"; + LogMetric expectedResponse = + LogMetric.newBuilder().setName(name).setDescription(description).setFilter(filter).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockMetricsServiceV2.setResponses(expectedResponses); + + String formattedParent = MetricsServiceV2Api.formatParentName("[PROJECT]"); + LogMetric metric = LogMetric.newBuilder().build(); + + LogMetric actualResponse = api.createLogMetric(formattedParent, metric); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateLogMetricRequest actualRequest = (CreateLogMetricRequest) actualRequests.get(0); + + Assert.assertEquals(formattedParent, actualRequest.getParent()); + Assert.assertEquals(metric, actualRequest.getMetric()); + } + + @Test + @SuppressWarnings("all") + public void updateLogMetricTest() { + String name = "name3373707"; + String description = "description-1724546052"; + String filter = "filter-1274492040"; + LogMetric expectedResponse = + LogMetric.newBuilder().setName(name).setDescription(description).setFilter(filter).build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockMetricsServiceV2.setResponses(expectedResponses); + + String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]"); + LogMetric metric = LogMetric.newBuilder().build(); + + LogMetric actualResponse = api.updateLogMetric(formattedMetricName, metric); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateLogMetricRequest actualRequest = (UpdateLogMetricRequest) actualRequests.get(0); + + Assert.assertEquals(formattedMetricName, actualRequest.getMetricName()); + Assert.assertEquals(metric, actualRequest.getMetric()); + } + + @Test + @SuppressWarnings("all") + public void deleteLogMetricTest() { + Empty expectedResponse = Empty.newBuilder().build(); + List expectedResponses = new ArrayList<>(); + expectedResponses.add(expectedResponse); + mockMetricsServiceV2.setResponses(expectedResponses); + + String formattedMetricName = MetricsServiceV2Api.formatMetricName("[PROJECT]", "[METRIC]"); + + api.deleteLogMetric(formattedMetricName); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteLogMetricRequest actualRequest = (DeleteLogMetricRequest) actualRequests.get(0); + + Assert.assertEquals(formattedMetricName, actualRequest.getMetricName()); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockConfigServiceV2.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockConfigServiceV2.java new file mode 100644 index 000000000000..faf30424ebd5 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockConfigServiceV2.java @@ -0,0 +1,49 @@ +/* + * 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.logging.spi.v2; + +import com.google.api.gax.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +public class MockConfigServiceV2 implements MockGrpcService { + private MockConfigServiceV2Impl serviceImpl; + + public MockConfigServiceV2() { + serviceImpl = new MockConfigServiceV2Impl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void setResponses(List responses) { + serviceImpl.setResponses(responses); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockConfigServiceV2Impl.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockConfigServiceV2Impl.java new file mode 100644 index 000000000000..8e5d22e40c69 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockConfigServiceV2Impl.java @@ -0,0 +1,97 @@ +/* + * 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.logging.spi.v2; + +import com.google.common.collect.Lists; +import com.google.logging.v2.ConfigServiceV2Grpc.ConfigServiceV2ImplBase; +import com.google.logging.v2.CreateSinkRequest; +import com.google.logging.v2.DeleteSinkRequest; +import com.google.logging.v2.GetSinkRequest; +import com.google.logging.v2.ListSinksRequest; +import com.google.logging.v2.ListSinksResponse; +import com.google.logging.v2.LogSink; +import com.google.logging.v2.UpdateSinkRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +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 MockConfigServiceV2Impl extends ConfigServiceV2ImplBase { + private ArrayList requests; + private Queue responses; + + public MockConfigServiceV2Impl() { + 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 listSinks( + ListSinksRequest request, StreamObserver responseObserver) { + ListSinksResponse response = (ListSinksResponse) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void getSink(GetSinkRequest request, StreamObserver responseObserver) { + LogSink response = (LogSink) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void createSink(CreateSinkRequest request, StreamObserver responseObserver) { + LogSink response = (LogSink) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void updateSink(UpdateSinkRequest request, StreamObserver responseObserver) { + LogSink response = (LogSink) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void deleteSink(DeleteSinkRequest request, StreamObserver responseObserver) { + Empty response = (Empty) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2.java new file mode 100644 index 000000000000..236addeff7a9 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2.java @@ -0,0 +1,49 @@ +/* + * 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.logging.spi.v2; + +import com.google.api.gax.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +public class MockLoggingServiceV2 implements MockGrpcService { + private MockLoggingServiceV2Impl serviceImpl; + + public MockLoggingServiceV2() { + serviceImpl = new MockLoggingServiceV2Impl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void setResponses(List responses) { + serviceImpl.setResponses(responses); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java new file mode 100644 index 000000000000..2964cfc0ed91 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockLoggingServiceV2Impl.java @@ -0,0 +1,93 @@ +/* + * 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.logging.spi.v2; + +import com.google.common.collect.Lists; +import com.google.logging.v2.DeleteLogRequest; +import com.google.logging.v2.ListLogEntriesRequest; +import com.google.logging.v2.ListLogEntriesResponse; +import com.google.logging.v2.ListMonitoredResourceDescriptorsRequest; +import com.google.logging.v2.ListMonitoredResourceDescriptorsResponse; +import com.google.logging.v2.LoggingServiceV2Grpc.LoggingServiceV2ImplBase; +import com.google.logging.v2.WriteLogEntriesRequest; +import com.google.logging.v2.WriteLogEntriesResponse; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +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 MockLoggingServiceV2Impl extends LoggingServiceV2ImplBase { + private ArrayList requests; + private Queue responses; + + public MockLoggingServiceV2Impl() { + 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 deleteLog(DeleteLogRequest request, StreamObserver responseObserver) { + Empty response = (Empty) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void writeLogEntries( + WriteLogEntriesRequest request, StreamObserver responseObserver) { + WriteLogEntriesResponse response = (WriteLogEntriesResponse) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void listLogEntries( + ListLogEntriesRequest request, StreamObserver responseObserver) { + ListLogEntriesResponse response = (ListLogEntriesResponse) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void listMonitoredResourceDescriptors( + ListMonitoredResourceDescriptorsRequest request, + StreamObserver responseObserver) { + ListMonitoredResourceDescriptorsResponse response = + (ListMonitoredResourceDescriptorsResponse) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockMetricsServiceV2.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockMetricsServiceV2.java new file mode 100644 index 000000000000..8b0ea5526094 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockMetricsServiceV2.java @@ -0,0 +1,49 @@ +/* + * 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.logging.spi.v2; + +import com.google.api.gax.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +public class MockMetricsServiceV2 implements MockGrpcService { + private MockMetricsServiceV2Impl serviceImpl; + + public MockMetricsServiceV2() { + serviceImpl = new MockMetricsServiceV2Impl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void setResponses(List responses) { + serviceImpl.setResponses(responses); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockMetricsServiceV2Impl.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockMetricsServiceV2Impl.java new file mode 100644 index 000000000000..99a44483ee00 --- /dev/null +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/spi/v2/MockMetricsServiceV2Impl.java @@ -0,0 +1,101 @@ +/* + * 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.logging.spi.v2; + +import com.google.common.collect.Lists; +import com.google.logging.v2.CreateLogMetricRequest; +import com.google.logging.v2.DeleteLogMetricRequest; +import com.google.logging.v2.GetLogMetricRequest; +import com.google.logging.v2.ListLogMetricsRequest; +import com.google.logging.v2.ListLogMetricsResponse; +import com.google.logging.v2.LogMetric; +import com.google.logging.v2.MetricsServiceV2Grpc.MetricsServiceV2ImplBase; +import com.google.logging.v2.UpdateLogMetricRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.GeneratedMessageV3; +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 MockMetricsServiceV2Impl extends MetricsServiceV2ImplBase { + private ArrayList requests; + private Queue responses; + + public MockMetricsServiceV2Impl() { + 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 listLogMetrics( + ListLogMetricsRequest request, StreamObserver responseObserver) { + ListLogMetricsResponse response = (ListLogMetricsResponse) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void getLogMetric( + GetLogMetricRequest request, StreamObserver responseObserver) { + LogMetric response = (LogMetric) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void createLogMetric( + CreateLogMetricRequest request, StreamObserver responseObserver) { + LogMetric response = (LogMetric) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void updateLogMetric( + UpdateLogMetricRequest request, StreamObserver responseObserver) { + LogMetric response = (LogMetric) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + + @Override + public void deleteLogMetric( + DeleteLogMetricRequest request, StreamObserver responseObserver) { + Empty response = (Empty) responses.remove(); + requests.add(request); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } +} diff --git a/google-cloud-monitoring/pom.xml b/google-cloud-monitoring/pom.xml index 8ff98bf15c44..3570d2adb35b 100644 --- a/google-cloud-monitoring/pom.xml +++ b/google-cloud-monitoring/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-monitoring-v3 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java index b0e44057ca58..78608f7f1c0d 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceApi.java @@ -14,7 +14,7 @@ package com.google.cloud.monitoring.spi.v3; import com.google.api.MonitoredResource; -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.monitoring.v3.CreateGroupRequest; @@ -106,14 +106,18 @@ public class GroupServiceApi implements AutoCloseable { private final List closeables = new ArrayList<>(); private final ApiCallable listGroupsCallable; - private final ApiCallable> listGroupsPagedCallable; + private final ApiCallable< + ListGroupsRequest, PagedListResponse> + listGroupsPagedCallable; private final ApiCallable getGroupCallable; private final ApiCallable createGroupCallable; private final ApiCallable updateGroupCallable; private final ApiCallable deleteGroupCallable; private final ApiCallable listGroupMembersCallable; - private final ApiCallable> + private final ApiCallable< + ListGroupMembersRequest, + PagedListResponse> listGroupMembersPagedCallable; public final GroupServiceSettings getSettings() { @@ -244,7 +248,7 @@ public void close() throws IOException { * ListGroupsRequest request = ListGroupsRequest.newBuilder() * .setName(formattedName) * .build(); - * for (Group element : groupServiceApi.listGroups(request)) { + * for (Group element : groupServiceApi.listGroups(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -253,7 +257,8 @@ public void close() throws IOException { * @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 listGroups(ListGroupsRequest request) { + public final PagedListResponse listGroups( + ListGroupsRequest request) { return listGroupsPagedCallable().call(request); } @@ -269,15 +274,17 @@ public final PageAccessor listGroups(ListGroupsRequest request) { * ListGroupsRequest request = ListGroupsRequest.newBuilder() * .setName(formattedName) * .build(); - * ListenableFuture<PageAccessor<Group>> future = groupServiceApi.listGroupsPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListGroupsRequest,ListGroupsResponse,Group>> future = groupServiceApi.listGroupsPagedCallable().futureCall(request); * // Do something - * for (Group element : future.get()) { + * for (Group element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } *
*/ - public final ApiCallable> listGroupsPagedCallable() { + public final ApiCallable< + ListGroupsRequest, PagedListResponse> + listGroupsPagedCallable() { return listGroupsPagedCallable; } @@ -622,7 +629,7 @@ public final ApiCallable deleteGroupCallable() { * String formattedName = GroupServiceApi.formatGroupName("[PROJECT]", "[GROUP]"); * String filter = ""; * TimeInterval interval = TimeInterval.newBuilder().build(); - * for (MonitoredResource element : groupServiceApi.listGroupMembers(formattedName, filter, interval)) { + * for (MonitoredResource element : groupServiceApi.listGroupMembers(formattedName, filter, interval).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -643,8 +650,9 @@ public final ApiCallable deleteGroupCallable() { * membership over the last minute is returned. * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listGroupMembers( - String name, String filter, TimeInterval interval) { + public final PagedListResponse< + ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> + listGroupMembers(String name, String filter, TimeInterval interval) { GROUP_PATH_TEMPLATE.validate(name, "listGroupMembers"); ListGroupMembersRequest request = ListGroupMembersRequest.newBuilder() @@ -671,7 +679,7 @@ public final PageAccessor listGroupMembers( * .setFilter(filter) * .setInterval(interval) * .build(); - * for (MonitoredResource element : groupServiceApi.listGroupMembers(request)) { + * for (MonitoredResource element : groupServiceApi.listGroupMembers(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -680,7 +688,9 @@ public final PageAccessor listGroupMembers( * @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 listGroupMembers(ListGroupMembersRequest request) { + public final PagedListResponse< + ListGroupMembersRequest, ListGroupMembersResponse, MonitoredResource> + listGroupMembers(ListGroupMembersRequest request) { return listGroupMembersPagedCallable().call(request); } @@ -700,15 +710,17 @@ public final PageAccessor listGroupMembers(ListGroupMembersRe * .setFilter(filter) * .setInterval(interval) * .build(); - * ListenableFuture<PageAccessor<MonitoredResource>> future = groupServiceApi.listGroupMembersPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListGroupMembersRequest,ListGroupMembersResponse,MonitoredResource>> future = groupServiceApi.listGroupMembersPagedCallable().futureCall(request); * // Do something - * for (MonitoredResource element : future.get()) { + * for (MonitoredResource element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ - public final ApiCallable> + public final ApiCallable< + ListGroupMembersRequest, + PagedListResponse> listGroupMembersPagedCallable() { return listGroupMembersPagedCallable; } diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java index a414f70a079e..5a13158b02d2 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/GroupServiceSettings.java @@ -227,6 +227,16 @@ public ListGroupsRequest injectToken(ListGroupsRequest payload, Object token) { return ListGroupsRequest.newBuilder(payload).setPageToken((String) token).build(); } + @Override + public ListGroupsRequest injectPageSize(ListGroupsRequest payload, int pageSize) { + return ListGroupsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListGroupsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListGroupsResponse payload) { return payload.getNextPageToken(); @@ -256,6 +266,17 @@ public ListGroupMembersRequest injectToken( .build(); } + @Override + public ListGroupMembersRequest injectPageSize( + ListGroupMembersRequest payload, int pageSize) { + return ListGroupMembersRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListGroupMembersRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListGroupMembersResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java index 09d5ba3d45f5..da6546754f39 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceApi.java @@ -15,10 +15,9 @@ import com.google.api.MetricDescriptor; import com.google.api.MonitoredResourceDescriptor; -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.monitoring.v3.Aggregation; import com.google.monitoring.v3.CreateMetricDescriptorRequest; import com.google.monitoring.v3.CreateTimeSeriesRequest; import com.google.monitoring.v3.DeleteMetricDescriptorRequest; @@ -29,9 +28,7 @@ import com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest; import com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse; import com.google.monitoring.v3.ListTimeSeriesRequest; -import com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView; import com.google.monitoring.v3.ListTimeSeriesResponse; -import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.TimeSeries; import com.google.protobuf.Empty; import io.grpc.ManagedChannel; @@ -105,13 +102,19 @@ public class MetricServiceApi implements AutoCloseable { ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable; private final ApiCallable< - ListMonitoredResourceDescriptorsRequest, PageAccessor> + ListMonitoredResourceDescriptorsRequest, + PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsPagedCallable; private final ApiCallable getMonitoredResourceDescriptorCallable; private final ApiCallable listMetricDescriptorsCallable; - private final ApiCallable> + private final ApiCallable< + ListMetricDescriptorsRequest, + PagedListResponse< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor>> listMetricDescriptorsPagedCallable; private final ApiCallable getMetricDescriptorCallable; @@ -119,7 +122,9 @@ public class MetricServiceApi implements AutoCloseable { createMetricDescriptorCallable; private final ApiCallable deleteMetricDescriptorCallable; private final ApiCallable listTimeSeriesCallable; - private final ApiCallable> + private final ApiCallable< + ListTimeSeriesRequest, + PagedListResponse> listTimeSeriesPagedCallable; private final ApiCallable createTimeSeriesCallable; @@ -301,7 +306,7 @@ public void close() throws IOException { * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) { * String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); * String filter = ""; - * for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(formattedName, filter)) { + * for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(formattedName, filter).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -318,8 +323,10 @@ public void close() throws IOException { * resource.type = starts_with("gce_") AND resource.label:id * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listMonitoredResourceDescriptors( - String name, String filter) { + public final PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptors(String name, String filter) { PROJECT_PATH_TEMPLATE.validate(name, "listMonitoredResourceDescriptors"); ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder() @@ -342,7 +349,7 @@ public final PageAccessor listMonitoredResourceDesc * .setName(formattedName) * .setFilter(filter) * .build(); - * for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(request)) { + * for (MonitoredResourceDescriptor element : metricServiceApi.listMonitoredResourceDescriptors(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -351,8 +358,10 @@ public final PageAccessor listMonitoredResourceDesc * @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 listMonitoredResourceDescriptors( - ListMonitoredResourceDescriptorsRequest request) { + public final PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + listMonitoredResourceDescriptors(ListMonitoredResourceDescriptorsRequest request) { return listMonitoredResourceDescriptorsPagedCallable().call(request); } @@ -369,16 +378,19 @@ public final PageAccessor listMonitoredResourceDesc * .setName(formattedName) * .setFilter(filter) * .build(); - * ListenableFuture<PageAccessor<MonitoredResourceDescriptor>> future = metricServiceApi.listMonitoredResourceDescriptorsPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListMonitoredResourceDescriptorsRequest,ListMonitoredResourceDescriptorsResponse,MonitoredResourceDescriptor>> future = metricServiceApi.listMonitoredResourceDescriptorsPagedCallable().futureCall(request); * // Do something - * for (MonitoredResourceDescriptor element : future.get()) { + * for (MonitoredResourceDescriptor element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ public final ApiCallable< - ListMonitoredResourceDescriptorsRequest, PageAccessor> + ListMonitoredResourceDescriptorsRequest, + PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsPagedCallable() { return listMonitoredResourceDescriptorsPagedCallable; } @@ -496,7 +508,7 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( * try (MetricServiceApi metricServiceApi = MetricServiceApi.create()) { * String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); * String filter = ""; - * for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(formattedName, filter)) { + * for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(formattedName, filter).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -514,7 +526,9 @@ private final MonitoredResourceDescriptor getMonitoredResourceDescriptor( * metric.type = starts_with("custom.googleapis.com/") * @throws com.google.api.gax.grpc.ApiException if the remote call fails */ - public final PageAccessor listMetricDescriptors(String name, String filter) { + public final PagedListResponse< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + listMetricDescriptors(String name, String filter) { PROJECT_PATH_TEMPLATE.validate(name, "listMetricDescriptors"); ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder().setName(name).setFilter(filter).build(); @@ -534,7 +548,7 @@ public final PageAccessor listMetricDescriptors(String name, S * .setName(formattedName) * .setFilter(filter) * .build(); - * for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(request)) { + * for (MetricDescriptor element : metricServiceApi.listMetricDescriptors(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -543,8 +557,9 @@ public final PageAccessor listMetricDescriptors(String name, S * @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 listMetricDescriptors( - ListMetricDescriptorsRequest request) { + public final PagedListResponse< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor> + listMetricDescriptors(ListMetricDescriptorsRequest request) { return listMetricDescriptorsPagedCallable().call(request); } @@ -561,15 +576,18 @@ public final PageAccessor listMetricDescriptors( * .setName(formattedName) * .setFilter(filter) * .build(); - * ListenableFuture<PageAccessor<MetricDescriptor>> future = metricServiceApi.listMetricDescriptorsPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListMetricDescriptorsRequest,ListMetricDescriptorsResponse,MetricDescriptor>> future = metricServiceApi.listMetricDescriptorsPagedCallable().futureCall(request); * // Do something - * for (MetricDescriptor element : future.get()) { + * for (MetricDescriptor element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ - public final ApiCallable> + public final ApiCallable< + ListMetricDescriptorsRequest, + PagedListResponse< + ListMetricDescriptorsRequest, ListMetricDescriptorsResponse, MetricDescriptor>> listMetricDescriptorsPagedCallable() { return listMetricDescriptorsPagedCallable; } @@ -852,7 +870,7 @@ public final ApiCallable deleteMetricDescr * .setOrderBy(orderBy) * .setView(view) * .build(); - * for (TimeSeries element : metricServiceApi.listTimeSeries(request)) { + * for (TimeSeries element : metricServiceApi.listTimeSeries(request).iterateAllElements()) { * // doThingsWith(element); * } * } @@ -861,7 +879,8 @@ public final ApiCallable deleteMetricDescr * @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 listTimeSeries(ListTimeSeriesRequest request) { + public final PagedListResponse + listTimeSeries(ListTimeSeriesRequest request) { return listTimeSeriesPagedCallable().call(request); } @@ -886,15 +905,17 @@ public final PageAccessor listTimeSeries(ListTimeSeriesRequest reque * .setOrderBy(orderBy) * .setView(view) * .build(); - * ListenableFuture<PageAccessor<TimeSeries>> future = metricServiceApi.listTimeSeriesPagedCallable().futureCall(request); + * ListenableFuture<PagedListResponse<ListTimeSeriesRequest,ListTimeSeriesResponse,TimeSeries>> future = metricServiceApi.listTimeSeriesPagedCallable().futureCall(request); * // Do something - * for (TimeSeries element : future.get()) { + * for (TimeSeries element : future.get().iterateAllElements()) { * // doThingsWith(element); * } * } * */ - public final ApiCallable> + public final ApiCallable< + ListTimeSeriesRequest, + PagedListResponse> listTimeSeriesPagedCallable() { return listTimeSeriesPagedCallable; } diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java index 27831a6e861e..e52ce64c5ca1 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/MetricServiceSettings.java @@ -272,6 +272,19 @@ public ListMonitoredResourceDescriptorsRequest injectToken( .build(); } + @Override + public ListMonitoredResourceDescriptorsRequest injectPageSize( + ListMonitoredResourceDescriptorsRequest payload, int pageSize) { + return ListMonitoredResourceDescriptorsRequest.newBuilder(payload) + .setPageSize(pageSize) + .build(); + } + + @Override + public Integer extractPageSize(ListMonitoredResourceDescriptorsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListMonitoredResourceDescriptorsResponse payload) { return payload.getNextPageToken(); @@ -302,6 +315,17 @@ public ListMetricDescriptorsRequest injectToken( .build(); } + @Override + public ListMetricDescriptorsRequest injectPageSize( + ListMetricDescriptorsRequest payload, int pageSize) { + return ListMetricDescriptorsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListMetricDescriptorsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListMetricDescriptorsResponse payload) { return payload.getNextPageToken(); @@ -327,6 +351,17 @@ public ListTimeSeriesRequest injectToken(ListTimeSeriesRequest payload, Object t return ListTimeSeriesRequest.newBuilder(payload).setPageToken((String) token).build(); } + @Override + public ListTimeSeriesRequest injectPageSize( + ListTimeSeriesRequest payload, int pageSize) { + return ListTimeSeriesRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListTimeSeriesRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListTimeSeriesResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java index 1185776418d4..d37c7e7690ff 100644 --- a/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java +++ b/google-cloud-monitoring/src/main/java/com/google/cloud/monitoring/spi/v3/package-info.java @@ -13,7 +13,7 @@ */ /** - * A client to Google Monitoring API. + * A client to Stackdriver Monitoring API. * * The interfaces provided are listed below, along with a usage sample * diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java index 62852c768a7a..21921b188880 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/AgentTranslationServiceTest.java @@ -15,14 +15,14 @@ package com.google.cloud.monitoring.spi.v3; import com.google.api.MonitoredResource; -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.monitoring.v3.CollectdPayload; import com.google.monitoring.v3.CreateCollectdTimeSeriesRequest; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -79,7 +79,7 @@ public void tearDown() throws Exception { @SuppressWarnings("all") public void createCollectdTimeSeriesTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockAgentTranslationService.setResponses(expectedResponses); @@ -90,7 +90,7 @@ public void createCollectdTimeSeriesTest() { api.createCollectdTimeSeries(formattedName, resource, collectdVersion, collectdPayloads); - List actualRequests = mockAgentTranslationService.getRequests(); + List actualRequests = mockAgentTranslationService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateCollectdTimeSeriesRequest actualRequest = (CreateCollectdTimeSeriesRequest) actualRequests.get(0); diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java index ab06da6415c2..c3944b8cb0af 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/GroupServiceTest.java @@ -15,7 +15,7 @@ package com.google.cloud.monitoring.spi.v3; import com.google.api.MonitoredResource; -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; @@ -28,7 +28,7 @@ import com.google.monitoring.v3.TimeInterval; import com.google.monitoring.v3.UpdateGroupRequest; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -97,7 +97,7 @@ public void getGroupTest() { .setFilter(filter) .setIsCluster(isCluster) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockGroupService.setResponses(expectedResponses); @@ -106,7 +106,7 @@ public void getGroupTest() { Group actualResponse = api.getGroup(formattedName); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockGroupService.getRequests(); + List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetGroupRequest actualRequest = (GetGroupRequest) actualRequests.get(0); @@ -129,7 +129,7 @@ public void createGroupTest() { .setFilter(filter) .setIsCluster(isCluster) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockGroupService.setResponses(expectedResponses); @@ -140,7 +140,7 @@ public void createGroupTest() { Group actualResponse = api.createGroup(formattedName, group, validateOnly); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockGroupService.getRequests(); + List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateGroupRequest actualRequest = (CreateGroupRequest) actualRequests.get(0); @@ -165,7 +165,7 @@ public void updateGroupTest() { .setFilter(filter) .setIsCluster(isCluster) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockGroupService.setResponses(expectedResponses); @@ -175,7 +175,7 @@ public void updateGroupTest() { Group actualResponse = api.updateGroup(group, validateOnly); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockGroupService.getRequests(); + List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); UpdateGroupRequest actualRequest = (UpdateGroupRequest) actualRequests.get(0); @@ -187,7 +187,7 @@ public void updateGroupTest() { @SuppressWarnings("all") public void deleteGroupTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockGroupService.setResponses(expectedResponses); @@ -195,7 +195,7 @@ public void deleteGroupTest() { api.deleteGroup(formattedName); - List actualRequests = mockGroupService.getRequests(); + List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteGroupRequest actualRequest = (DeleteGroupRequest) actualRequests.get(0); @@ -205,17 +205,17 @@ public void deleteGroupTest() { @Test @SuppressWarnings("all") public void listGroupMembersTest() { + String nextPageToken = ""; + int totalSize = -705419236; MonitoredResource membersElement = MonitoredResource.newBuilder().build(); List members = Arrays.asList(membersElement); - String nextPageToken = "nextPageToken-1530815211"; - int totalSize = -705419236; ListGroupMembersResponse expectedResponse = ListGroupMembersResponse.newBuilder() - .addAllMembers(members) .setNextPageToken(nextPageToken) .setTotalSize(totalSize) + .addAllMembers(members) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockGroupService.setResponses(expectedResponses); @@ -223,16 +223,14 @@ public void listGroupMembersTest() { String filter = "filter-1274492040"; TimeInterval interval = TimeInterval.newBuilder().build(); - PageAccessor pageAccessor = - api.listGroupMembers(formattedName, filter, interval); + PagedListResponse + pagedListResponse = api.listGroupMembers(formattedName, filter, interval); - // 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()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getMembersList().get(0), resources.get(0)); - List actualRequests = mockGroupService.getRequests(); + List actualRequests = mockGroupService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListGroupMembersRequest actualRequest = (ListGroupMembersRequest) actualRequests.get(0); diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java index 77ae6be6ffb6..fa8034b62219 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MetricServiceTest.java @@ -16,7 +16,7 @@ import com.google.api.MetricDescriptor; import com.google.api.MonitoredResourceDescriptor; -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; @@ -31,7 +31,7 @@ import com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse; import com.google.monitoring.v3.TimeSeries; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -87,33 +87,34 @@ public void tearDown() throws Exception { @Test @SuppressWarnings("all") public void listMonitoredResourceDescriptorsTest() { + String nextPageToken = ""; MonitoredResourceDescriptor resourceDescriptorsElement = MonitoredResourceDescriptor.newBuilder().build(); List resourceDescriptors = Arrays.asList(resourceDescriptorsElement); - String nextPageToken = "nextPageToken-1530815211"; ListMonitoredResourceDescriptorsResponse expectedResponse = ListMonitoredResourceDescriptorsResponse.newBuilder() - .addAllResourceDescriptors(resourceDescriptors) .setNextPageToken(nextPageToken) + .addAllResourceDescriptors(resourceDescriptors) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); String filter = "filter-1274492040"; - PageAccessor pageAccessor = - api.listMonitoredResourceDescriptors(formattedName, filter); + PagedListResponse< + ListMonitoredResourceDescriptorsRequest, ListMonitoredResourceDescriptorsResponse, + MonitoredResourceDescriptor> + pagedListResponse = api.listMonitoredResourceDescriptors(formattedName, filter); - // 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()); + List resources = + Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getResourceDescriptorsList().get(0), resources.get(0)); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListMonitoredResourceDescriptorsRequest actualRequest = (ListMonitoredResourceDescriptorsRequest) actualRequests.get(0); @@ -138,7 +139,7 @@ public void getMonitoredResourceDescriptorTest() { .setDisplayName(displayName) .setDescription(description) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); @@ -149,7 +150,7 @@ public void getMonitoredResourceDescriptorTest() { MonitoredResourceDescriptor actualResponse = api.getMonitoredResourceDescriptor(formattedName); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetMonitoredResourceDescriptorRequest actualRequest = (GetMonitoredResourceDescriptorRequest) actualRequests.get(0); @@ -160,30 +161,29 @@ public void getMonitoredResourceDescriptorTest() { @Test @SuppressWarnings("all") public void listMetricDescriptorsTest() { + String nextPageToken = ""; MetricDescriptor metricDescriptorsElement = MetricDescriptor.newBuilder().build(); List metricDescriptors = Arrays.asList(metricDescriptorsElement); - String nextPageToken = "nextPageToken-1530815211"; ListMetricDescriptorsResponse expectedResponse = ListMetricDescriptorsResponse.newBuilder() - .addAllMetricDescriptors(metricDescriptors) .setNextPageToken(nextPageToken) + .addAllMetricDescriptors(metricDescriptors) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); String formattedName = MetricServiceApi.formatProjectName("[PROJECT]"); String filter = "filter-1274492040"; - PageAccessor pageAccessor = api.listMetricDescriptors(formattedName, filter); + PagedListResponse + pagedListResponse = api.listMetricDescriptors(formattedName, filter); - // 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()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getMetricDescriptorsList().get(0), resources.get(0)); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListMetricDescriptorsRequest actualRequest = (ListMetricDescriptorsRequest) actualRequests.get(0); @@ -209,7 +209,7 @@ public void getMetricDescriptorTest() { .setDescription(description) .setDisplayName(displayName) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); @@ -219,7 +219,7 @@ public void getMetricDescriptorTest() { MetricDescriptor actualResponse = api.getMetricDescriptor(formattedName); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetMetricDescriptorRequest actualRequest = (GetMetricDescriptorRequest) actualRequests.get(0); @@ -242,7 +242,7 @@ public void createMetricDescriptorTest() { .setDescription(description) .setDisplayName(displayName) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); @@ -252,7 +252,7 @@ public void createMetricDescriptorTest() { MetricDescriptor actualResponse = api.createMetricDescriptor(formattedName, metricDescriptor); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateMetricDescriptorRequest actualRequest = (CreateMetricDescriptorRequest) actualRequests.get(0); @@ -265,7 +265,7 @@ public void createMetricDescriptorTest() { @SuppressWarnings("all") public void deleteMetricDescriptorTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); @@ -274,7 +274,7 @@ public void deleteMetricDescriptorTest() { api.deleteMetricDescriptor(formattedName); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteMetricDescriptorRequest actualRequest = (DeleteMetricDescriptorRequest) actualRequests.get(0); @@ -286,7 +286,7 @@ public void deleteMetricDescriptorTest() { @SuppressWarnings("all") public void createTimeSeriesTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockMetricService.setResponses(expectedResponses); @@ -295,7 +295,7 @@ public void createTimeSeriesTest() { api.createTimeSeries(formattedName, timeSeries); - List actualRequests = mockMetricService.getRequests(); + List actualRequests = mockMetricService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateTimeSeriesRequest actualRequest = (CreateTimeSeriesRequest) actualRequests.get(0); diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java index 40e641cbebe5..a580421d56a4 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.monitoring.v3.AgentTranslationServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockAgentTranslationService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return AgentTranslationServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java index 79eefb710584..9d1538556a69 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockAgentTranslationServiceImpl.java @@ -15,10 +15,10 @@ package com.google.cloud.monitoring.spi.v3; import com.google.common.collect.Lists; -import com.google.monitoring.v3.AgentTranslationServiceGrpc.AgentTranslationService; +import com.google.monitoring.v3.AgentTranslationServiceGrpc.AgentTranslationServiceImplBase; import com.google.monitoring.v3.CreateCollectdTimeSeriesRequest; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -26,20 +26,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockAgentTranslationServiceImpl implements AgentTranslationService { - private ArrayList requests; - private Queue responses; +public class MockAgentTranslationServiceImpl extends AgentTranslationServiceImplBase { + private ArrayList requests; + private Queue responses; public MockAgentTranslationServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupService.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupService.java index 58f02392f3a6..6322a7e084ef 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupService.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.monitoring.v3.GroupServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockGroupService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return GroupServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupServiceImpl.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupServiceImpl.java index e68220eb18f2..a033a8ad47ba 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupServiceImpl.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockGroupServiceImpl.java @@ -19,14 +19,14 @@ import com.google.monitoring.v3.DeleteGroupRequest; import com.google.monitoring.v3.GetGroupRequest; import com.google.monitoring.v3.Group; -import com.google.monitoring.v3.GroupServiceGrpc.GroupService; +import com.google.monitoring.v3.GroupServiceGrpc.GroupServiceImplBase; import com.google.monitoring.v3.ListGroupMembersRequest; import com.google.monitoring.v3.ListGroupMembersResponse; import com.google.monitoring.v3.ListGroupsRequest; import com.google.monitoring.v3.ListGroupsResponse; import com.google.monitoring.v3.UpdateGroupRequest; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -34,20 +34,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockGroupServiceImpl implements GroupService { - private ArrayList requests; - private Queue responses; +public class MockGroupServiceImpl extends GroupServiceImplBase { + private ArrayList requests; + private Queue responses; public MockGroupServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricService.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricService.java index 6168d6176eb1..384d0c7acb96 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricService.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.monitoring.v3.MetricServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockMetricService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return MetricServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricServiceImpl.java b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricServiceImpl.java index 74669c6f8eaf..01bccc7a3ef4 100644 --- a/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricServiceImpl.java +++ b/google-cloud-monitoring/src/test/java/com/google/cloud/monitoring/spi/v3/MockMetricServiceImpl.java @@ -28,9 +28,9 @@ import com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse; import com.google.monitoring.v3.ListTimeSeriesRequest; import com.google.monitoring.v3.ListTimeSeriesResponse; -import com.google.monitoring.v3.MetricServiceGrpc.MetricService; +import com.google.monitoring.v3.MetricServiceGrpc.MetricServiceImplBase; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -38,20 +38,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockMetricServiceImpl implements MetricService { - private ArrayList requests; - private Queue responses; +public class MockMetricServiceImpl extends MetricServiceImplBase { + private ArrayList requests; + private Queue responses; public MockMetricServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-pubsub/pom.xml b/google-cloud-pubsub/pom.xml index 861af28c66a0..a24a5a277998 100644 --- a/google-cloud-pubsub/pom.xml +++ b/google-cloud-pubsub/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-pubsub-v1 - 0.0.9 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java index 4b992d2db4b5..1d131fd560d5 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.pubsub.spi.v1; -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.iam.v1.GetIamPolicyRequest; @@ -21,7 +21,6 @@ import com.google.iam.v1.SetIamPolicyRequest; import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; -import com.google.protobuf.ByteString; import com.google.protobuf.Empty; import com.google.pubsub.v1.DeleteTopicRequest; import com.google.pubsub.v1.GetTopicRequest; @@ -104,10 +103,14 @@ public class PublisherApi implements AutoCloseable { private final ApiCallable publishCallable; private final ApiCallable getTopicCallable; private final ApiCallable listTopicsCallable; - private final ApiCallable> listTopicsPagedCallable; + private final ApiCallable< + ListTopicsRequest, PagedListResponse> + listTopicsPagedCallable; private final ApiCallable listTopicSubscriptionsCallable; - private final ApiCallable> + private final ApiCallable< + ListTopicSubscriptionsRequest, + PagedListResponse> listTopicSubscriptionsPagedCallable; private final ApiCallable deleteTopicCallable; private final ApiCallable setIamPolicyCallable; @@ -470,7 +473,7 @@ public final ApiCallable getTopicCallable() { *

    * try (PublisherApi publisherApi = PublisherApi.create()) {
    *   String formattedProject = PublisherApi.formatProjectName("[PROJECT]");
-   *   for (Topic element : publisherApi.listTopics(formattedProject)) {
+   *   for (Topic element : publisherApi.listTopics(formattedProject).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -479,7 +482,8 @@ public final ApiCallable getTopicCallable() {
    * @param project The name of the cloud project that topics belong to.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final PageAccessor listTopics(String project) {
+  public final PagedListResponse listTopics(
+      String project) {
     PROJECT_PATH_TEMPLATE.validate(project, "listTopics");
     ListTopicsRequest request = ListTopicsRequest.newBuilder().setProject(project).build();
     return listTopics(request);
@@ -496,7 +500,7 @@ public final PageAccessor listTopics(String project) {
    *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
    *     .setProject(formattedProject)
    *     .build();
-   *   for (Topic element : publisherApi.listTopics(request)) {
+   *   for (Topic element : publisherApi.listTopics(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -505,7 +509,8 @@ public final PageAccessor listTopics(String project) {
    * @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 listTopics(ListTopicsRequest request) {
+  public final PagedListResponse listTopics(
+      ListTopicsRequest request) {
     return listTopicsPagedCallable().call(request);
   }
 
@@ -520,15 +525,17 @@ public final PageAccessor listTopics(ListTopicsRequest request) {
    *   ListTopicsRequest request = ListTopicsRequest.newBuilder()
    *     .setProject(formattedProject)
    *     .build();
-   *   ListenableFuture<PageAccessor<Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request);
+   *   ListenableFuture<PagedListResponse<ListTopicsRequest,ListTopicsResponse,Topic>> future = publisherApi.listTopicsPagedCallable().futureCall(request);
    *   // Do something
-   *   for (Topic element : future.get()) {
+   *   for (Topic element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ - public final ApiCallable> listTopicsPagedCallable() { + public final ApiCallable< + ListTopicsRequest, PagedListResponse> + listTopicsPagedCallable() { return listTopicsPagedCallable; } @@ -570,7 +577,7 @@ public final ApiCallable listTopicsCallab *

    * try (PublisherApi publisherApi = PublisherApi.create()) {
    *   String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
-   *   for (String element : publisherApi.listTopicSubscriptions(formattedTopic)) {
+   *   for (String element : publisherApi.listTopicSubscriptions(formattedTopic).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -579,7 +586,9 @@ public final ApiCallable listTopicsCallab
    * @param topic The name of the topic that subscriptions are attached to.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final PageAccessor listTopicSubscriptions(String topic) {
+  public final PagedListResponse<
+          ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
+      listTopicSubscriptions(String topic) {
     TOPIC_PATH_TEMPLATE.validate(topic, "listTopicSubscriptions");
     ListTopicSubscriptionsRequest request =
         ListTopicSubscriptionsRequest.newBuilder().setTopic(topic).build();
@@ -597,7 +606,7 @@ public final PageAccessor listTopicSubscriptions(String topic) {
    *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
    *     .setTopic(formattedTopic)
    *     .build();
-   *   for (String element : publisherApi.listTopicSubscriptions(request)) {
+   *   for (String element : publisherApi.listTopicSubscriptions(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -606,7 +615,9 @@ public final PageAccessor listTopicSubscriptions(String topic) {
    * @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 listTopicSubscriptions(ListTopicSubscriptionsRequest request) {
+  public final PagedListResponse<
+          ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse, String>
+      listTopicSubscriptions(ListTopicSubscriptionsRequest request) {
     return listTopicSubscriptionsPagedCallable().call(request);
   }
 
@@ -621,15 +632,17 @@ public final PageAccessor listTopicSubscriptions(ListTopicSubscriptionsR
    *   ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
    *     .setTopic(formattedTopic)
    *     .build();
-   *   ListenableFuture<PageAccessor<String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request);
+   *   ListenableFuture<PagedListResponse<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse,String>> future = publisherApi.listTopicSubscriptionsPagedCallable().futureCall(request);
    *   // Do something
-   *   for (String element : future.get()) {
+   *   for (String element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ - public final ApiCallable> + public final ApiCallable< + ListTopicSubscriptionsRequest, + PagedListResponse> listTopicSubscriptionsPagedCallable() { return listTopicSubscriptionsPagedCallable; } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java index 11db4dde916f..c626216fe117 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PublisherSettings.java @@ -271,6 +271,16 @@ public ListTopicsRequest injectToken(ListTopicsRequest payload, Object token) { return ListTopicsRequest.newBuilder(payload).setPageToken((String) token).build(); } + @Override + public ListTopicsRequest injectPageSize(ListTopicsRequest payload, int pageSize) { + return ListTopicsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListTopicsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListTopicsResponse payload) { return payload.getNextPageToken(); @@ -300,6 +310,19 @@ public ListTopicSubscriptionsRequest injectToken( .build(); } + @Override + public ListTopicSubscriptionsRequest injectPageSize( + ListTopicSubscriptionsRequest payload, int pageSize) { + return ListTopicSubscriptionsRequest.newBuilder(payload) + .setPageSize(pageSize) + .build(); + } + + @Override + public Integer extractPageSize(ListTopicSubscriptionsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListTopicSubscriptionsResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java index 8e2c7258b954..147cc4be18a6 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.pubsub.spi.v1; -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.iam.v1.GetIamPolicyRequest; @@ -107,7 +107,9 @@ public class SubscriberApi implements AutoCloseable { private final ApiCallable getSubscriptionCallable; private final ApiCallable listSubscriptionsCallable; - private final ApiCallable> + private final ApiCallable< + ListSubscriptionsRequest, + PagedListResponse> listSubscriptionsPagedCallable; private final ApiCallable deleteSubscriptionCallable; private final ApiCallable modifyAckDeadlineCallable; @@ -467,7 +469,7 @@ public final ApiCallable getSubscriptionCa *

    * try (SubscriberApi subscriberApi = SubscriberApi.create()) {
    *   String formattedProject = SubscriberApi.formatProjectName("[PROJECT]");
-   *   for (Subscription element : subscriberApi.listSubscriptions(formattedProject)) {
+   *   for (Subscription element : subscriberApi.listSubscriptions(formattedProject).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -476,7 +478,8 @@ public final ApiCallable getSubscriptionCa
    * @param project The name of the cloud project that subscriptions belong to.
    * @throws com.google.api.gax.grpc.ApiException if the remote call fails
    */
-  public final PageAccessor listSubscriptions(String project) {
+  public final PagedListResponse
+      listSubscriptions(String project) {
     PROJECT_PATH_TEMPLATE.validate(project, "listSubscriptions");
     ListSubscriptionsRequest request =
         ListSubscriptionsRequest.newBuilder().setProject(project).build();
@@ -494,7 +497,7 @@ public final PageAccessor listSubscriptions(String project) {
    *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
    *     .setProject(formattedProject)
    *     .build();
-   *   for (Subscription element : subscriberApi.listSubscriptions(request)) {
+   *   for (Subscription element : subscriberApi.listSubscriptions(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -503,7 +506,8 @@ public final PageAccessor listSubscriptions(String project) {
    * @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 listSubscriptions(ListSubscriptionsRequest request) {
+  public final PagedListResponse
+      listSubscriptions(ListSubscriptionsRequest request) {
     return listSubscriptionsPagedCallable().call(request);
   }
 
@@ -518,15 +522,17 @@ public final PageAccessor listSubscriptions(ListSubscriptionsReque
    *   ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
    *     .setProject(formattedProject)
    *     .build();
-   *   ListenableFuture<PageAccessor<Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request);
+   *   ListenableFuture<PagedListResponse<ListSubscriptionsRequest,ListSubscriptionsResponse,Subscription>> future = subscriberApi.listSubscriptionsPagedCallable().futureCall(request);
    *   // Do something
-   *   for (Subscription element : future.get()) {
+   *   for (Subscription element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ - public final ApiCallable> + public final ApiCallable< + ListSubscriptionsRequest, + PagedListResponse> listSubscriptionsPagedCallable() { return listSubscriptionsPagedCallable; } diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java index 803e4e9da3e2..1eb8e6af5849 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/SubscriberSettings.java @@ -286,6 +286,17 @@ public ListSubscriptionsRequest injectToken( .build(); } + @Override + public ListSubscriptionsRequest injectPageSize( + ListSubscriptionsRequest payload, int pageSize) { + return ListSubscriptionsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListSubscriptionsRequest payload) { + return payload.getPageSize(); + } + @Override public Object extractNextToken(ListSubscriptionsResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicy.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicy.java index be1117e47043..241181d4a8a7 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicy.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicy.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.iam.v1.IAMPolicyGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockIAMPolicy() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return IAMPolicyGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicyImpl.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicyImpl.java index 224bdfcc5f7a..afef90b61d2a 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicyImpl.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockIAMPolicyImpl.java @@ -16,12 +16,12 @@ import com.google.common.collect.Lists; import com.google.iam.v1.GetIamPolicyRequest; -import com.google.iam.v1.IAMPolicyGrpc.IAMPolicy; +import com.google.iam.v1.IAMPolicyGrpc.IAMPolicyImplBase; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -29,20 +29,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockIAMPolicyImpl implements IAMPolicy { - private ArrayList requests; - private Queue responses; +public class MockIAMPolicyImpl extends IAMPolicyImplBase { + private ArrayList requests; + private Queue responses; public MockIAMPolicyImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisher.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisher.java index b33087c4e803..9c5b0a594a44 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisher.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisher.java @@ -15,7 +15,7 @@ package com.google.cloud.pubsub.spi.v1; import com.google.api.gax.testing.MockGrpcService; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import com.google.pubsub.v1.PublisherGrpc; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockPublisher() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return PublisherGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisherImpl.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisherImpl.java index da815f23426f..87ab32168959 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisherImpl.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockPublisherImpl.java @@ -16,7 +16,7 @@ import com.google.common.collect.Lists; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import com.google.pubsub.v1.DeleteTopicRequest; import com.google.pubsub.v1.GetTopicRequest; import com.google.pubsub.v1.ListTopicSubscriptionsRequest; @@ -25,7 +25,7 @@ import com.google.pubsub.v1.ListTopicsResponse; import com.google.pubsub.v1.PublishRequest; import com.google.pubsub.v1.PublishResponse; -import com.google.pubsub.v1.PublisherGrpc.Publisher; +import com.google.pubsub.v1.PublisherGrpc.PublisherImplBase; import com.google.pubsub.v1.Topic; import io.grpc.stub.StreamObserver; import java.util.ArrayList; @@ -34,20 +34,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockPublisherImpl implements Publisher { - private ArrayList requests; - private Queue responses; +public class MockPublisherImpl extends PublisherImplBase { + private ArrayList requests; + private Queue responses; public MockPublisherImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriber.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriber.java index 906834f3ac95..1355a9fd1ef1 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriber.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriber.java @@ -15,7 +15,7 @@ package com.google.cloud.pubsub.spi.v1; import com.google.api.gax.testing.MockGrpcService; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import com.google.pubsub.v1.SubscriberGrpc; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockSubscriber() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return SubscriberGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java index 7674ece2c2f4..10368ecae789 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/MockSubscriberImpl.java @@ -16,7 +16,7 @@ import com.google.common.collect.Lists; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import com.google.pubsub.v1.AcknowledgeRequest; import com.google.pubsub.v1.DeleteSubscriptionRequest; import com.google.pubsub.v1.GetSubscriptionRequest; @@ -26,7 +26,7 @@ import com.google.pubsub.v1.ModifyPushConfigRequest; import com.google.pubsub.v1.PullRequest; import com.google.pubsub.v1.PullResponse; -import com.google.pubsub.v1.SubscriberGrpc.Subscriber; +import com.google.pubsub.v1.SubscriberGrpc.SubscriberImplBase; import com.google.pubsub.v1.Subscription; import io.grpc.stub.StreamObserver; import java.util.ArrayList; @@ -35,20 +35,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockSubscriberImpl implements Subscriber { - private ArrayList requests; - private Queue responses; +public class MockSubscriberImpl extends SubscriberImplBase { + private ArrayList requests; + private Queue responses; public MockSubscriberImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherApiTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherApiTest.java index 044c5c5cc370..e2a9fd3339df 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherApiTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherApiTest.java @@ -165,7 +165,7 @@ public void testListTopics() throws Exception { publisherApi.createTopic(topicName2); publisherApi.createTopic(topicName3); List topics = new ArrayList<>(); - for (Topic topic : publisherApi.listTopics(project1)) { + for (Topic topic : publisherApi.listTopics(project1).iterateAllElements()) { topics.add(topic); } Assert.assertEquals(2, topics.size()); @@ -180,7 +180,7 @@ public void testDeleteTopic() throws Exception { publisherApi.createTopic(topicName); publisherApi.deleteTopic(topicName); List topics = new ArrayList<>(); - for (Topic topic : publisherApi.listTopics(project)) { + for (Topic topic : publisherApi.listTopics(project).iterateAllElements()) { topics.add(topic); } Assert.assertEquals(0, topics.size()); diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java index 18104e858939..7d76c1a27111 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/PublisherTest.java @@ -14,7 +14,7 @@ package com.google.cloud.pubsub.spi.v1; -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; @@ -25,7 +25,7 @@ import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import com.google.pubsub.v1.DeleteTopicRequest; import com.google.pubsub.v1.GetTopicRequest; import com.google.pubsub.v1.ListTopicSubscriptionsRequest; @@ -92,7 +92,7 @@ public void tearDown() throws Exception { public void createTopicTest() { String formattedName2 = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]"); Topic expectedResponse = Topic.newBuilder().setName(formattedName2).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockPublisher.setResponses(expectedResponses); @@ -101,7 +101,7 @@ public void createTopicTest() { Topic actualResponse = api.createTopic(formattedName); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockPublisher.getRequests(); + List actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); Topic actualRequest = (Topic) actualRequests.get(0); @@ -115,7 +115,7 @@ public void publishTest() { List messageIds = Arrays.asList(messageIdsElement); PublishResponse expectedResponse = PublishResponse.newBuilder().addAllMessageIds(messageIds).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockPublisher.setResponses(expectedResponses); @@ -127,7 +127,7 @@ public void publishTest() { PublishResponse actualResponse = api.publish(formattedTopic, messages); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockPublisher.getRequests(); + List actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); PublishRequest actualRequest = (PublishRequest) actualRequests.get(0); @@ -140,7 +140,7 @@ public void publishTest() { public void getTopicTest() { String name = "name3373707"; Topic expectedResponse = Topic.newBuilder().setName(name).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockPublisher.setResponses(expectedResponses); @@ -149,7 +149,7 @@ public void getTopicTest() { Topic actualResponse = api.getTopic(formattedTopic); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockPublisher.getRequests(); + List actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTopicRequest actualRequest = (GetTopicRequest) actualRequests.get(0); @@ -159,29 +159,28 @@ public void getTopicTest() { @Test @SuppressWarnings("all") public void listTopicsTest() { + String nextPageToken = ""; Topic topicsElement = Topic.newBuilder().build(); List topics = Arrays.asList(topicsElement); - String nextPageToken = "nextPageToken-1530815211"; ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder() - .addAllTopics(topics) .setNextPageToken(nextPageToken) + .addAllTopics(topics) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockPublisher.setResponses(expectedResponses); String formattedProject = PublisherApi.formatProjectName("[PROJECT]"); - PageAccessor pageAccessor = api.listTopics(formattedProject); + PagedListResponse pagedListResponse = + api.listTopics(formattedProject); - // 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()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getTopicsList().get(0), resources.get(0)); - List actualRequests = mockPublisher.getRequests(); + List actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListTopicsRequest actualRequest = (ListTopicsRequest) actualRequests.get(0); @@ -191,29 +190,28 @@ public void listTopicsTest() { @Test @SuppressWarnings("all") public void listTopicSubscriptionsTest() { + String nextPageToken = ""; String subscriptionsElement = "subscriptionsElement1698708147"; List subscriptions = Arrays.asList(subscriptionsElement); - String nextPageToken = "nextPageToken-1530815211"; ListTopicSubscriptionsResponse expectedResponse = ListTopicSubscriptionsResponse.newBuilder() - .addAllSubscriptions(subscriptions) .setNextPageToken(nextPageToken) + .addAllSubscriptions(subscriptions) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockPublisher.setResponses(expectedResponses); String formattedTopic = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]"); - PageAccessor pageAccessor = api.listTopicSubscriptions(formattedTopic); + PagedListResponse + pagedListResponse = api.listTopicSubscriptions(formattedTopic); - // 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()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0)); - List actualRequests = mockPublisher.getRequests(); + List actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListTopicSubscriptionsRequest actualRequest = (ListTopicSubscriptionsRequest) actualRequests.get(0); @@ -225,7 +223,7 @@ public void listTopicSubscriptionsTest() { @SuppressWarnings("all") public void deleteTopicTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockPublisher.setResponses(expectedResponses); @@ -233,7 +231,7 @@ public void deleteTopicTest() { api.deleteTopic(formattedTopic); - List actualRequests = mockPublisher.getRequests(); + List actualRequests = mockPublisher.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteTopicRequest actualRequest = (DeleteTopicRequest) actualRequests.get(0); @@ -246,7 +244,7 @@ public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockIAMPolicy.setResponses(expectedResponses); @@ -256,7 +254,7 @@ public void setIamPolicyTest() { Policy actualResponse = api.setIamPolicy(formattedResource, policy); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockIAMPolicy.getRequests(); + List actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); @@ -270,7 +268,7 @@ public void getIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockIAMPolicy.setResponses(expectedResponses); @@ -279,7 +277,7 @@ public void getIamPolicyTest() { Policy actualResponse = api.getIamPolicy(formattedResource); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockIAMPolicy.getRequests(); + List actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetIamPolicyRequest actualRequest = (GetIamPolicyRequest) actualRequests.get(0); @@ -289,10 +287,8 @@ public void getIamPolicyTest() { @Test @SuppressWarnings("all") public void testIamPermissionsTest() { - List permissions2 = new ArrayList<>(); - TestIamPermissionsResponse expectedResponse = - TestIamPermissionsResponse.newBuilder().addAllPermissions(permissions2).build(); - List expectedResponses = new ArrayList<>(); + TestIamPermissionsResponse expectedResponse = TestIamPermissionsResponse.newBuilder().build(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockIAMPolicy.setResponses(expectedResponses); @@ -303,7 +299,7 @@ public void testIamPermissionsTest() { api.testIamPermissions(formattedResource, permissions); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockIAMPolicy.getRequests(); + List actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); TestIamPermissionsRequest actualRequest = (TestIamPermissionsRequest) actualRequests.get(0); diff --git a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java index 210580ee0d2e..28e25b421ac7 100644 --- a/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java +++ b/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberTest.java @@ -14,7 +14,7 @@ package com.google.cloud.pubsub.spi.v1; -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; @@ -25,7 +25,7 @@ import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import com.google.pubsub.v1.AcknowledgeRequest; import com.google.pubsub.v1.DeleteSubscriptionRequest; import com.google.pubsub.v1.GetSubscriptionRequest; @@ -100,7 +100,7 @@ public void createSubscriptionTest() { .setTopic(formattedTopic2) .setAckDeadlineSeconds(ackDeadlineSeconds2) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -113,7 +113,7 @@ public void createSubscriptionTest() { api.createSubscription(formattedName, formattedTopic, pushConfig, ackDeadlineSeconds); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); Subscription actualRequest = (Subscription) actualRequests.get(0); @@ -135,7 +135,7 @@ public void getSubscriptionTest() { .setTopic(topic) .setAckDeadlineSeconds(ackDeadlineSeconds) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -145,7 +145,7 @@ public void getSubscriptionTest() { Subscription actualResponse = api.getSubscription(formattedSubscription); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetSubscriptionRequest actualRequest = (GetSubscriptionRequest) actualRequests.get(0); @@ -155,29 +155,28 @@ public void getSubscriptionTest() { @Test @SuppressWarnings("all") public void listSubscriptionsTest() { + String nextPageToken = ""; Subscription subscriptionsElement = Subscription.newBuilder().build(); List subscriptions = Arrays.asList(subscriptionsElement); - String nextPageToken = "nextPageToken-1530815211"; ListSubscriptionsResponse expectedResponse = ListSubscriptionsResponse.newBuilder() - .addAllSubscriptions(subscriptions) .setNextPageToken(nextPageToken) + .addAllSubscriptions(subscriptions) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); String formattedProject = SubscriberApi.formatProjectName("[PROJECT]"); - PageAccessor pageAccessor = api.listSubscriptions(formattedProject); + PagedListResponse + pagedListResponse = api.listSubscriptions(formattedProject); - // 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()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0)); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListSubscriptionsRequest actualRequest = (ListSubscriptionsRequest) actualRequests.get(0); @@ -188,7 +187,7 @@ public void listSubscriptionsTest() { @SuppressWarnings("all") public void deleteSubscriptionTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -197,7 +196,7 @@ public void deleteSubscriptionTest() { api.deleteSubscription(formattedSubscription); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteSubscriptionRequest actualRequest = (DeleteSubscriptionRequest) actualRequests.get(0); @@ -208,7 +207,7 @@ public void deleteSubscriptionTest() { @SuppressWarnings("all") public void modifyAckDeadlineTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -219,7 +218,7 @@ public void modifyAckDeadlineTest() { api.modifyAckDeadline(formattedSubscription, ackIds, ackDeadlineSeconds); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); ModifyAckDeadlineRequest actualRequest = (ModifyAckDeadlineRequest) actualRequests.get(0); @@ -232,7 +231,7 @@ public void modifyAckDeadlineTest() { @SuppressWarnings("all") public void acknowledgeTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -242,7 +241,7 @@ public void acknowledgeTest() { api.acknowledge(formattedSubscription, ackIds); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); AcknowledgeRequest actualRequest = (AcknowledgeRequest) actualRequests.get(0); @@ -254,7 +253,7 @@ public void acknowledgeTest() { @SuppressWarnings("all") public void pullTest() { PullResponse expectedResponse = PullResponse.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -266,7 +265,7 @@ public void pullTest() { PullResponse actualResponse = api.pull(formattedSubscription, returnImmediately, maxMessages); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); PullRequest actualRequest = (PullRequest) actualRequests.get(0); @@ -279,7 +278,7 @@ public void pullTest() { @SuppressWarnings("all") public void modifyPushConfigTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSubscriber.setResponses(expectedResponses); @@ -289,7 +288,7 @@ public void modifyPushConfigTest() { api.modifyPushConfig(formattedSubscription, pushConfig); - List actualRequests = mockSubscriber.getRequests(); + List actualRequests = mockSubscriber.getRequests(); Assert.assertEquals(1, actualRequests.size()); ModifyPushConfigRequest actualRequest = (ModifyPushConfigRequest) actualRequests.get(0); @@ -303,7 +302,7 @@ public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockIAMPolicy.setResponses(expectedResponses); @@ -313,7 +312,7 @@ public void setIamPolicyTest() { Policy actualResponse = api.setIamPolicy(formattedResource, policy); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockIAMPolicy.getRequests(); + List actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); @@ -327,7 +326,7 @@ public void getIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockIAMPolicy.setResponses(expectedResponses); @@ -336,7 +335,7 @@ public void getIamPolicyTest() { Policy actualResponse = api.getIamPolicy(formattedResource); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockIAMPolicy.getRequests(); + List actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetIamPolicyRequest actualRequest = (GetIamPolicyRequest) actualRequests.get(0); @@ -346,10 +345,8 @@ public void getIamPolicyTest() { @Test @SuppressWarnings("all") public void testIamPermissionsTest() { - List permissions2 = new ArrayList<>(); - TestIamPermissionsResponse expectedResponse = - TestIamPermissionsResponse.newBuilder().addAllPermissions(permissions2).build(); - List expectedResponses = new ArrayList<>(); + TestIamPermissionsResponse expectedResponse = TestIamPermissionsResponse.newBuilder().build(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockIAMPolicy.setResponses(expectedResponses); @@ -360,7 +357,7 @@ public void testIamPermissionsTest() { api.testIamPermissions(formattedResource, permissions); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockIAMPolicy.getRequests(); + List actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); TestIamPermissionsRequest actualRequest = (TestIamPermissionsRequest) actualRequests.get(0); diff --git a/google-cloud-speech/pom.xml b/google-cloud-speech/pom.xml index 6f4a1048fa9c..2afb87c66296 100644 --- a/google-cloud-speech/pom.xml +++ b/google-cloud-speech/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-cloud-speech-v1beta1 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeech.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeech.java index 35e556f53659..ec3185919394 100644 --- a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeech.java +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeech.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.cloud.speech.v1beta1.SpeechGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockSpeech() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return SpeechGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java index f625817f868d..a33911f8274b 100644 --- a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/MockSpeechImpl.java @@ -15,14 +15,14 @@ package com.google.cloud.speech.spi.v1beta1; import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest; -import com.google.cloud.speech.v1beta1.SpeechGrpc.Speech; +import com.google.cloud.speech.v1beta1.SpeechGrpc.SpeechImplBase; import com.google.cloud.speech.v1beta1.StreamingRecognizeRequest; import com.google.cloud.speech.v1beta1.StreamingRecognizeResponse; import com.google.cloud.speech.v1beta1.SyncRecognizeRequest; import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.common.collect.Lists; import com.google.longrunning.Operation; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -30,20 +30,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockSpeechImpl implements Speech { - private ArrayList requests; - private Queue responses; +public class MockSpeechImpl extends SpeechImplBase { + private ArrayList requests; + private Queue responses; public MockSpeechImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java index 15a8b5229ec2..a41f6bf15dc7 100644 --- a/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java +++ b/google-cloud-speech/src/test/java/com/google/cloud/speech/spi/v1beta1/SpeechTest.java @@ -14,7 +14,7 @@ package com.google.cloud.speech.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.cloud.speech.v1beta1.AsyncRecognizeRequest; @@ -24,7 +24,7 @@ import com.google.cloud.speech.v1beta1.SyncRecognizeResponse; import com.google.common.collect.Lists; import com.google.longrunning.Operation; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -74,7 +74,7 @@ public void tearDown() throws Exception { @SuppressWarnings("all") public void syncRecognizeTest() { SyncRecognizeResponse expectedResponse = SyncRecognizeResponse.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSpeech.setResponses(expectedResponses); @@ -84,7 +84,7 @@ public void syncRecognizeTest() { SyncRecognizeResponse actualResponse = api.syncRecognize(config, audio); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockSpeech.getRequests(); + List actualRequests = mockSpeech.getRequests(); Assert.assertEquals(1, actualRequests.size()); SyncRecognizeRequest actualRequest = (SyncRecognizeRequest) actualRequests.get(0); @@ -98,7 +98,7 @@ public void asyncRecognizeTest() { String name = "name3373707"; boolean done = true; Operation expectedResponse = Operation.newBuilder().setName(name).setDone(done).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockSpeech.setResponses(expectedResponses); @@ -108,7 +108,7 @@ public void asyncRecognizeTest() { Operation actualResponse = api.asyncRecognize(config, audio); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockSpeech.getRequests(); + List actualRequests = mockSpeech.getRequests(); Assert.assertEquals(1, actualRequests.size()); AsyncRecognizeRequest actualRequest = (AsyncRecognizeRequest) actualRequests.get(0); diff --git a/google-cloud-trace/pom.xml b/google-cloud-trace/pom.xml index 2a25afc42ca4..c9ca285198e5 100644 --- a/google-cloud-trace/pom.xml +++ b/google-cloud-trace/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-devtools-cloudtrace-v1 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java index 0e94787987e7..f7e3afe0b9c9 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceApi.java @@ -13,7 +13,7 @@ */ package com.google.cloud.trace.spi.v1; -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.cloudtrace.v1.GetTraceRequest; @@ -97,7 +97,9 @@ public class TraceServiceApi implements AutoCloseable { private final ApiCallable patchTracesCallable; private final ApiCallable getTraceCallable; private final ApiCallable listTracesCallable; - private final ApiCallable> listTracesPagedCallable; + private final ApiCallable< + ListTracesRequest, PagedListResponse> + listTracesPagedCallable; public final TraceServiceSettings getSettings() { return settings; @@ -318,7 +320,7 @@ public final ApiCallable getTraceCallable() { *

    * try (TraceServiceApi traceServiceApi = TraceServiceApi.create()) {
    *   String projectId = "";
-   *   for (Trace element : traceServiceApi.listTraces(projectId)) {
+   *   for (Trace element : traceServiceApi.listTraces(projectId).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -327,7 +329,8 @@ public final ApiCallable getTraceCallable() {
    * @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) {
+  public final PagedListResponse listTraces(
+      String projectId) {
     ListTracesRequest request = ListTracesRequest.newBuilder().setProjectId(projectId).build();
     return listTraces(request);
   }
@@ -343,7 +346,7 @@ public final PageAccessor listTraces(String projectId) {
    *   ListTracesRequest request = ListTracesRequest.newBuilder()
    *     .setProjectId(projectId)
    *     .build();
-   *   for (Trace element : traceServiceApi.listTraces(request)) {
+   *   for (Trace element : traceServiceApi.listTraces(request).iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
@@ -352,7 +355,8 @@ public final PageAccessor listTraces(String projectId) {
    * @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) {
+  public final PagedListResponse listTraces(
+      ListTracesRequest request) {
     return listTracesPagedCallable().call(request);
   }
 
@@ -367,15 +371,17 @@ public final PageAccessor listTraces(ListTracesRequest request) {
    *   ListTracesRequest request = ListTracesRequest.newBuilder()
    *     .setProjectId(projectId)
    *     .build();
-   *   ListenableFuture<PageAccessor<Trace>> future = traceServiceApi.listTracesPagedCallable().futureCall(request);
+   *   ListenableFuture<PagedListResponse<ListTracesRequest,ListTracesResponse,Trace>> future = traceServiceApi.listTracesPagedCallable().futureCall(request);
    *   // Do something
-   *   for (Trace element : future.get()) {
+   *   for (Trace element : future.get().iterateAllElements()) {
    *     // doThingsWith(element);
    *   }
    * }
    * 
*/ - public final ApiCallable> listTracesPagedCallable() { + public final ApiCallable< + ListTracesRequest, PagedListResponse> + listTracesPagedCallable() { return listTracesPagedCallable; } diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java index 145adeffed56..413759d4e53b 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/TraceServiceSettings.java @@ -195,6 +195,18 @@ public ListTracesRequest injectToken(ListTracesRequest payload, Object token) { return ListTracesRequest.newBuilder(payload).setPageToken((String) token).build(); } + @Override + public ListTracesRequest injectPageSize(ListTracesRequest payload, int pageSize) { + throw new UnsupportedOperationException( + "page size is not supported by this API method"); + } + + @Override + public Integer extractPageSize(ListTracesRequest payload) { + throw new UnsupportedOperationException( + "page size is not supported by this API method"); + } + @Override public Object extractNextToken(ListTracesResponse payload) { return payload.getNextPageToken(); diff --git a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java index 32b3625ef678..0d89aecc3319 100644 --- a/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java +++ b/google-cloud-trace/src/main/java/com/google/cloud/trace/spi/v1/package-info.java @@ -13,7 +13,7 @@ */ /** - * A client to Google Cloud Trace API. + * A client to Stackdriver Trace API. * * The interfaces provided are listed below, along with a usage sample * diff --git a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java index dab3938d506f..95c45f72975d 100644 --- a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java +++ b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceService.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.devtools.cloudtrace.v1.TraceServiceGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockTraceService() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return TraceServiceGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java index e1d2ea4929f0..a118f1b38eb6 100644 --- a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java +++ b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/MockTraceServiceImpl.java @@ -20,9 +20,9 @@ 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.devtools.cloudtrace.v1.TraceServiceGrpc.TraceServiceImplBase; import com.google.protobuf.Empty; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -30,20 +30,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockTraceServiceImpl implements TraceService { - private ArrayList requests; - private Queue responses; +public class MockTraceServiceImpl extends TraceServiceImplBase { + private ArrayList requests; + private Queue responses; public MockTraceServiceImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); } diff --git a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java index 9af39602f843..c11b05b0c269 100644 --- a/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java +++ b/google-cloud-trace/src/test/java/com/google/cloud/trace/spi/v1/TraceServiceTest.java @@ -14,7 +14,7 @@ package com.google.cloud.trace.spi.v1; -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; @@ -25,7 +25,7 @@ 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 com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -75,7 +75,7 @@ public void tearDown() throws Exception { @SuppressWarnings("all") public void patchTracesTest() { Empty expectedResponse = Empty.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockTraceService.setResponses(expectedResponses); @@ -84,7 +84,7 @@ public void patchTracesTest() { api.patchTraces(projectId, traces); - List actualRequests = mockTraceService.getRequests(); + List actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); PatchTracesRequest actualRequest = (PatchTracesRequest) actualRequests.get(0); @@ -99,7 +99,7 @@ public void getTraceTest() { String traceId2 = "traceId2987826376"; Trace expectedResponse = Trace.newBuilder().setProjectId(projectId2).setTraceId(traceId2).build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockTraceService.setResponses(expectedResponses); @@ -109,7 +109,7 @@ public void getTraceTest() { Trace actualResponse = api.getTrace(projectId, traceId); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockTraceService.getRequests(); + List actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTraceRequest actualRequest = (GetTraceRequest) actualRequests.get(0); @@ -120,29 +120,28 @@ public void getTraceTest() { @Test @SuppressWarnings("all") public void listTracesTest() { + String nextPageToken = ""; Trace tracesElement = Trace.newBuilder().build(); List traces = Arrays.asList(tracesElement); - String nextPageToken = "nextPageToken-1530815211"; ListTracesResponse expectedResponse = ListTracesResponse.newBuilder() - .addAllTraces(traces) .setNextPageToken(nextPageToken) + .addAllTraces(traces) .build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockTraceService.setResponses(expectedResponses); String projectId = "projectId-1969970175"; - PageAccessor pageAccessor = api.listTraces(projectId); + PagedListResponse pagedListResponse = + 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()); + List resources = Lists.newArrayList(pagedListResponse.iterateAllElements()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getTracesList().get(0), resources.get(0)); - List actualRequests = mockTraceService.getRequests(); + List actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0); diff --git a/google-cloud-vision/pom.xml b/google-cloud-vision/pom.xml index 105b4243881a..9755ffbbb3de 100644 --- a/google-cloud-vision/pom.xml +++ b/google-cloud-vision/pom.xml @@ -20,7 +20,7 @@ io.netty netty-tcnative-boringssl-static - 1.1.33.Fork17 + 1.1.33.Fork19 ${project.groupId} @@ -30,17 +30,12 @@ com.google.api.grpc grpc-google-cloud-vision-v1 - 0.0.7 + 0.1.0 io.grpc grpc-all - 0.15.0 - - - com.google.auto.value - auto-value - 1.1 + 1.0.1 ${project.groupId} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/ImageAnnotatorTest.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/ImageAnnotatorTest.java index f25bc08b6036..c9afa9f00c43 100644 --- a/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/ImageAnnotatorTest.java +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/ImageAnnotatorTest.java @@ -14,14 +14,14 @@ package com.google.cloud.vision.spi.v1; -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.cloud.vision.v1.AnnotateImageRequest; import com.google.cloud.vision.v1.BatchAnnotateImagesRequest; import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; import com.google.common.collect.Lists; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -71,7 +71,7 @@ public void tearDown() throws Exception { @SuppressWarnings("all") public void batchAnnotateImagesTest() { BatchAnnotateImagesResponse expectedResponse = BatchAnnotateImagesResponse.newBuilder().build(); - List expectedResponses = new ArrayList<>(); + List expectedResponses = new ArrayList<>(); expectedResponses.add(expectedResponse); mockImageAnnotator.setResponses(expectedResponses); @@ -80,7 +80,7 @@ public void batchAnnotateImagesTest() { BatchAnnotateImagesResponse actualResponse = api.batchAnnotateImages(requests); Assert.assertEquals(expectedResponse, actualResponse); - List actualRequests = mockImageAnnotator.getRequests(); + List actualRequests = mockImageAnnotator.getRequests(); Assert.assertEquals(1, actualRequests.size()); BatchAnnotateImagesRequest actualRequest = (BatchAnnotateImagesRequest) actualRequests.get(0); diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotator.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotator.java index e308fef89443..db4b51a7fe06 100644 --- a/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotator.java +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotator.java @@ -16,7 +16,7 @@ import com.google.api.gax.testing.MockGrpcService; import com.google.cloud.vision.v1.ImageAnnotatorGrpc; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.ServerServiceDefinition; import java.util.List; @@ -29,18 +29,18 @@ public MockImageAnnotator() { } @Override - public List getRequests() { + public List getRequests() { return serviceImpl.getRequests(); } @Override - public void setResponses(List responses) { + public void setResponses(List responses) { serviceImpl.setResponses(responses); } @Override public ServerServiceDefinition getServiceDefinition() { - return ImageAnnotatorGrpc.bindService(serviceImpl); + return serviceImpl.bindService(); } @Override diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotatorImpl.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotatorImpl.java index 845ab36db57f..637a31b78bd7 100644 --- a/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotatorImpl.java +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/spi/v1/MockImageAnnotatorImpl.java @@ -16,9 +16,9 @@ import com.google.cloud.vision.v1.BatchAnnotateImagesRequest; import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; -import com.google.cloud.vision.v1.ImageAnnotatorGrpc.ImageAnnotator; +import com.google.cloud.vision.v1.ImageAnnotatorGrpc.ImageAnnotatorImplBase; import com.google.common.collect.Lists; -import com.google.protobuf.GeneratedMessage; +import com.google.protobuf.GeneratedMessageV3; import io.grpc.stub.StreamObserver; import java.util.ArrayList; import java.util.LinkedList; @@ -26,20 +26,20 @@ import java.util.Queue; @javax.annotation.Generated("by GAPIC") -public class MockImageAnnotatorImpl implements ImageAnnotator { - private ArrayList requests; - private Queue responses; +public class MockImageAnnotatorImpl extends ImageAnnotatorImplBase { + private ArrayList requests; + private Queue responses; public MockImageAnnotatorImpl() { requests = new ArrayList<>(); responses = new LinkedList<>(); } - public List getRequests() { + public List getRequests() { return requests; } - public void setResponses(List responses) { + public void setResponses(List responses) { this.responses = Lists.newLinkedList(responses); }