Partial work + broken commit
This commit is contained in:
parent
3911b18069
commit
52d33113d9
50 changed files with 228 additions and 1092 deletions
|
|
@ -5,6 +5,8 @@ import akka.actor.ActorSystem;
|
|||
|
||||
import akka.japi.*;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.Promise;
|
||||
import scala.concurrent.util.Duration;
|
||||
import akka.testkit.TestKitExtension;
|
||||
import org.junit.AfterClass;
|
||||
|
|
@ -54,7 +56,7 @@ public class JavaFutureTests {
|
|||
public String apply(String s) {
|
||||
return s + " World";
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
|
||||
assertEquals("Hello World", Await.result(f2, timeout));
|
||||
}
|
||||
|
|
@ -63,13 +65,13 @@ public class JavaFutureTests {
|
|||
public void mustBeAbleToExecuteAnOnResultCallback() throws Throwable {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
Future<String> f = cf;
|
||||
Future<String> f = cf.future();
|
||||
f.onSuccess(new OnSuccess<String>() {
|
||||
public void onSuccess(String result) {
|
||||
if (result.equals("foo"))
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
|
||||
cf.success("foo");
|
||||
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
|
||||
|
|
@ -80,13 +82,13 @@ public class JavaFutureTests {
|
|||
public void mustBeAbleToExecuteAnOnExceptionCallback() throws Throwable {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
Future<String> f = cf;
|
||||
Future<String> f = cf.future();
|
||||
f.onFailure(new OnFailure() {
|
||||
public void onFailure(Throwable t) {
|
||||
if (t instanceof NullPointerException)
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
|
||||
Throwable exception = new NullPointerException();
|
||||
cf.failure(exception);
|
||||
|
|
@ -98,12 +100,12 @@ public class JavaFutureTests {
|
|||
public void mustBeAbleToExecuteAnOnCompleteCallback() throws Throwable {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
Future<String> f = cf;
|
||||
Future<String> f = cf.future();
|
||||
f.onComplete(new OnComplete<String>() {
|
||||
public void onComplete(Throwable t, String r) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
|
||||
cf.success("foo");
|
||||
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
|
||||
|
|
@ -114,12 +116,12 @@ public class JavaFutureTests {
|
|||
public void mustBeAbleToForeachAFuture() throws Throwable {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
Future<String> f = cf;
|
||||
Future<String> f = cf.future();
|
||||
f.foreach(new Foreach<String>() {
|
||||
public void each(String future) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
},system.dispatcher());
|
||||
|
||||
cf.success("foo");
|
||||
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
|
||||
|
|
@ -131,16 +133,16 @@ public class JavaFutureTests {
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
cf.success("1000");
|
||||
Future<String> f = cf;
|
||||
Future<String> f = cf.future();
|
||||
Future<Integer> r = f.flatMap(new Mapper<String, Future<Integer>>() {
|
||||
public Future<Integer> checkedApply(String r) throws Throwable {
|
||||
if (false) throw new IOException("Just here to make sure this compiles.");
|
||||
latch.countDown();
|
||||
Promise<Integer> cf = Futures.promise(system.dispatcher());
|
||||
cf.success(Integer.parseInt(r));
|
||||
return cf;
|
||||
return cf.future();
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
|
||||
assertEquals(Await.result(f, timeout), "1000");
|
||||
assertEquals(Await.result(r, timeout).intValue(), 1000);
|
||||
|
|
@ -151,13 +153,13 @@ public class JavaFutureTests {
|
|||
public void mustBeAbleToFilterAFuture() throws Throwable {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Promise<String> cf = Futures.promise(system.dispatcher());
|
||||
Future<String> f = cf;
|
||||
Future<String> f = cf.future();
|
||||
Future<String> r = f.filter(Filter.filterOf(new Function<String, Boolean>() {
|
||||
public Boolean apply(String r) {
|
||||
latch.countDown();
|
||||
return r.equals("foo");
|
||||
}
|
||||
}));
|
||||
}), system.dispatcher());
|
||||
|
||||
cf.success("foo");
|
||||
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
|
||||
|
|
@ -281,8 +283,8 @@ public class JavaFutureTests {
|
|||
Promise<String> p = Futures.promise(system.dispatcher());
|
||||
Duration d = Duration.create(1, TimeUnit.SECONDS);
|
||||
p.success("foo");
|
||||
Await.ready(p, d);
|
||||
assertEquals(Await.result(p, d), "foo");
|
||||
Await.ready(p.future(), d);
|
||||
assertEquals(Await.result(p.future(), d), "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -291,8 +293,8 @@ public class JavaFutureTests {
|
|||
Future<String> f = p.future().mapTo(classTag(String.class));
|
||||
Duration d = Duration.create(1, TimeUnit.SECONDS);
|
||||
p.success("foo");
|
||||
Await.ready(p, d);
|
||||
assertEquals(Await.result(p, d), "foo");
|
||||
Await.ready(p.future(), d);
|
||||
assertEquals(Await.result(p.future(), d), "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -306,7 +308,7 @@ public class JavaFutureTests {
|
|||
else
|
||||
throw t;
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
Duration d = Duration.create(1, TimeUnit.SECONDS);
|
||||
p.failure(fail);
|
||||
assertEquals(Await.result(f, d), "foo");
|
||||
|
|
@ -323,7 +325,7 @@ public class JavaFutureTests {
|
|||
else
|
||||
throw t;
|
||||
}
|
||||
});
|
||||
}, system.dispatcher());
|
||||
Duration d = Duration.create(1, TimeUnit.SECONDS);
|
||||
p.failure(fail);
|
||||
assertEquals(Await.result(f, d), "foo");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue