Search in sources :

Example 6 with ListLogMetricsRequest

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));
}
Also used : ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Example 7 with ListLogMetricsRequest

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));
}
Also used : ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Example 8 with ListLogMetricsRequest

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));
}
Also used : ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Example 9 with ListLogMetricsRequest

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));
}
Also used : ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Example 10 with ListLogMetricsRequest

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));
}
Also used : ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Aggregations

ListLogMetricsRequest (com.google.logging.v2.ListLogMetricsRequest)10 ListLogMetricsResponse (com.google.logging.v2.ListLogMetricsResponse)10 LogMetric (com.google.logging.v2.LogMetric)9 Test (org.junit.Test)9 AsyncPage (com.google.api.gax.paging.AsyncPage)1 ListLogMetricsPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 ParentNameOneof (com.google.logging.v2.ParentNameOneof)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1