diff --git a/pom.xml b/pom.xml index 778f614..a655b67 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,10 @@ A small library for composing asynchronous Java code. - 17.0 + 21.0 + 1.8 + 1.8 UTF-8 diff --git a/src/main/java/com/spotify/trickle/Graph.java b/src/main/java/com/spotify/trickle/Graph.java index 5a56b42..b2409c6 100644 --- a/src/main/java/com/spotify/trickle/Graph.java +++ b/src/main/java/com/spotify/trickle/Graph.java @@ -50,7 +50,7 @@ public abstract class Graph implements Parameter, NodeInfo { /** * Run the graph, executing all node methods on the thread that completes the underlying future. * This is equivalent to calling {@link #run(java.util.concurrent.Executor)} with {@link - * com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor()}. + * com.google.common.util.concurrent.MoreExecutors#directExecutor()}. * * @return a future for the value returned by the graph execution * @throws IllegalArgumentException if not all {@link Input}s used in node invocations are bound diff --git a/src/main/java/com/spotify/trickle/NodeExecutionFallback.java b/src/main/java/com/spotify/trickle/NodeExecutionFallback.java index 9336005..73def5c 100644 --- a/src/main/java/com/spotify/trickle/NodeExecutionFallback.java +++ b/src/main/java/com/spotify/trickle/NodeExecutionFallback.java @@ -16,7 +16,7 @@ package com.spotify.trickle; -import com.google.common.util.concurrent.FutureFallback; +import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.ListenableFuture; import static com.google.common.base.Preconditions.checkNotNull; @@ -26,7 +26,7 @@ /** * Fallback that handles errors when executing a graph node. */ -class NodeExecutionFallback implements FutureFallback { +class NodeExecutionFallback implements AsyncFunction { private final TraverseState.FutureCallInformation currentCall; private final TraverseState state; @@ -41,7 +41,7 @@ public NodeExecutionFallback(GraphBuilder graph, } @Override - public ListenableFuture create(Throwable t) { + public ListenableFuture apply(Throwable t) { if (graph.getFallback().isPresent()) { try { return graph.getFallback().get().apply(t); diff --git a/src/main/java/com/spotify/trickle/PreparedGraph.java b/src/main/java/com/spotify/trickle/PreparedGraph.java index e246336..f079f68 100644 --- a/src/main/java/com/spotify/trickle/PreparedGraph.java +++ b/src/main/java/com/spotify/trickle/PreparedGraph.java @@ -30,12 +30,10 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Preconditions.*; import static com.google.common.collect.ImmutableList.builder; import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.directExecutor; /** * A decorator class for Graph that holds bound values for input names thus making @@ -80,7 +78,7 @@ public Graph debug(boolean debug) { @Override public ListenableFuture run() { - return run(sameThreadExecutor()); + return run(directExecutor()); } @Override @@ -117,15 +115,17 @@ private ListenableFuture future(final TraverseState state) { checkArgument(graph.getInputs().size() == futures.size(), "sanity check result: insane"); - return Futures.withFallback( + return Futures.catchingAsync( nodeFuture(futures, allFuture, state.getExecutor()), - new NodeExecutionFallback(graph, currentCall, state)); + Exception.class, + new NodeExecutionFallback(graph, currentCall, state) + ); } private ListenableFuture nodeFuture(final ImmutableList> values, final ListenableFuture> doneSignal, final Executor executor) { - return Futures.transform( + return Futures.transformAsync( doneSignal, new AsyncFunction, R>() { @Override diff --git a/src/test/java/com/spotify/trickle/GraphExceptionWrapperTest.java b/src/test/java/com/spotify/trickle/GraphExceptionWrapperTest.java index b2b8726..0923d2f 100644 --- a/src/test/java/com/spotify/trickle/GraphExceptionWrapperTest.java +++ b/src/test/java/com/spotify/trickle/GraphExceptionWrapperTest.java @@ -66,7 +66,7 @@ public void setUp() throws Exception { t = new RuntimeException("the original problem"); Map, Object> emptyMap = Collections.emptyMap(); - traverseState = new TraverseState(emptyMap, MoreExecutors.sameThreadExecutor(), true); + traverseState = new TraverseState(emptyMap, MoreExecutors.directExecutor(), true); List currentNodeParameters = ImmutableList.of( new FakeNodeInfo("arg1", Collections .emptyList()), diff --git a/src/test/java/com/spotify/trickle/NodeExecutionFallbackTest.java b/src/test/java/com/spotify/trickle/NodeExecutionFallbackTest.java index f581795..1149c7c 100644 --- a/src/test/java/com/spotify/trickle/NodeExecutionFallbackTest.java +++ b/src/test/java/com/spotify/trickle/NodeExecutionFallbackTest.java @@ -60,7 +60,7 @@ public void setUp() throws Exception { .thenReturn(Optional.>absent()); Map, Object> emptyMap = Collections.emptyMap(); - traverseState = new TraverseState(emptyMap, MoreExecutors.sameThreadExecutor(), true); + traverseState = new TraverseState(emptyMap, MoreExecutors.directExecutor(), true); List currentNodeParameters = ImmutableList.of(); @@ -77,7 +77,7 @@ public void setUp() throws Exception { public void shouldNotWrapGraphExecutionException() throws Exception { Throwable expected = new GraphExecutionException(null, currentCallInfo, NO_CALLS); - ListenableFuture future = fallback.create(expected); + ListenableFuture future = fallback.apply(expected); try { future.get(); @@ -91,7 +91,7 @@ public void shouldNotWrapGraphExecutionException() throws Exception { public void shouldWrapGeneralException() throws Exception { Throwable expected = new RuntimeException("expected"); - ListenableFuture future = fallback.create(expected); + ListenableFuture future = fallback.apply(expected); try { future.get(); @@ -115,7 +115,7 @@ public ListenableFuture apply(Throwable input) throws Exception { Throwable expected = new GraphExecutionException(null, currentCallInfo, NO_CALLS); - ListenableFuture future = fallback.create(expected); + ListenableFuture future = fallback.apply(expected); assertThat(future.get(), equalTo("all is well, nothing to see here")); } diff --git a/src/test/java/com/spotify/trickle/PackageSanityTest.java b/src/test/java/com/spotify/trickle/PackageSanityTest.java index 110fe1d..3d28ea3 100644 --- a/src/test/java/com/spotify/trickle/PackageSanityTest.java +++ b/src/test/java/com/spotify/trickle/PackageSanityTest.java @@ -80,7 +80,7 @@ public ListenableFuture run(List values) { setDefault(Graph.class, graphBuilder); setDefault(GraphBuilder.class, graphBuilder); - setDefault(TraverseState.class, TraverseState.empty(MoreExecutors.sameThreadExecutor(), false)); + setDefault(TraverseState.class, TraverseState.empty(MoreExecutors.directExecutor(), false)); setDefault(TraverseState.FutureCallInformation.class, NO_INFO); setDefault(CallInfo.class, new CallInfo(graphBuilder, Collections.>emptyList())); diff --git a/src/test/java/com/spotify/trickle/TrickleErrorHandlingTest.java b/src/test/java/com/spotify/trickle/TrickleErrorHandlingTest.java index fa734ce..8a351ff 100644 --- a/src/test/java/com/spotify/trickle/TrickleErrorHandlingTest.java +++ b/src/test/java/com/spotify/trickle/TrickleErrorHandlingTest.java @@ -17,34 +17,29 @@ package com.spotify.trickle; import com.google.common.base.Function; +import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; - -import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import javax.annotation.Nullable; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; -import javax.annotation.Nullable; - import static com.google.common.collect.Lists.newArrayList; import static com.google.common.util.concurrent.Futures.immediateFailedFuture; import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.spotify.trickle.Trickle.call; import static com.spotify.trickle.Util.hasAncestor; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.fail; @@ -346,7 +341,7 @@ public boolean equals(@Nullable Object obj) { @Override public String toString() { - return Objects.toStringHelper(this) + return MoreObjects.toStringHelper(this) .add("nodeName", nodeName) .add("parameterNames", parameterNames) .add("parameterValues", parameterValues)