use of com.google.cloud.MonitoredResourceDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptorAsyncNextPage.
@Test
public void testListResourceDescriptorAsyncNextPage() throws ExecutionException, InterruptedException {
String cursor1 = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request1 = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
ListMonitoredResourceDescriptorsRequest request2 = ListMonitoredResourceDescriptorsRequest.newBuilder().setPageToken(cursor1).build();
List<MonitoredResourceDescriptor> descriptorList1 = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
List<MonitoredResourceDescriptor> descriptorList2 = ImmutableList.of(DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response1 = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor1).addAllResourceDescriptors(Lists.transform(descriptorList1, DESCRIPTOR_TO_PB_FUNCTION)).build();
String cursor2 = "nextCursor";
ListMonitoredResourceDescriptorsResponse response2 = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor2).addAllResourceDescriptors(Lists.transform(descriptorList2, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
EasyMock.replay(loggingRpcMock);
AsyncPage<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptorsAsync().get();
assertEquals(cursor1, page.getNextPageToken());
assertArrayEquals(descriptorList1.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
page = page.getNextPageAsync().get();
assertEquals(cursor2, page.getNextPageToken());
assertArrayEquals(descriptorList2.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
use of com.google.cloud.MonitoredResourceDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method listMonitoredResourceDescriptorsAsync.
/**
* Example of asynchronously listing monitored resource descriptors, specifying the page size.
*/
// [TARGET listMonitoredResourceDescriptorsAsync(ListOption...)]
public Page<MonitoredResourceDescriptor> listMonitoredResourceDescriptorsAsync() throws ExecutionException, InterruptedException {
// [START listMonitoredResourceDescriptorsAsync]
Future<AsyncPage<MonitoredResourceDescriptor>> future = logging.listMonitoredResourceDescriptorsAsync(ListOption.pageSize(100));
// ...
AsyncPage<MonitoredResourceDescriptor> descriptors = future.get();
for (MonitoredResourceDescriptor descriptor : descriptors.iterateAll()) {
// do something with the descriptor
}
// [END listMonitoredResourceDescriptorsAsync]
return descriptors;
}
use of com.google.cloud.MonitoredResourceDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptorAsyncWithOptions.
@Test
public void testListResourceDescriptorAsyncWithOptions() throws ExecutionException, InterruptedException {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().setPageToken(cursor).setPageSize(42).build();
List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor).addAllResourceDescriptors(Lists.transform(descriptorList, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptorsAsync(ListOption.pageSize(42), ListOption.pageToken(cursor)).get();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
use of com.google.cloud.MonitoredResourceDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptorWithOptions.
@Test
public void testListResourceDescriptorWithOptions() {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().setPageToken(cursor).setPageSize(42).build();
List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor).addAllResourceDescriptors(Lists.transform(descriptorList, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptors(ListOption.pageSize(42), ListOption.pageToken(cursor));
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
use of com.google.cloud.MonitoredResourceDescriptor in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListResourceDescriptor.
@Test
public void testListResourceDescriptor() {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of(DESCRIPTOR, DESCRIPTOR);
ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken(cursor).addAllResourceDescriptors(Lists.transform(descriptorList, DESCRIPTOR_TO_PB_FUNCTION)).build();
ApiFuture<ListMonitoredResourceDescriptorsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptors();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
Aggregations