@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
@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(); }
@Test public void testListLogEntries() { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).build(); List<LogEntry> entriesList = ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2); 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)); }
@Test public void testListLogEntriesAyncEmpty() throws ExecutionException, InterruptedException { 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); AsyncPage<LogEntry> page = logging.listLogEntriesAsync().get(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(entriesList.toArray(), Iterables.toArray(page.getValues(), LogEntry.class)); }
@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)); }
@Test public void testListLogEntriesAsync() throws ExecutionException, InterruptedException { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).build(); List<LogEntry> entriesList = ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2); 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); AsyncPage<LogEntry> page = logging.listLogEntriesAsync().get(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(entriesList.toArray(), Iterables.toArray(page.getValues(), LogEntry.class)); }
@Test public void testListLogEntriesWithOptions() { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() .addProjectIds(PROJECT) .setOrderBy("timestamp desc") .setFilter("logName:syslog") .build(); List<LogEntry> entriesList = ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2); 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( EntryListOption.filter("logName:syslog"), EntryListOption.sortOrder(SortingField.TIMESTAMP, Logging.SortingOrder.DESCENDING)); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(entriesList.toArray(), Iterables.toArray(page.getValues(), LogEntry.class)); }
List<LogEntry> descriptorList2 = ImmutableList.of(LOG_ENTRY1); ListLogEntriesResponse response1 = ListLogEntriesResponse.newBuilder() .setNextPageToken(cursor1) .addAllEntries(Lists.transform(descriptorList1, LogEntry.toPbFunction(PROJECT))) String cursor2 = "nextCursor"; ListLogEntriesResponse response2 = ListLogEntriesResponse.newBuilder() .setNextPageToken(cursor2) .addAllEntries(Lists.transform(descriptorList2, LogEntry.toPbFunction(PROJECT)))
List<LogEntry> descriptorList2 = ImmutableList.of(LOG_ENTRY1); ListLogEntriesResponse response1 = ListLogEntriesResponse.newBuilder() .setNextPageToken(cursor1) .addAllEntries(Lists.transform(descriptorList1, LogEntry.toPbFunction(PROJECT))) String cursor2 = "nextCursor"; ListLogEntriesResponse response2 = ListLogEntriesResponse.newBuilder() .setNextPageToken(cursor2) .addAllEntries(Lists.transform(descriptorList2, LogEntry.toPbFunction(PROJECT)))
@Test public void testListLogEntriesAsyncWithOptions() throws ExecutionException, InterruptedException { String cursor = "cursor"; EasyMock.replay(rpcFactoryMock); logging = options.getService(); ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder() .addProjectIds(PROJECT) .setOrderBy("timestamp desc") .setFilter("logName:syslog") .build(); List<LogEntry> entriesList = ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2); 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); AsyncPage<LogEntry> page = logging .listLogEntriesAsync( EntryListOption.filter("logName:syslog"), EntryListOption.sortOrder(SortingField.TIMESTAMP, Logging.SortingOrder.DESCENDING)) .get(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(entriesList.toArray(), Iterables.toArray(page.getValues(), LogEntry.class)); }
List<LogEntry> entries = Arrays.asList(entriesElement); ListLogEntriesResponse expectedResponse = ListLogEntriesResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllEntries(entries)