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:
commit
018e0c33b5
3 changed files with 40 additions and 2 deletions
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -121,6 +121,7 @@ abstract class Inbox {
|
||||||
* up to the specified duration to await reception of a message. If no message
|
* up to the specified duration to await reception of a message. If no message
|
||||||
* is received a [[java.util.concurrent.TimeoutException]] will be raised.
|
* is received a [[java.util.concurrent.TimeoutException]] will be raised.
|
||||||
*/
|
*/
|
||||||
|
@throws(classOf[java.util.concurrent.TimeoutException])
|
||||||
def receive(max: FiniteDuration): Any
|
def receive(max: FiniteDuration): Any
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,11 @@ public class InboxDocTest {
|
||||||
probe.expectMsgEquals("hello");
|
probe.expectMsgEquals("hello");
|
||||||
probe.send(probe.getLastSender(), "world");
|
probe.send(probe.getLastSender(), "world");
|
||||||
//#inbox
|
//#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
|
//#inbox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +54,11 @@ public class InboxDocTest {
|
||||||
final Inbox inbox = Inbox.create(system);
|
final Inbox inbox = Inbox.create(system);
|
||||||
inbox.watch(target);
|
inbox.watch(target);
|
||||||
target.tell(PoisonPill.getInstance(), ActorRef.noSender());
|
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
|
//#watch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue