Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<description>A small library for composing asynchronous Java code.</description>

<properties>
<guava.version>17.0</guava.version>
<guava.version>21.0</guava.version>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/spotify/trickle/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class Graph<T> implements Parameter<T>, 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
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/spotify/trickle/NodeExecutionFallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +26,7 @@
/**
* Fallback that handles errors when executing a graph node.
*/
class NodeExecutionFallback<R> implements FutureFallback<R> {
class NodeExecutionFallback<R> implements AsyncFunction<Throwable, R> {

private final TraverseState.FutureCallInformation currentCall;
private final TraverseState state;
Expand All @@ -41,7 +41,7 @@ public NodeExecutionFallback(GraphBuilder<R> graph,
}

@Override
public ListenableFuture<R> create(Throwable t) {
public ListenableFuture<R> apply(Throwable t) {
if (graph.getFallback().isPresent()) {
try {
return graph.getFallback().get().apply(t);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/spotify/trickle/PreparedGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,7 +78,7 @@ public Graph<R> debug(boolean debug) {

@Override
public ListenableFuture<R> run() {
return run(sameThreadExecutor());
return run(directExecutor());
}

@Override
Expand Down Expand Up @@ -117,15 +115,17 @@ private ListenableFuture<R> 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<R>(graph, currentCall, state));
Exception.class,
new NodeExecutionFallback<R>(graph, currentCall, state)
);
}

private ListenableFuture<R> nodeFuture(final ImmutableList<ListenableFuture<?>> values,
final ListenableFuture<List<Object>> doneSignal,
final Executor executor) {
return Futures.transform(
return Futures.transformAsync(
doneSignal,
new AsyncFunction<List<Object>, R>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void setUp() throws Exception {
t = new RuntimeException("the original problem");

Map<Input<?>, Object> emptyMap = Collections.emptyMap();
traverseState = new TraverseState(emptyMap, MoreExecutors.sameThreadExecutor(), true);
traverseState = new TraverseState(emptyMap, MoreExecutors.directExecutor(), true);

List<? extends NodeInfo> currentNodeParameters = ImmutableList.of(
new FakeNodeInfo("arg1", Collections .<NodeInfo>emptyList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void setUp() throws Exception {
.thenReturn(Optional.<AsyncFunction<Throwable, String>>absent());

Map<Input<?>, Object> emptyMap = Collections.emptyMap();
traverseState = new TraverseState(emptyMap, MoreExecutors.sameThreadExecutor(), true);
traverseState = new TraverseState(emptyMap, MoreExecutors.directExecutor(), true);

List<? extends NodeInfo> currentNodeParameters = ImmutableList.of();

Expand All @@ -77,7 +77,7 @@ public void setUp() throws Exception {
public void shouldNotWrapGraphExecutionException() throws Exception {
Throwable expected = new GraphExecutionException(null, currentCallInfo, NO_CALLS);

ListenableFuture<String> future = fallback.create(expected);
ListenableFuture<String> future = fallback.apply(expected);

try {
future.get();
Expand All @@ -91,7 +91,7 @@ public void shouldNotWrapGraphExecutionException() throws Exception {
public void shouldWrapGeneralException() throws Exception {
Throwable expected = new RuntimeException("expected");

ListenableFuture<String> future = fallback.create(expected);
ListenableFuture<String> future = fallback.apply(expected);

try {
future.get();
Expand All @@ -115,7 +115,7 @@ public ListenableFuture<String> apply(Throwable input) throws Exception {

Throwable expected = new GraphExecutionException(null, currentCallInfo, NO_CALLS);

ListenableFuture<String> future = fallback.create(expected);
ListenableFuture<String> future = fallback.apply(expected);

assertThat(future.get(), equalTo("all is well, nothing to see here"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/spotify/trickle/PackageSanityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.<ParameterValue<?>>emptyList()));
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/com/spotify/trickle/TrickleErrorHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down