Search in sources :

Example 6 with LogEntry

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

the class LoggingClientTest method listLogEntriesTest.

@Test
@SuppressWarnings("all")
public void listLogEntriesTest() {
    String nextPageToken = "";
    LogEntry entriesElement = LogEntry.newBuilder().build();
    List<LogEntry> entries = Arrays.asList(entriesElement);
    ListLogEntriesResponse expectedResponse = ListLogEntriesResponse.newBuilder().setNextPageToken(nextPageToken).addAllEntries(entries).build();
    mockLoggingServiceV2.addResponse(expectedResponse);
    List<String> resourceNames = new ArrayList<>();
    String filter = "filter-1274492040";
    String orderBy = "orderBy1234304744";
    ListLogEntriesPagedResponse pagedListResponse = client.listLogEntries(resourceNames, filter, orderBy);
    List<LogEntry> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getEntriesList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockLoggingServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogEntriesRequest actualRequest = (ListLogEntriesRequest) actualRequests.get(0);
    Assert.assertEquals(resourceNames, actualRequest.getResourceNamesList());
    Assert.assertEquals(filter, actualRequest.getFilter());
    Assert.assertEquals(orderBy, actualRequest.getOrderBy());
}
Also used : ListLogEntriesResponse(com.google.logging.v2.ListLogEntriesResponse) ArrayList(java.util.ArrayList) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) LogEntry(com.google.logging.v2.LogEntry) ListLogEntriesPagedResponse(com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogEntriesPagedResponse) ListLogEntriesRequest(com.google.logging.v2.ListLogEntriesRequest) Test(org.junit.Test)

Example 7 with LogEntry

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

the class LoggingImplTest method testListLogEntriesEmpty.

@Test
public void testListLogEntriesEmpty() {
    String cursor = "cursor";
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).build();
    List<LogEntry> entriesList = ImmutableList.of();
    ListLogEntriesResponse response = ListLogEntriesResponse.newBuilder().setNextPageToken(cursor).addAllEntries(Lists.transform(entriesList, LogEntry.toPbFunction(PROJECT))).build();
    ApiFuture<ListLogEntriesResponse> futureResponse = ApiFutures.immediateFuture(response);
    EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
    EasyMock.replay(loggingRpcMock);
    Page<LogEntry> page = logging.listLogEntries();
    assertEquals(cursor, page.getNextPageToken());
    assertArrayEquals(entriesList.toArray(), Iterables.toArray(page.getValues(), LogEntry.class));
}
Also used : ListLogEntriesResponse(com.google.logging.v2.ListLogEntriesResponse) ListLogEntriesRequest(com.google.logging.v2.ListLogEntriesRequest) Test(org.junit.Test)

Example 8 with LogEntry

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

the class LoggingImplTest method testListLogEntriesNextPage.

@Test
public void testListLogEntriesNextPage() throws ExecutionException, InterruptedException {
    String cursor1 = "cursor";
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListLogEntriesRequest request1 = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).build();
    ListLogEntriesRequest request2 = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).setPageToken(cursor1).build();
    List<LogEntry> descriptorList1 = ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2);
    List<LogEntry> descriptorList2 = ImmutableList.of(LOG_ENTRY1);
    ListLogEntriesResponse response1 = ListLogEntriesResponse.newBuilder().setNextPageToken(cursor1).addAllEntries(Lists.transform(descriptorList1, LogEntry.toPbFunction(PROJECT))).build();
    String cursor2 = "nextCursor";
    ListLogEntriesResponse response2 = ListLogEntriesResponse.newBuilder().setNextPageToken(cursor2).addAllEntries(Lists.transform(descriptorList2, LogEntry.toPbFunction(PROJECT))).build();
    ApiFuture<ListLogEntriesResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
    ApiFuture<ListLogEntriesResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
    EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
    EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
    EasyMock.replay(loggingRpcMock);
    AsyncPage<LogEntry> page = logging.listLogEntriesAsync().get();
    assertEquals(cursor1, page.getNextPageToken());
    assertArrayEquals(descriptorList1.toArray(), Iterables.toArray(page.getValues(), LogEntry.class));
    page = page.getNextPageAsync().get();
    assertEquals(cursor2, page.getNextPageToken());
    assertArrayEquals(descriptorList2.toArray(), Iterables.toArray(page.getValues(), LogEntry.class));
}
Also used : ListLogEntriesResponse(com.google.logging.v2.ListLogEntriesResponse) ListLogEntriesRequest(com.google.logging.v2.ListLogEntriesRequest) Test(org.junit.Test)

