Merge pull request #328 from jboner/wip-1821-checked-exceptions-√

First stab, do we want to go for throws Throwable or even just switch to...
This commit is contained in:
viktorklang 2012-02-19 13:49:56 -08:00
commit 5e2b74bfe6
11 changed files with 45 additions and 38 deletions

View file

@ -39,7 +39,7 @@ public class JavaFutureTests {
}
@Test
public void mustBeAbleToMapAFuture() {
public void mustBeAbleToMapAFuture() throws Exception {
Future<String> f1 = Futures.future(new Callable<String>() {
public String call() {
@ -163,7 +163,7 @@ public class JavaFutureTests {
// TODO: Improve this test, perhaps with an Actor
@Test
public void mustSequenceAFutureList() {
public void mustSequenceAFutureList() throws Exception{
LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
LinkedList<String> listExpected = new LinkedList<String>();
@ -183,7 +183,7 @@ public class JavaFutureTests {
// TODO: Improve this test, perhaps with an Actor
@Test
public void foldForJavaApiMustWork() {
public void foldForJavaApiMustWork() throws Exception{
LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
StringBuilder expected = new StringBuilder();
@ -206,7 +206,7 @@ public class JavaFutureTests {
}
@Test
public void reduceForJavaApiMustWork() {
public void reduceForJavaApiMustWork() throws Exception{
LinkedList<Future<String>> listFutures = new LinkedList<Future<String>>();
StringBuilder expected = new StringBuilder();
@ -229,7 +229,7 @@ public class JavaFutureTests {
}
@Test
public void traverseForJavaApiMustWork() {
public void traverseForJavaApiMustWork() throws Exception{
LinkedList<String> listStrings = new LinkedList<String>();
LinkedList<String> expectedStrings = new LinkedList<String>();
@ -252,7 +252,7 @@ public class JavaFutureTests {
}
@Test
public void findForJavaApiMustWork() {
public void findForJavaApiMustWork() throws Exception{
LinkedList<Future<Integer>> listFutures = new LinkedList<Future<Integer>>();
for (int i = 0; i < 10; i++) {
final Integer fi = i;
@ -273,7 +273,7 @@ public class JavaFutureTests {
}
@Test
public void blockMustBeCallable() {
public void blockMustBeCallable() throws Exception {
Promise<String> p = Futures.promise(system.dispatcher());
Duration d = Duration.create(1, TimeUnit.SECONDS);
p.success("foo");
@ -282,7 +282,7 @@ public class JavaFutureTests {
}
@Test
public void mapToMustBeCallable() {
public void mapToMustBeCallable() throws Exception {
Promise<Object> p = Futures.promise(system.dispatcher());
Future<String> f = p.future().mapTo(manifest(String.class));
Duration d = Duration.create(1, TimeUnit.SECONDS);
@ -292,7 +292,7 @@ public class JavaFutureTests {
}
@Test
public void recoverToMustBeCallable() {
public void recoverToMustBeCallable() throws Exception {
final IllegalStateException fail = new IllegalStateException("OHNOES");
Promise<Object> p = Futures.promise(system.dispatcher());
Future<Object> f = p.future().recover(new Recover<Object>() {
@ -309,7 +309,7 @@ public class JavaFutureTests {
}
@Test
public void recoverWithToMustBeCallable() {
public void recoverWithToMustBeCallable() throws Exception{
final IllegalStateException fail = new IllegalStateException("OHNOES");
Promise<Object> p = Futures.promise(system.dispatcher());
Future<Object> f = p.future().recoverWith(new Recover<Future<Object>>() {

View file

@ -39,12 +39,14 @@ object Await {
* Should throw [[java.util.concurrent.TimeoutException]] if times out
* This method should not be called directly.
*/
@throws(classOf[TimeoutException])
def ready(atMost: Duration)(implicit permit: CanAwait): this.type
/**
* Throws exceptions if cannot produce a T within the specified time
* This method should not be called directly.
*/
@throws(classOf[Exception])
def result(atMost: Duration)(implicit permit: CanAwait): T
}
@ -57,6 +59,7 @@ object Await {
* @throws [[java.util.concurrent.TimeoutException]] if times out
* @return The returned value as returned by Awaitable.ready
*/
@throws(classOf[TimeoutException])
def ready[T <: Awaitable[_]](awaitable: T, atMost: Duration): T = awaitable.ready(atMost)
/**
@ -66,6 +69,7 @@ object Await {
* @throws [[java.util.concurrent.TimeoutException]] if times out
* @return The returned value as returned by Awaitable.result
*/
@throws(classOf[Exception])
def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable.result(atMost)
}
@ -819,10 +823,12 @@ class DefaultPromise[T](implicit val executor: ExecutionContext) extends Abstrac
awaitUnsafe(if (atMost.isFinite) atMost.toNanos else Long.MaxValue)
}
@throws(classOf[TimeoutException])
def ready(atMost: Duration)(implicit permit: CanAwait): this.type =
if (isCompleted || tryAwait(atMost)) this
else throw new TimeoutException("Futures timed out after [" + atMost.toMillis + "] milliseconds")
@throws(classOf[Exception])
def result(atMost: Duration)(implicit permit: CanAwait): T =
ready(atMost).value.get match {
case Left(e: AskTimeoutException) throw new AskTimeoutException(e.getMessage, e) // to get meaningful stack trace

View file

@ -150,7 +150,7 @@ public class FaultHandlingTestBase {
}
@Test
public void mustEmploySupervisorStrategy() {
public void mustEmploySupervisorStrategy() throws Exception {
// code here
//#testkit
EventFilter ex1 = (EventFilter) new ErrorFilter(ArithmeticException.class);

View file

@ -130,7 +130,7 @@ public class UntypedActorDocTestBase {
}
@Test
public void usingAsk() {
public void usingAsk() throws Exception {
ActorSystem system = ActorSystem.create("MySystem");
ActorRef myActor = system.actorOf(new Props(new UntypedActorFactory() {
public UntypedActor create() {
@ -188,7 +188,7 @@ public class UntypedActorDocTestBase {
}
@Test
public void useWatch() {
public void useWatch() throws Exception {
ActorSystem system = ActorSystem.create("MySystem");
ActorRef myActor = system.actorOf(new Props(WatchActor.class));
Future<Object> future = Patterns.ask(myActor, "kill", 1000);
@ -197,7 +197,7 @@ public class UntypedActorDocTestBase {
}
@Test
public void usePatternsGracefulStop() {
public void usePatternsGracefulStop() throws Exception {
ActorSystem system = ActorSystem.create("MySystem");
ActorRef actorRef = system.actorOf(new Props(MyUntypedActor.class));
//#gracefulStop

View file

@ -74,7 +74,7 @@ public class FutureDocTestBase {
}
@Test
public void useBlockingFromActor() {
public void useBlockingFromActor() throws Exception {
ActorRef actor = system.actorOf(new Props(MyActor.class));
String msg = "hello";
//#ask-blocking
@ -86,7 +86,7 @@ public class FutureDocTestBase {
}
@Test
public void useFutureEval() {
public void useFutureEval() throws Exception {
//#future-eval
Future<String> f = future(new Callable<String>() {
public String call() {
@ -99,7 +99,7 @@ public class FutureDocTestBase {
}
@Test
public void useMap() {
public void useMap() throws Exception {
//#map
Future<String> f1 = future(new Callable<String>() {
public String call() {
@ -162,7 +162,7 @@ public class FutureDocTestBase {
}
@Test
public void useFlatMap() {
public void useFlatMap() throws Exception {
//#flat-map
Future<String> f1 = future(new Callable<String>() {
public String call() {
@ -186,7 +186,7 @@ public class FutureDocTestBase {
}
@Test
public void useSequence() {
public void useSequence() throws Exception {
List<Future<Integer>> source = new ArrayList<Future<Integer>>();
source.add(Futures.successful(1, system.dispatcher()));
source.add(Futures.successful(2, system.dispatcher()));
@ -214,7 +214,7 @@ public class FutureDocTestBase {
}
@Test
public void useTraverse() {
public void useTraverse() throws Exception {
//#traverse
//Just a sequence of Strings
Iterable<String> listStrings = Arrays.asList("a", "b", "c");
@ -236,7 +236,7 @@ public class FutureDocTestBase {
}
@Test
public void useFold() {
public void useFold() throws Exception {
List<Future<String>> source = new ArrayList<Future<String>>();
source.add(Futures.successful("a", system.dispatcher()));
source.add(Futures.successful("b", system.dispatcher()));
@ -258,7 +258,7 @@ public class FutureDocTestBase {
}
@Test
public void useReduce() {
public void useReduce() throws Exception {
List<Future<String>> source = new ArrayList<Future<String>>();
source.add(Futures.successful("a", system.dispatcher()));
source.add(Futures.successful("b", system.dispatcher()));
@ -280,7 +280,7 @@ public class FutureDocTestBase {
}
@Test
public void useSuccessfulAndFailed() {
public void useSuccessfulAndFailed() throws Exception {
//#successful
Future<String> future = Futures.successful("Yay!", system.dispatcher());
//#successful
@ -294,7 +294,7 @@ public class FutureDocTestBase {
}
@Test
public void useFilter() {
public void useFilter() throws Exception {
//#filter
Future<Integer> future1 = Futures.successful(4, system.dispatcher());
Future<Integer> successfulFilter = future1.filter(new Filter<Integer>() {
@ -338,7 +338,7 @@ public class FutureDocTestBase {
}
@Test
public void useRecover() {
public void useRecover() throws Exception {
//#recover
Future<Integer> future = future(new Callable<Integer>() {
public Integer call() {
@ -358,7 +358,7 @@ public class FutureDocTestBase {
}
@Test
public void useTryRecover() {
public void useTryRecover() throws Exception {
//#try-recover
Future<Integer> future = future(new Callable<Integer>() {
public Integer call() {
@ -382,7 +382,7 @@ public class FutureDocTestBase {
}
@Test
public void useOnSuccessOnFailureAndOnComplete() {
public void useOnSuccessOnFailureAndOnComplete() throws Exception {
{
Future<String> future = Futures.successful("foo", system.dispatcher());
@ -429,7 +429,7 @@ public class FutureDocTestBase {
}
@Test
public void useOrAndZip() {
public void useOrAndZip() throws Exception {
{
//#zip
Future<String> future1 = Futures.successful("foo", system.dispatcher());

View file

@ -55,7 +55,7 @@ public class CustomRouterDocTestBase {
//#crTest
@Test
public void countVotesAsIntendedNotAsInFlorida() {
public void countVotesAsIntendedNotAsInFlorida() throws Exception {
ActorRef routedActor = system.actorOf(new Props().withRouter(new VoteCountRouter()));
routedActor.tell(DemocratVote);
routedActor.tell(DemocratVote);

View file

@ -18,7 +18,7 @@ import akka.dispatch.Await;
//#parentActor
public class ParentActor extends UntypedActor {
public void onReceive(Object msg) {
public void onReceive(Object msg) throws Exception {
if (msg.equals("rrr")) {
//#roundRobinRouter
ActorRef roundRobinRouter = getContext().actorOf(

View file

@ -20,7 +20,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
public class TransactorDocTest {
@Test
public void coordinatedExample() {
public void coordinatedExample() throws Exception {
//#coordinated-example
ActorSystem system = ActorSystem.create("CoordinatedExample");
@ -63,7 +63,7 @@ public class TransactorDocTest {
}
@Test
public void counterTransactor() {
public void counterTransactor() throws Exception {
ActorSystem system = ActorSystem.create("CounterTransactor");
ActorRef counter = system.actorOf(new Props(Counter.class));
@ -79,7 +79,7 @@ public class TransactorDocTest {
}
@Test
public void friendlyCounterTransactor() {
public void friendlyCounterTransactor() throws Exception {
ActorSystem system = ActorSystem.create("FriendlyCounterTransactor");
ActorRef friend = system.actorOf(new Props(Counter.class));
ActorRef friendlyCounter = system.actorOf(new Props(FriendlyCounter.class));

View file

@ -30,13 +30,14 @@ class TestLatch(count: Int = 1)(implicit system: ActorSystem) extends Awaitable[
def open() = while (!isOpen) countDown()
def reset() = latch = new CountDownLatch(count)
@throws(classOf[TimeoutException])
def ready(atMost: Duration)(implicit permit: CanAwait) = {
val opened = latch.await(atMost.dilated.toNanos, TimeUnit.NANOSECONDS)
if (!opened) throw new TimeoutException(
"Timeout of %s with time factor of %s" format (atMost.toString, TestKitExtension(system).TestTimeFactor))
this
}
@throws(classOf[Exception])
def result(atMost: Duration)(implicit permit: CanAwait): Unit = {
ready(atMost)
}

View file

@ -72,7 +72,7 @@ public class UntypedCoordinatedIncrementTest {
}
@Test
public void incrementAllCountersWithSuccessfulTransaction() {
public void incrementAllCountersWithSuccessfulTransaction() throws Exception {
CountDownLatch incrementLatch = new CountDownLatch(numCounters);
Increment message = new Increment(counters.subList(1, counters.size()), incrementLatch);
counters.get(0).tell(new Coordinated(message, timeout));
@ -88,7 +88,7 @@ public class UntypedCoordinatedIncrementTest {
}
@Test
public void incrementNoCountersWithFailingTransaction() {
public void incrementNoCountersWithFailingTransaction() throws Exception {
EventFilter expectedFailureFilter = (EventFilter) new ErrorFilter(ExpectedFailureException.class);
EventFilter coordinatedFilter = (EventFilter) new ErrorFilter(CoordinatedTransactionException.class);
Seq<EventFilter> ignoreExceptions = seq(expectedFailureFilter, coordinatedFilter);

View file

@ -73,7 +73,7 @@ public class UntypedTransactorTest {
}
@Test
public void incrementAllCountersWithSuccessfulTransaction() {
public void incrementAllCountersWithSuccessfulTransaction() throws Exception {
CountDownLatch incrementLatch = new CountDownLatch(numCounters);
Increment message = new Increment(counters.subList(1, counters.size()), incrementLatch);
counters.get(0).tell(message);
@ -89,7 +89,7 @@ public class UntypedTransactorTest {
}
@Test
public void incrementNoCountersWithFailingTransaction() {
public void incrementNoCountersWithFailingTransaction() throws Exception {
EventFilter expectedFailureFilter = (EventFilter) new ErrorFilter(ExpectedFailureException.class);
EventFilter coordinatedFilter = (EventFilter) new ErrorFilter(CoordinatedTransactionException.class);
Seq<EventFilter> ignoreExceptions = seq(expectedFailureFilter, coordinatedFilter);