aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-11-26 14:39:22 -0800
committerJason Zaugg <jzaugg@gmail.com>2012-11-26 14:39:22 -0800
commit72f72811582af9a9c41dbc82a74d771198024a57 (patch)
tree275eddcf4ab55fb04e9c5224c6c1da69de6c0449 /src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
parent3fd51865dfcb6121f84145f4504abd0f80bf6cca (diff)
parent4eb47ba34bf10bc483fa8f04a9f76708f9161317 (diff)
downloadscala-async-72f72811582af9a9c41dbc82a74d771198024a57.tar.gz
scala-async-72f72811582af9a9c41dbc82a74d771198024a57.tar.bz2
scala-async-72f72811582af9a9c41dbc82a74d771198024a57.zip
Merge pull request #44 from phaller/topic/exception-handling
Topic/exception handling
Diffstat (limited to 'src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala')
-rw-r--r--src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
new file mode 100644
index 0000000..733ea01
--- /dev/null
+++ b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
+ */
+
+package scala.async
+package run
+package exceptions
+
+import scala.async.Async.{async, await}
+
+import scala.concurrent.{future, ExecutionContext, Await}
+import ExecutionContext.Implicits._
+import scala.concurrent.duration._
+import scala.reflect.ClassTag
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class ExceptionsSpec {
+
+ @Test
+ def `uncaught exception within async`() {
+ val fut = async { throw new Exception("problem") }
+ intercept[Exception] { Await.result(fut, 2.seconds) }
+ }
+
+ @Test
+ def `uncaught exception within async after await`() {
+ val base = future { "five!".length }
+ val fut = async {
+ val len = await(base)
+ throw new Exception(s"illegal length: $len")
+ }
+ intercept[Exception] { Await.result(fut, 2.seconds) }
+ }
+
+ @Test
+ def `await failing future within async`() {
+ val base = future[Int] { throw new Exception("problem") }
+ val fut = async {
+ val x = await(base)
+ x * 2
+ }
+ intercept[Exception] { Await.result(fut, 2.seconds) }
+ }
+
+ @Test
+ def `await failing future within async after await`() {
+ val base = future[Any] { "five!".length }
+ val fut = async {
+ val a = await(base.mapTo[Int]) // result: 5
+ val b = await((future { (a * 2).toString }).mapTo[Int]) // result: ClassCastException
+ val c = await(future { (7 * 2).toString }) // result: "14"
+ b + "-" + c
+ }
+ intercept[ClassCastException] { Await.result(fut, 2.seconds) }
+ }
+
+}