use of com.google.logging.v2.WriteLogEntriesResponse 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());
}
use of com.google.logging.v2.WriteLogEntriesResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testFlush.
@Test
public void testFlush() throws InterruptedException {
SettableApiFuture<WriteLogEntriesResponse> mockRpcResponse = SettableApiFuture.create();
replay(rpcFactoryMock);
logging = options.getService();
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder().addAllEntries(Iterables.transform(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT))).build();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(mockRpcResponse);
EasyMock.replay(loggingRpcMock);
// no messages, nothing to flush.
logging.flush();
// send a message
logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2));
Thread flushWaiter = new Thread(new Runnable() {
@Override
public void run() {
logging.flush();
}
});
flushWaiter.start();
// flushWaiter should be waiting for mockRpc to complete.
flushWaiter.join(1000);
assertTrue(flushWaiter.isAlive());
// With the RPC completed, flush should return, and the thread should terminate.
mockRpcResponse.set(null);
flushWaiter.join(1000);
assertFalse(flushWaiter.isAlive());
}
use of com.google.logging.v2.WriteLogEntriesResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testWriteLogEntriesAsyncWithOptions.
@Test
public void testWriteLogEntriesAsyncWithOptions() {
Map<String, String> labels = ImmutableMap.of("key", "value");
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder().putAllLabels(labels).setLogName(LOG_NAME_PB).setResource(MONITORED_RESOURCE.toPb()).addAllEntries(Iterables.transform(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT))).build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.newBuilder().build();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
EasyMock.replay(rpcFactoryMock, loggingRpcMock);
logging = options.getService();
logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), WriteOption.logName(LOG_NAME), WriteOption.resource(MONITORED_RESOURCE), WriteOption.labels(labels));
logging.flush();
}
use of com.google.logging.v2.WriteLogEntriesResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testWriteLogEntriesAsync.
@Test
public void testWriteLogEntriesAsync() throws ExecutionException, InterruptedException {
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder().addAllEntries(Iterables.transform(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT))).build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.newBuilder().build();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
EasyMock.replay(rpcFactoryMock, loggingRpcMock);
logging = options.getService();
logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2));
logging.flush();
}
use of com.google.logging.v2.WriteLogEntriesResponse in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImplTest method testWriteLogEntriesWithOptions.
@Test
public void testWriteLogEntriesWithOptions() {
Map<String, String> labels = ImmutableMap.of("key", "value");
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder().putAllLabels(labels).setLogName(LOG_NAME_PB).setResource(MONITORED_RESOURCE.toPb()).addAllEntries(Iterables.transform(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT))).build();
WriteLogEntriesResponse response = WriteLogEntriesResponse.newBuilder().build();
EasyMock.expect(loggingRpcMock.write(request)).andReturn(ApiFutures.immediateFuture(response));
EasyMock.replay(rpcFactoryMock, loggingRpcMock);
logging = options.getService();
logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), WriteOption.logName(LOG_NAME), WriteOption.resource(MONITORED_RESOURCE), WriteOption.labels(labels));
}
Aggregations