Example 9 with LogEntry

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

the class LoggingImplTest method testListLogEntriesAsyncNextPage.

@Test
public void testListLogEntriesAsyncNextPage() {
    String cursor1 = "cursor";
    EasyMock.replay(rpcFactoryMock);
    logging = options.getService();
    ListLogEntriesRequest request1 = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).build();
    ListLogEntriesRequest request2 = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).setPageToken(cursor1).build();
    List<LogEntry> descriptorList1 = ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2);
    List<LogEntry> descriptorList2 = ImmutableList.of(LOG_ENTRY1);
    ListLogEntriesResponse response1 = ListLogEntriesResponse.newBuilder().setNextPageToken(cursor1).addAllEntries(Lists.transform(descriptorList1, LogEntry.toPbFunction(PROJECT))).build();
    String cursor2 = "nextCursor";
    ListLogEntriesResponse response2 = ListLogEntriesResponse.newBuilder().setNextPageToken(cursor2).addAllEntries(Lists.transform(descriptorList2, LogEntry.toPbFunction(PROJECT))).build();
    ApiFuture<ListLogEntriesResponse> futureResponse1 = ApiFutures.immediateFuture(response1);
    ApiFuture<ListLogEntriesResponse> futureResponse2 = ApiFutures.immediateFuture(response2);
    EasyMock.expect(loggingRpcMock.list(request1)).andReturn(futureResponse1);
    EasyMock.expect(loggingRpcMock.list(request2)).andReturn(futureResponse2);
    EasyMock.replay(loggingRpcMock);
    Page<LogEntry> page = logging.listLogEntries();
    assertEquals(cursor1, page.getNextPageToken());
    assertArrayEquals(descriptorList1.toArray(), Iterables.toArray(page.getValues(), LogEntry.class));
    page = page.getNextPage();
    assertEquals(cursor2, page.getNextPageToken());
    assertArrayEquals(descriptorList2.toArray(), Iterables.toArray(page.getValues(), LogEntry.class));
}
Also used : ListLogEntriesResponse(com.google.logging.v2.ListLogEntriesResponse) ListLogEntriesRequest(com.google.logging.v2.ListLogEntriesRequest) Test(org.junit.Test)

Example 10 with LogEntry

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

the class LocalLoggingImpl method listLogEntries.

@Override
public void listLogEntries(ListLogEntriesRequest request, StreamObserver<ListLogEntriesResponse> responseObserver) {
    List<LogEntry> entries = new ArrayList<>();
    for (ByteString proj : request.getProjectIdsList().asByteStringList()) {
        String prefix = "projects/" + proj.toStringUtf8() + "/";
        for (Map.Entry<String, List<LogEntry>> entry : logs.entrySet()) {
            if (entry.getKey().startsWith(prefix)) {
                entries.addAll(entry.getValue());
            }
        }
    }
    responseObserver.onNext(ListLogEntriesResponse.newBuilder().addAllEntries(entries).build());
    responseObserver.onCompleted();
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ByteString(com.google.protobuf.ByteString) HashMap(java.util.HashMap) Map(java.util.Map) LogEntry(com.google.logging.v2.LogEntry)

Aggregations

Test (org.junit.Test)11 ListLogEntriesRequest (com.google.logging.v2.ListLogEntriesRequest)10 ListLogEntriesResponse (com.google.logging.v2.ListLogEntriesResponse)10 ArrayList (java.util.ArrayList)5 LogEntry (com.google.logging.v2.LogEntry)4 HashMap (java.util.HashMap)3 MonitoredResource (com.google.api.MonitoredResource)2 LogNameOneof (com.google.logging.v2.LogNameOneof)2 WriteLogEntriesRequest (com.google.logging.v2.WriteLogEntriesRequest)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 List (java.util.List)2 ApiException (com.google.api.gax.grpc.ApiException)1 AsyncPage (com.google.api.gax.paging.AsyncPage)1 MonitoredResource (com.google.cloud.MonitoredResource)1 ListLogEntriesPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogEntriesPagedResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 DeleteLogRequest (com.google.logging.v2.DeleteLogRequest)1 WriteLogEntriesResponse (com.google.logging.v2.WriteLogEntriesResponse)1 ByteString (com.google.protobuf.ByteString)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1