+act #15284 Add throws TimeoutException to Inbox.receive

(cherry picked from commit ab19cc8a527f1a01a8180c2b199affcb47e5b1d2)
This commit is contained in:
Patrik Nordwall 2014-06-25 17:08:28 +02:00
parent d225149a96
commit 3a94510869
3 changed files with 40 additions and 2 deletions

View file

@ -0,0 +1,29 @@
/**
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.actor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.ClassRule;
import org.junit.Test;
import akka.testkit.AkkaJUnitActorSystemResource;
import akka.testkit.AkkaSpec;
import scala.concurrent.duration.FiniteDuration;
public class InboxJavaAPITest {
@ClassRule
public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("InboxJavaAPITest",
AkkaSpec.testConf());
private final ActorSystem system = actorSystemResource.getSystem();
@Test(expected = TimeoutException.class)
public void mustBeAbleToThrowTimeoutException() throws TimeoutException {
Inbox inbox = Inbox.create(system);
inbox.receive(new FiniteDuration(10, TimeUnit.MILLISECONDS));
}
}

View file

@ -121,6 +121,7 @@ abstract class Inbox {
* up to the specified duration to await reception of a message. If no message
* is received a [[java.util.concurrent.TimeoutException]] will be raised.
*/
@throws(classOf[java.util.concurrent.TimeoutException])
def receive(max: FiniteDuration): Any
/**

View file

@ -38,7 +38,11 @@ public class InboxDocTest {
probe.expectMsgEquals("hello");
probe.send(probe.getLastSender(), "world");
//#inbox
assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)).equals("world");
try {
assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)).equals("world");
} catch (java.util.concurrent.TimeoutException e) {
// timeout
}
//#inbox
}
@ -50,7 +54,11 @@ public class InboxDocTest {
final Inbox inbox = Inbox.create(system);
inbox.watch(target);
target.tell(PoisonPill.getInstance(), ActorRef.noSender());
assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)) instanceof Terminated;
try {
assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)) instanceof Terminated;
} catch (java.util.concurrent.TimeoutException e) {
// timeout
}
//#watch
}