/** 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; }
@Test public void testReloadAsyncNull() throws ExecutionException, InterruptedException { initializeExpectedSink(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.getSinkAsync(NAME)).andReturn(ApiFutures.<Sink>immediateFuture(null)); replay(logging); initializeSink(); assertNull(sink.reloadAsync().get()); }
@Test public void testReloadAsync() 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); expect(logging.getSinkAsync(NAME)).andReturn(ApiFutures.immediateFuture(expectedSink)); replay(logging); initializeSink(); Sink updatedSink = sink.reloadAsync().get(); compareSink(expectedSink, updatedSink); }