private ApiFuture<Void> writeAsync(Iterable<LogEntry> logEntries, WriteOption... options) { return transform( rpc.write(writeLogEntriesRequest(getOptions(), logEntries, optionMap(options))), WRITE_RESPONSE_TO_VOID_FUNCTION); }
@Test public void testWriteLogEntries() { 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)); }
@Test public void testWriteLogEntriesWithSeverityFlushEnabled() { 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.setFlushSeverity(Severity.DEFAULT); logging.write(ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2)); }
@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(); }
ImmutableList.of(LOG_ENTRY1, LOG_ENTRY2), LogEntry.toPbFunction(PROJECT))) .build(); EasyMock.expect(loggingRpcMock.write(request)).andReturn(mockRpcResponse); EasyMock.replay(loggingRpcMock);
EasyMock.expect(loggingRpcMock.write(request)).andReturn(mockRpcResponse).times(threads.length); EasyMock.replay(loggingRpcMock);
@Test public void testWriteLogEntriesDoesnotEnableFlushByDefault() { WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder() .addAllEntries( Iterables.transform( ImmutableList.of( LOG_ENTRY1, LOG_ENTRY2.toBuilder().setSeverity(Severity.EMERGENCY).build()), LogEntry.toPbFunction(PROJECT))) .build(); ApiFuture<WriteLogEntriesResponse> apiFuture = SettableApiFuture.create(); EasyMock.expect(loggingRpcMock.write(request)).andReturn(apiFuture); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); logging.write( ImmutableList.of( LOG_ENTRY1, LOG_ENTRY2.toBuilder().setSeverity(Severity.EMERGENCY).build())); }
@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)); }
@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(); }
private ApiFuture<Void> writeAsync(Iterable<LogEntry> logEntries, WriteOption... options) { return transform( rpc.write(writeLogEntriesRequest(getOptions(), logEntries, optionMap(options))), WRITE_RESPONSE_TO_VOID_FUNCTION); }