use of com.google.logging.v2.ListLogMetricsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListMetricsWithOptionsAsync.
@Test
public void testListMetricsWithOptionsAsync() throws ExecutionException, InterruptedException {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setPageToken(cursor).setPageSize(42).setParent(PROJECT_PB).build();
List<Metric> sinkList = ImmutableList.of(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)));
ListLogMetricsResponse response = ListLogMetricsResponse.newBuilder().setNextPageToken(cursor).addAllMetrics(Lists.transform(sinkList, METRIC_TO_PB_FUNCTION)).build();
ApiFuture<ListLogMetricsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<Metric> page = logging.listMetricsAsync(ListOption.pageSize(42), ListOption.pageToken(cursor)).get();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Metric.class));
}
use of com.google.logging.v2.ListLogMetricsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListMetricsAsync.
@Test
public void testListMetricsAsync() throws ExecutionException, InterruptedException {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(PROJECT_PB).build();
List<Metric> sinkList = ImmutableList.of(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)));
ListLogMetricsResponse response = ListLogMetricsResponse.newBuilder().setNextPageToken(cursor).addAllMetrics(Lists.transform(sinkList, METRIC_TO_PB_FUNCTION)).build();
ApiFuture<ListLogMetricsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
AsyncPage<Metric> page = logging.listMetricsAsync().get();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Metric.class));
}
use of com.google.logging.v2.ListLogMetricsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListMetrics.
@Test
public void testListMetrics() {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(PROJECT_PB).build();
List<Metric> sinkList = ImmutableList.of(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)));
ListLogMetricsResponse response = ListLogMetricsResponse.newBuilder().setNextPageToken(cursor).addAllMetrics(Lists.transform(sinkList, METRIC_TO_PB_FUNCTION)).build();
ApiFuture<ListLogMetricsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<Metric> page = logging.listMetrics();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Metric.class));
}
use of com.google.logging.v2.ListLogMetricsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListMetricsAsyncNextPage.
@Test
public void testListMetricsAsyncNextPage() throws ExecutionException, InterruptedException {
String cursor1 = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListLogMetricsRequest request1 = ListLogMetricsRequest.newBuilder().setParent(PROJECT_PB).build();
ListLogMetricsRequest request2 = ListLogMetricsRequest.newBuilder().setParent(PROJECT_PB).setPageToken(cursor1).build();
List<Metric> sinkList1 = ImmutableList.of(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)));
List<Metric> sinkList2 = ImmutableList.of(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)));
ListLogMetricsResponse response1 = ListLogMetricsResponse.newBuilder().setNextPageToken(cursor1).addAllMetrics(Lists.transform(sinkList1, METRIC_TO_PB_FUNCTION)).build();
String cursor2 = "nextCursor";
ListLogMetricsResponse response2 = ListLogMetricsResponse.newBuilder().setNextPageToken(cursor2).addAllMetrics(Lists.transform(sinkList2, METRIC_TO_PB_FUNCTION)).build();
ApiFuture<ListLogMetricsResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
ApiFuture<ListLogMetricsResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
EasyMock.replay(loggingRpcMock);
AsyncPage<Metric> page = logging.listMetricsAsync().get();
assertEquals(cursor1, page.getNextPageToken());
assertArrayEquals(sinkList1.toArray(), Iterables.toArray(page.getValues(), Metric.class));
page = page.getNextPageAsync().get();
assertEquals(cursor2, page.getNextPageToken());
assertArrayEquals(sinkList2.toArray(), Iterables.toArray(page.getValues(), Metric.class));
}
use of com.google.logging.v2.ListLogMetricsRequest in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListMetricsEmpty.
@Test
public void testListMetricsEmpty() {
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListLogMetricsRequest request = ListLogMetricsRequest.newBuilder().setParent(PROJECT_PB).build();
List<Metric> sinkList = ImmutableList.of();
ListLogMetricsResponse response = ListLogMetricsResponse.newBuilder().setNextPageToken("").addAllMetrics(Lists.transform(sinkList, METRIC_TO_PB_FUNCTION)).build();
ApiFuture<ListLogMetricsResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<Metric> page = logging.listMetrics();
assertNull(page.getNextPageToken());
assertNull(page.getNextPage());
assertArrayEquals(sinkList.toArray(), Iterables.toArray(page.getValues(), Metric.class));
}
Aggregations