Merge pull request #15465 from akka/wip-15284-throws-annotation-master-patriknw

+act #15284 Add throws TimeoutException to Inbox.receive
This commit is contained in:
Patrik Nordwall 2014-06-27 14:56:23 +02:00
commit 018e0c33b5
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
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());
try {
assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)) instanceof Terminated;
} catch (java.util.concurrent.TimeoutException e) {
// timeout
}
//#watch
}