use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method listLogEntriesAsync.
private static ApiFuture<AsyncPage<LogEntry>> listLogEntriesAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListLogEntriesRequest request = listLogEntriesRequest(serviceOptions, options);
ApiFuture<ListLogEntriesResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListLogEntriesResponse, AsyncPage<LogEntry>>() {
@Override
public AsyncPage<LogEntry> apply(ListLogEntriesResponse listLogEntrysResponse) {
List<LogEntry> entries = listLogEntrysResponse.getEntriesList() == null ? ImmutableList.<LogEntry>of() : Lists.transform(listLogEntrysResponse.getEntriesList(), LogEntry.FROM_PB_FUNCTION);
String cursor = listLogEntrysResponse.getNextPageToken().equals("") ? null : listLogEntrysResponse.getNextPageToken();
return new AsyncPageImpl<>(new LogEntryPageFetcher(serviceOptions, cursor, options), cursor, entries);
}
});
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method writeLogEntriesRequest.
private static WriteLogEntriesRequest writeLogEntriesRequest(LoggingOptions serviceOptions, Iterable<LogEntry> logEntries, Map<Option.OptionType, ?> options) {
String projectId = serviceOptions.getProjectId();
WriteLogEntriesRequest.Builder builder = WriteLogEntriesRequest.newBuilder();
String logName = LOG_NAME.get(options);
if (logName != null) {
builder.setLogName(LogName.create(projectId, logName).toString());
}
MonitoredResource resource = RESOURCE.get(options);
if (resource != null) {
builder.setResource(resource.toPb());
}
Map<String, String> labels = LABELS.get(options);
if (labels != null) {
builder.putAllLabels(labels);
}
builder.addAllEntries(Iterables.transform(logEntries, LogEntry.toPbFunction(projectId)));
return builder.build();
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testListLogEntriesAsync.
@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));
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingClientTest method writeLogEntriesExceptionTest.
@Test
@SuppressWarnings("all")
public void writeLogEntriesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockLoggingServiceV2.addException(exception);
try {
LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
MonitoredResource resource = MonitoredResource.newBuilder().build();
Map<String, String> labels = new HashMap<>();
List<LogEntry> entries = new ArrayList<>();
client.writeLogEntries(logName, resource, labels, entries);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.logging.v2.LogEntry in project google-cloud-java by GoogleCloudPlatform.
the class LoggingClientTest method writeLogEntriesTest.
@Test
@SuppressWarnings("all")
public void writeLogEntriesTest() {
WriteLogEntriesResponse expectedResponse = WriteLogEntriesResponse.newBuilder().build();
mockLoggingServiceV2.addResponse(expectedResponse);
LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
MonitoredResource resource = MonitoredResource.newBuilder().build();
Map<String, String> labels = new HashMap<>();
List<LogEntry> entries = new ArrayList<>();
WriteLogEntriesResponse actualResponse = client.writeLogEntries(logName, resource, labels, entries);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockLoggingServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
WriteLogEntriesRequest actualRequest = (WriteLogEntriesRequest) actualRequests.get(0);
Assert.assertEquals(logName, actualRequest.getLogNameAsLogNameOneof());
Assert.assertEquals(resource, actualRequest.getResource());
Assert.assertEquals(labels, actualRequest.getLabelsMap());
Assert.assertEquals(entries, actualRequest.getEntriesList());
}
Aggregations