Add Java API versions of Future.{traverse, sequence}, closes #786
This commit is contained in:
parent
414122bf6c
commit
ff711a4253
4 changed files with 93 additions and 27 deletions
|
|
@ -3,28 +3,50 @@ package akka.dispatch;
|
|||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.LinkedList;
|
||||
import akka.japi.Function;
|
||||
import akka.japi.Procedure;
|
||||
import scala.Some;
|
||||
import scala.Right;
|
||||
import static akka.dispatch.Futures.future;
|
||||
import static akka.dispatch.Futures.traverse;
|
||||
import static akka.dispatch.Futures.sequence;
|
||||
|
||||
@SuppressWarnings("unchecked") public class JavaFutureTests {
|
||||
public class JavaFutureTests {
|
||||
|
||||
@Test public void mustBeAbleToMapAFuture() {
|
||||
Future f1 = future(new Callable<String>() {
|
||||
Future<String> f1 = future(new Callable<String>() {
|
||||
public String call() {
|
||||
return "Hello";
|
||||
}
|
||||
});
|
||||
|
||||
Future f2 = f1.map(new Function<String, String>() {
|
||||
Future<String> f2 = f1.map(new Function<String, String>() {
|
||||
public String apply(String s) {
|
||||
return s + " World";
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(new Some(new Right("Hello World")), f2.await().value());
|
||||
assertEquals("Hello World", f2.get());
|
||||
}
|
||||
|
||||
// TODO: Improve this test, perhaps with an Actor
|
||||
@Test public void mustSequenceAFutureList() {
|
||||
LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
|
||||
LinkedList<String> listExpected = new LinkedList<String>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
listExpected.add("test");
|
||||
listFutures.add(future(new Callable<String>() {
|
||||
public String call() {
|
||||
return "test";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Future<LinkedList<String>> futureList = sequence(listFutures);
|
||||
|
||||
assertEquals(futureList.get(), listExpected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue