Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
fix: handle case where Future.cause() is null in FutureGroup (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu Tao authored and neverchanje committed Sep 24, 2019
1 parent 4e40054 commit 91f672a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 1 addition & 2 deletions carrot
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function java_client_get_next_version()
esac

if [ ${versions[2]} == "SNAPSHOT" ]; then
echo ${versions[0]}.${versions[1]}.SNAPSHOT-$staging_branch
echo ${versions[0]}.${versions[1]}-$staging_branch-SNAPSHOT
else
echo ${versions[0]}.${versions[1]}.${versions[2]}-$staging_branch
fi
Expand Down Expand Up @@ -282,7 +282,6 @@ function release_minor
carrot_execute "mvn versions:set -DnewVersion=$new_version"
carrot_execute "mvn versions:commit"
carrot_execute "git commit -am \"Bump version to $new_version\""
carrot_execute "git push -u origin $this_branch"
}

function usage_carrot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void waitAllCompleteOrOneFail(List<Result> results, int timeoutMillis) throws PE
}
} else {
Throwable cause = fu.cause();
if (cause == null) {
throw new PException(
String.format(
"async task #[" + i + "] failed: timeout expired (%dms)", timeoutMillis));
}
throw new PException("async task #[" + i + "] failed: " + cause.getMessage(), cause);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

public class TestFutureGroup {

@Rule public TestName name = new TestName();

private static final class TestEventExecutor extends SingleThreadEventExecutor {
TestEventExecutor() {
super(null, Executors.defaultThreadFactory(), false);
Expand Down Expand Up @@ -46,7 +50,7 @@ public void testBlockingOperationException() throws Exception {
group.waitAllCompleteOrOneFail(10000);
} catch (PException e) {
success.set(false);
System.err.println("TestFutureGroup.testInterrupt: " + e.toString());
System.err.println(name.getMethodName() + ": " + e.toString());
}
executed.set(true);
});
Expand All @@ -64,4 +68,22 @@ public void testBlockingOperationException() throws Exception {

Assert.assertFalse(success.get());
}

@Test
public void testFutureWaitTimeout() throws Exception {
TestEventExecutor executor = new TestEventExecutor();
Promise<Void> promise = executor.newPromise();

FutureGroup<Void> group = new FutureGroup<>(1);
group.add(promise);
try {
// never wake up promise.
group.waitAllCompleteOrOneFail(10);
} catch (PException e) {
// must throw exception
System.err.println(name.getMethodName() + ": " + e.toString());
return;
}
Assert.fail();
}
}

0 comments on commit 91f672a

Please sign in to comment.