/** Example of asynchronously getting a sink. */ // [TARGET getSinkAsync(String)] // [VARIABLE "my_sink_name"] public Sink getSinkAsync(String sinkName) throws ExecutionException, InterruptedException { // [START getSinkAsync] Future<Sink> future = logging.getSinkAsync(sinkName); // ... Sink sink = future.get(); if (sink == null) { // sink was not found } // [END getSinkAsync] return sink; }
/** * Sends a request to fetch current sink's latest information. This method returns a {@code * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a {@code Sink} object * with latest information or {@code null} if not found. * * <p>Example of asynchronously getting the sink's latest information. * * <pre>{@code * ApiFuture<Sink> future = sink.reloadAsync(); * // ... * Sink latestSink = future.get(); * if (latestSink == null) { * // the sink was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Sink> reloadAsync() { return logging.getSinkAsync(getName()); }
@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 testGetSinkAsync_Null() throws ExecutionException, InterruptedException { ApiFuture<LogSink> response = ApiFutures.immediateFuture(null); GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).build(); EasyMock.expect(loggingRpcMock.get(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); assertNull(logging.getSinkAsync(SINK_NAME).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); }
@Test public void testGetSinkAsync() throws ExecutionException, InterruptedException { LogSink sinkPb = SINK_INFO.toPb(PROJECT); ApiFuture<LogSink> response = ApiFutures.immediateFuture(sinkPb); GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).build(); EasyMock.expect(loggingRpcMock.get(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Sink sink = logging.getSinkAsync(SINK_NAME).get(); assertEquals(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), sink); }
/** * Sends a request to fetch current sink's latest information. This method returns a {@code * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a {@code Sink} object * with latest information or {@code null} if not found. * * <p>Example of asynchronously getting the sink's latest information. * * <pre>{@code * ApiFuture<Sink> future = sink.reloadAsync(); * // ... * Sink latestSink = future.get(); * if (latestSink == null) { * // the sink was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Sink> reloadAsync() { return logging.getSinkAsync(getName()); }