Search in sources :

Example 11 with LogEntry

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

Example 12 with LogEntry

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

Example 13 with LogEntry

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);
}
Also used : DeleteLogRequest(com.google.logging.v2.DeleteLogRequest)

Example 14 with LogEntry

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

Example 15 with LogEntry

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

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