use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListLogEntriesAyncEmpty.
@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));
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListLogEntriesWithOptions.
@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));
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingClient method deleteLog.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes all the log entries in a log. The log reappears if it receives new entries. Log entries
* written shortly before the delete operation might not be deleted.
*
* <p>Sample code:
*
* <pre><code>
* try (LoggingClient loggingClient = LoggingClient.create()) {
* LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
* loggingClient.deleteLog(logName);
* }
* </code></pre>
*
* @param logName Required. The resource name of the log to delete:
* <p>"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]"
* "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]"
* <p>`[LOG_ID]` must be URL-encoded. For example, `"projects/my-project-id/logs/syslog"`,
* `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. For more
* information about log names, see [LogEntry][google.logging.v2.LogEntry].
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void deleteLog(LogNameOneof logName) {
DeleteLogRequest request = DeleteLogRequest.newBuilder().setLogNameWithLogNameOneof(logName).build();
deleteLog(request);
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListLogEntriesAsyncWithOptions.
@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));
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListLogEntries.
@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));
}
Aggregations