use of com.google.cloud.logging.Sink in project google-cloud-java by GoogleCloudPlatform.
the class ITLoggingSnippets method testSink.
@Test
public void testSink() throws ExecutionException, InterruptedException {
String sinkName1 = RemoteLoggingHelper.formatForTest("sink_name1");
String sinkName2 = RemoteLoggingHelper.formatForTest("sink_name2");
Sink sink1 = loggingSnippets.createSink(sinkName1, DATASET);
Sink sink2 = loggingSnippets.createSinkAsync(sinkName2, DATASET);
assertNotNull(sink1);
assertNotNull(sink2);
sink1 = loggingSnippets.getSink(sinkName1);
sink2 = loggingSnippets.getSinkAsync(sinkName2);
assertNotNull(sink1);
assertNotNull(sink2);
sink1 = loggingSnippets.updateSink(sinkName1, DATASET);
sink2 = loggingSnippets.updateSinkAsync(sinkName2, DATASET);
Set<Sink> sinks = Sets.newHashSet(loggingSnippets.listSinks().iterateAll());
while (!sinks.contains(sink1) || !sinks.contains(sink2)) {
Thread.sleep(500);
sinks = Sets.newHashSet(loggingSnippets.listSinks().iterateAll());
}
sinks = Sets.newHashSet(loggingSnippets.listSinksAsync().iterateAll());
while (!sinks.contains(sink1) || !sinks.contains(sink2)) {
Thread.sleep(500);
sinks = Sets.newHashSet(loggingSnippets.listSinksAsync().iterateAll());
}
assertTrue(loggingSnippets.deleteSink(sinkName1));
assertTrue(loggingSnippets.deleteSinkAsync(sinkName2));
}
use of com.google.cloud.logging.Sink in project google-cloud-java by GoogleCloudPlatform.
the class ITSinkSnippets method testSink.
@Test
public void testSink() throws InterruptedException, ExecutionException {
Sink sink = sinkSnippets.reload();
assertNotNull(sink);
Sink updatedSink = sinkSnippets.update();
assertEquals(UPDATED_SINK_FILTER, updatedSink.getFilter());
updatedSink = sinkSnippets.reloadAsync();
assertNotNull(updatedSink);
assertEquals(UPDATED_SINK_FILTER, updatedSink.getFilter());
sink.update();
updatedSink = sinkSnippets.updateAsync();
assertEquals(UPDATED_SINK_FILTER, updatedSink.getFilter());
assertTrue(sinkSnippets.delete());
assertFalse(sinkSnippets.deleteAsync());
}
use of com.google.cloud.logging.Sink in project google-cloud-java by GoogleCloudPlatform.
the class CreateAndListSinks method main.
public static void main(String... args) throws Exception {
// Credentials are inferred from the environment
try (Logging logging = LoggingOptions.getDefaultInstance().getService()) {
// Create a sink to back log entries to a BigQuery dataset
SinkInfo sinkInfo = SinkInfo.newBuilder("test-sink", DatasetDestination.of("test-dataset")).setFilter("severity >= ERROR").build();
logging.create(sinkInfo);
// List sinks
Page<Sink> sinks = logging.listSinks();
for (Sink sink : sinks.iterateAll()) {
System.out.println(sink);
}
}
}
use of com.google.cloud.logging.Sink in project google-cloud-java by GoogleCloudPlatform.
the class SinkSnippets method reloadAsync.
/**
* Example of asynchronously getting the sink's latest information.
*/
// [TARGET reloadAsync()]
public Sink reloadAsync() throws ExecutionException, InterruptedException {
// [START reloadAsync]
Future<Sink> future = sink.reloadAsync();
// ...
Sink latestSink = future.get();
if (latestSink == null) {
// the sink was not found
}
// [END reloadAsync]
return latestSink;
}
use of com.google.cloud.logging.Sink in project google-cloud-java by GoogleCloudPlatform.
the class SinkSnippets method updateAsync.
/**
* Example of asynchronously updating the sink's information.
*/
// [TARGET updateAsync()]
public Sink updateAsync() throws ExecutionException, InterruptedException {
// [START updateAsync]
Future<Sink> future = sink.toBuilder().setFilter("severity<=ERROR").build().updateAsync();
// ...
Sink updatedSink = future.get();
// [END updateAsync]
return updatedSink;
}