Search in sources :

Example 6 with ListMonitoredResourceDescriptorsResponse

use of com.google.logging.v2.ListMonitoredResourceDescriptorsResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListResourceDescriptorEmpty.

@Test
public void testListResourceDescriptorEmpty() {
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
    List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of();
    ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken("").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();
    assertNull(page.getNextPageToken());
    assertNull(page.getNextPage());
    assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 7 with ListMonitoredResourceDescriptorsResponse

use of com.google.logging.v2.ListMonitoredResourceDescriptorsResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListResourceDescriptorAsyncEmpty.

@Test
public void testListResourceDescriptorAsyncEmpty() throws ExecutionException, InterruptedException {
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().build();
    List<MonitoredResourceDescriptor> descriptorList = ImmutableList.of();
    ListMonitoredResourceDescriptorsResponse response = ListMonitoredResourceDescriptorsResponse.newBuilder().setNextPageToken("").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().get();
    assertNull(page.getNextPageToken());
    assertNull(page.getNextPage());
    assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 8 with ListMonitoredResourceDescriptorsResponse

use of com.google.logging.v2.ListMonitoredResourceDescriptorsResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListResourceDescriptorNextPage.

@Test
public void testListResourceDescriptorNextPage() {
    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);
    Page<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptors();
    assertEquals(cursor1, page.getNextPageToken());
    assertArrayEquals(descriptorList1.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
    page = page.getNextPage();
    assertEquals(cursor2, page.getNextPageToken());
    assertArrayEquals(descriptorList2.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 9 with ListMonitoredResourceDescriptorsResponse

use of com.google.logging.v2.ListMonitoredResourceDescriptorsResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testListResourceDescriptorAsync.

@Test
public void testListResourceDescriptorAsync() throws ExecutionException, InterruptedException {
    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);
    AsyncPage<MonitoredResourceDescriptor> page = logging.listMonitoredResourceDescriptorsAsync().get();
    assertEquals(cursor, page.getNextPageToken());
    assertArrayEquals(descriptorList.toArray(), Iterables.toArray(page.getValues(), MonitoredResourceDescriptor.class));
}
Also used : ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) Test(org.junit.Test)

Example 10 with ListMonitoredResourceDescriptorsResponse

use of com.google.logging.v2.ListMonitoredResourceDescriptorsResponse in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImpl method listMonitoredResourceDescriptorsAsync.

private static ApiFuture<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
    final ListMonitoredResourceDescriptorsRequest request = listMonitoredResourceDescriptorsRequest(options);
    ApiFuture<ListMonitoredResourceDescriptorsResponse> list = serviceOptions.getLoggingRpcV2().list(request);
    return transform(list, new Function<ListMonitoredResourceDescriptorsResponse, AsyncPage<MonitoredResourceDescriptor>>() {

        @Override
        public AsyncPage<MonitoredResourceDescriptor> apply(ListMonitoredResourceDescriptorsResponse listDescriptorsResponse) {
            List<MonitoredResourceDescriptor> descriptors = listDescriptorsResponse.getResourceDescriptorsList() == null ? ImmutableList.<MonitoredResourceDescriptor>of() : Lists.transform(listDescriptorsResponse.getResourceDescriptorsList(), new Function<com.google.api.MonitoredResourceDescriptor, MonitoredResourceDescriptor>() {

                @Override
                public MonitoredResourceDescriptor apply(com.google.api.MonitoredResourceDescriptor monitoredResourceDescriptor) {
                    return MonitoredResourceDescriptor.FROM_PB_FUNCTION.apply(monitoredResourceDescriptor);
                }
            });
            String cursor = listDescriptorsResponse.getNextPageToken().equals("") ? null : listDescriptorsResponse.getNextPageToken();
            return new AsyncPageImpl<>(new MonitoredResourceDescriptorPageFetcher(serviceOptions, cursor, options), cursor, descriptors);
        }
    });
}
Also used : MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) AsyncPage(com.google.api.gax.paging.AsyncPage) ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

MonitoredResourceDescriptor (com.google.cloud.MonitoredResourceDescriptor)9 ListMonitoredResourceDescriptorsRequest (com.google.logging.v2.ListMonitoredResourceDescriptorsRequest)9 ListMonitoredResourceDescriptorsResponse (com.google.logging.v2.ListMonitoredResourceDescriptorsResponse)9 Test (org.junit.Test)9 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)1 AsyncPage (com.google.api.gax.paging.AsyncPage)1 ListMonitoredResourceDescriptorsPagedResponse (com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMonitoredResourceDescriptorsPagedResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 ListMonitoredResourceDescriptorsRequest (com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest)1 ListMonitoredResourceDescriptorsResponse (com.google.monitoring.v3.ListMonitoredResourceDescriptorsResponse)1 ProjectName (com.google.monitoring.v3.ProjectName)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1