Adding some tests to make sure that the Future Java API doesn`t change breakingly
This commit is contained in:
parent
0896807cab
commit
c0efbc690f
1 changed files with 68 additions and 3 deletions
|
|
@ -5,12 +5,11 @@ import static org.junit.Assert.*;
|
|||
import java.util.concurrent.Callable;
|
||||
import java.util.LinkedList;
|
||||
import akka.japi.Function;
|
||||
import akka.japi.Function2;
|
||||
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;
|
||||
import static akka.dispatch.Futures.*;
|
||||
|
||||
public class JavaFutureTests {
|
||||
|
||||
|
|
@ -49,4 +48,70 @@ public class JavaFutureTests {
|
|||
assertEquals(futureList.get(), listExpected);
|
||||
}
|
||||
|
||||
// TODO: Improve this test, perhaps with an Actor
|
||||
@Test public void foldForJavaApiMustWork() {
|
||||
LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
|
||||
StringBuilder expected = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
expected.append("test");
|
||||
listFutures.add(future(new Callable<String>() {
|
||||
public String call() {
|
||||
return "test";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Future<String> result = fold("", 15000,listFutures, new Function2<String,String,String>(){
|
||||
public String apply(String r, String t) {
|
||||
return r + t;
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(result.get(), expected.toString());
|
||||
}
|
||||
|
||||
@Test public void reduceForJavaApiMustWork() {
|
||||
LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
|
||||
StringBuilder expected = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
expected.append("test");
|
||||
listFutures.add(future(new Callable<String>() {
|
||||
public String call() {
|
||||
return "test";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Future<String> result = reduce(listFutures, 15000, new Function2<String,String,String>(){
|
||||
public String apply(String r, String t) {
|
||||
return r + t;
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(result.get(), expected.toString());
|
||||
}
|
||||
|
||||
@Test public void traverseForJavaApiMustWork() {
|
||||
LinkedList<String> listStrings = new LinkedList<String>();
|
||||
LinkedList<String> expectedStrings = new LinkedList<String>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
expectedStrings.add("TEST");
|
||||
listStrings.add("test");
|
||||
}
|
||||
|
||||
Future<LinkedList<String>> result = traverse(listStrings, new Function<String,Future<String>>(){
|
||||
public Future<String> apply(final String r) {
|
||||
return future(new Callable<String>() {
|
||||
public String call() {
|
||||
return r.toUpperCase();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(result.get(), expectedStrings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue