/** 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; }
@Test public void testUpdate() { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.getOptions()).andReturn(mockOptions).times(2); expect(logging.update(expectedSink)).andReturn(expectedSink); replay(logging); initializeSink(); Sink updatedSink = sink.toBuilder().setFilter(NEW_FILTER).build().update(); compareSink(expectedSink, updatedSink); }
@Test public void testUpdateAsync() throws ExecutionException, InterruptedException { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.getOptions()).andReturn(mockOptions).times(2); expect(logging.updateAsync(expectedSink)).andReturn(ApiFutures.immediateFuture(expectedSink)); replay(logging); initializeSink(); Sink updatedSink = sink.toBuilder().setFilter(NEW_FILTER).build().updateAsync().get(); compareSink(expectedSink, updatedSink); }
@Test public void testCreateGetUpdateAndDeleteSink() { String name = formatForTest("test-create-get-update-sink"); SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) .setFilter("severity>=ERROR") .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); Sink sink = logging().create(sinkInfo); assertEquals(name, sink.getName()); assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); assertEquals("severity>=ERROR", sink.getFilter()); DatasetDestination datasetDestination = sink.getDestination(); assertEquals(logging().getOptions().getProjectId(), datasetDestination.getProject()); assertEquals("dataset", datasetDestination.getDataset()); assertEquals(sink, logging().getSink(name)); sink = sink.toBuilder().setFilter("severity<=ERROR").build().update(); assertEquals(name, sink.getName()); assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); assertEquals("severity<=ERROR", sink.getFilter()); assertTrue(sink.delete()); assertFalse(sink.delete()); }
@Test public void testBuilder() { initializeExpectedSink(2); replay(logging); Sink builtSink = expectedSink .toBuilder() .setName(NEW_NAME) .setFilter(NEW_FILTER) .setDestination(DATASET_DESTINATION) .setVersionFormat(NEW_VERSION) .build(); assertEquals(NEW_NAME, builtSink.getName()); assertEquals(DATASET_DESTINATION, builtSink.getDestination()); assertEquals(NEW_FILTER, builtSink.getFilter()); assertEquals(NEW_VERSION, builtSink.getVersionFormat()); }
@Test public void testToBuilder() { initializeExpectedSink(2); replay(logging); compareSink(expectedSink, expectedSink.toBuilder().build()); }
/** Example of updating the sink's information. */ // [TARGET update()] public Sink update() { // [START update] Sink updatedSink = sink.toBuilder().setFilter("severity<=ERROR").build().update(); // [END update] return updatedSink; }