@Override default ListenableFuture<?> whenBuildFinishes() { return transform(getPagesFuture(), ignored -> null, directExecutor()); } }
public ListenableFuture<TaskStatus> getTaskStatus(TaskState callersCurrentState) { requireNonNull(callersCurrentState, "callersCurrentState is null"); if (callersCurrentState.isDone()) { return immediateFuture(getTaskStatus()); } ListenableFuture<TaskState> futureTaskState = taskStateMachine.getStateChange(callersCurrentState); return Futures.transform(futureTaskState, input -> getTaskStatus(), directExecutor()); }
@Override protected ListenableFuture<String> buildChainingFuture(ListenableFuture<Integer> inputFuture) { return transform(inputFuture, new ComposeFunction(), directExecutor()); }
public static ListenableFuture<SplitBatch> fetchNextBatchAsync( SplitSource splitSource, int min, int max, ConnectorPartitionHandle partitionHandle, Lifespan lifespan) { GetNextBatch getNextBatch = new GetNextBatch(splitSource, min, max, partitionHandle, lifespan); ListenableFuture<?> future = getNextBatch.fetchSplits(); return Futures.transform(future, ignored -> new SplitBatch(getNextBatch.splits, getNextBatch.noMoreSplits), directExecutor()); }
@Override public ListenableFuture<SplitBatch> getNextBatch(ConnectorPartitionHandle partitionHandle, Lifespan lifespan, int maxSize) { ListenableFuture<SplitBatch> batch = splitSource.getNextBatch(partitionHandle, lifespan, maxSize); return Futures.transform(batch, splitBatch -> new SplitBatch( splitBatch.getSplits().stream() .filter(input -> ThreadLocalRandom.current().nextDouble() < sampleRatio) .collect(toImmutableList()), splitBatch.isLastBatch()), directExecutor()); }
@Override public ListenableFuture<OuterPositionIterator> getOuterPositionsFuture(Lifespan lifespan) { checkArgument(Lifespan.taskWide().equals(lifespan), "join bridge is not partitioned"); return transform(joinLifecycle.whenBuildAndProbeFinishes(), ignored -> taskWideJoinBridge.getOuterPositionIterator(), directExecutor()); }
@Override public ListenableFuture<OuterPositionIterator> getOuterPositionsFuture(Lifespan lifespan) { checkArgument(Lifespan.taskWide().equals(lifespan)); return transform(joinLifecycle.whenBuildAndProbeFinishes(), ignored -> joinBridge.getOuterPositionIterator(), directExecutor()); }
@Override public ListenableFuture<SplitBatch> getNextBatch(ConnectorPartitionHandle partitionHandle, Lifespan lifespan, int maxSize) { ListenableFuture<ConnectorSplitBatch> nextBatch = toListenableFuture(source.getNextBatch(partitionHandle, maxSize)); return Futures.transform(nextBatch, splitBatch -> { ImmutableList.Builder<Split> result = ImmutableList.builder(); for (ConnectorSplit connectorSplit : splitBatch.getSplits()) { result.add(new Split(connectorId, transactionHandle, connectorSplit, lifespan)); } return new SplitBatch(result.build(), splitBatch.isNoMoreSplits()); }, directExecutor()); }
@Override public ListenableFuture<OuterPositionIterator> getOuterPositionsFuture(Lifespan lifespan) { return transform( data(lifespan).joinLifecycle.whenBuildAndProbeFinishes(), ignored -> data(lifespan).joinBridge.getOuterPositionIterator(), directExecutor()); }
public void testTransform_ExceptionAfterCancellation() throws Exception { class Transformer implements Function<Object, Object> { ListenableFuture<Object> output; @Override public Object apply(Object input) { output.cancel(false); throw new MyRuntimeException(); } } Transformer transformer = new Transformer(); SettableFuture<Object> input = SettableFuture.create(); ListenableFuture<Object> output = transform(input, transformer, directExecutor()); transformer.output = output; input.set("foo"); assertTrue(output.isCancelled()); }
public void testTransform_ErrorAfterCancellation() throws Exception { class Transformer implements Function<Object, Object> { ListenableFuture<Object> output; @Override public Object apply(Object input) { output.cancel(false); throw new MyError(); } } Transformer transformer = new Transformer(); SettableFuture<Object> input = SettableFuture.create(); ListenableFuture<Object> output = transform(input, transformer, directExecutor()); transformer.output = output; input.set("foo"); assertTrue(output.isCancelled()); }
public void testTransform_genericsNull() throws Exception { ListenableFuture<?> nullFuture = immediateFuture(null); ListenableFuture<?> transformedFuture = transform(nullFuture, constant(null), directExecutor()); assertNull(getDone(transformedFuture)); }
public void testTransform_listenerThrowsError() throws Exception { SettableFuture<Object> input = SettableFuture.create(); ListenableFuture<Object> output = transform(input, identity(), directExecutor()); output.addListener( new Runnable() { @Override public void run() { throw new MyError(); } }, directExecutor()); try { input.set("foo"); fail(); } catch (MyError expected) { } }
public void testTransform_genericsHierarchy() throws Exception { ListenableFuture<FooChild> future = immediateFuture(null); final BarChild barChild = new BarChild(); Function<Foo, BarChild> function = new Function<Foo, BarChild>() { @Override public BarChild apply(Foo unused) { return barChild; } }; Bar bar = getDone(transform(future, function, directExecutor())); assertSame(barChild, bar); }
public void testTransform_rejectionPropagatesToOutput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); Function<Foo, Foo> identity = identity(); ListenableFuture<Foo> transformed = transform(input, identity, REJECTING_EXECUTOR); input.set(new Foo()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
private static ListenableFuture<NextBatchResult> getNextBatch(SplitSource splitSource, int maxSize) { ListenableFuture<SplitBatch> future = splitSource.getNextBatch(NOT_PARTITIONED, Lifespan.taskWide(), maxSize); return Futures.transform(future, NextBatchResult::new, directExecutor()); }
private static SerializedPage getNextPage(ExchangeClient exchangeClient) { ListenableFuture<SerializedPage> futurePage = Futures.transform(exchangeClient.isBlocked(), ignored -> exchangeClient.pollPage(), directExecutor()); return tryGetFutureValue(futurePage, 100, TimeUnit.SECONDS).orElse(null); }
public void testTransform_getThrowsError() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingError(new MyError()); ListenableFuture<Object> output = transform(input, identity(), directExecutor()); try { getDone(output); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyError.class); } }
public void testTransform_Executor() throws Exception { Object value = new Object(); ExecutorSpy spy = new ExecutorSpy(directExecutor()); assertFalse(spy.wasExecuted); ListenableFuture<Object> future = transform(immediateFuture(value), identity(), spy); assertSame(value, getDone(future)); assertTrue(spy.wasExecuted); }
public void testTransform_getThrowsRuntimeException() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingRuntimeException(new MyRuntimeException()); ListenableFuture<Object> output = transform(input, identity(), directExecutor()); try { getDone(output); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyRuntimeException.class); } }