diff options
author | aleksandar <aleksandar@lampmac14.epfl.ch> | 2011-12-12 18:57:33 +0100 |
---|---|---|
committer | aleksandar <aleksandar@lampmac14.epfl.ch> | 2011-12-12 18:57:33 +0100 |
commit | 72424e397135bb9701e2fd4e36b2184b03586bd5 (patch) | |
tree | 4fa45e44bad5686757ba271bb039ea6014632178 | |
parent | 249aa978e7900a792594d51b45f4560568f1552c (diff) | |
download | scala-72424e397135bb9701e2fd4e36b2184b03586bd5.tar.gz scala-72424e397135bb9701e2fd4e36b2184b03586bd5.tar.bz2 scala-72424e397135bb9701e2fd4e36b2184b03586bd5.zip |
Adding the tck test file.
-rw-r--r-- | test/files/jvm/scala-concurrent-tck.scala | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala new file mode 100644 index 0000000000..e1b8d2763c --- /dev/null +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -0,0 +1,166 @@ + + + +import scala.concurrent.{ + Future, + TimeoutException, + SyncVar, + ExecutionException +} + + + +trait TestBase { + + def future[T](body: =>T): Future[T] + + def once(body: (() => Unit) => Unit) { + val sv = new SyncVar[Boolean] + body(() => sv put true) + sv.take() + } + +} + + +trait FutureCallbacks extends TestBase { + + def testOnSuccess(): Unit = once { + done => + var x = 0 + val f = future { + x = 1 + } + f onSuccess { _ => + done() + assert(x == 1) + } + } + + def testOnSuccessWhenCompleted(): Unit = once { + done => + var x = 0 + val f = future { + x = 1 + } + f onSuccess { _ => + assert(x == 1) + x = 2 + f onSuccess { _ => + assert(x == 2) + done() + } + } + } + + def testOnSuccessWhenFailed(): Unit = once { + done => + val f = future[Unit] { + done() + throw new Exception + } + f onSuccess { _ => + assert(false) + } + } + + def testOnFailure(): Unit = once { + done => + var x = 0 + val f = future[Unit] { + x = 1 + throw new Exception + } + f onSuccess { _ => + done() + assert(false) + } + f onFailure { + case _ => + done() + assert(x == 1) + } + } + + def testOnFailureWhenSpecialThrowable(num: Int, cause: Throwable): Unit = once { + done => + val f = future[Unit] { + throw cause + } + f onSuccess { _ => + done() + assert(false) + } + f onFailure { + case e: ExecutionException if (e.getCause == cause) => + done() + case _ => + done() + assert(false) + } + } + + def testOnFailureWhenTimeoutException(): Unit = once { + done => + val f = future[Unit] { + throw new TimeoutException() + } + f onSuccess { _ => + done() + assert(false) + } + f onFailure { + case e: TimeoutException => + done() + case other => + done() + assert(false) + } + } + + testOnSuccess() + testOnSuccessWhenCompleted() + testOnSuccessWhenFailed() + testOnFailure() + testOnFailureWhenSpecialThrowable(5, new Error) + testOnFailureWhenSpecialThrowable(6, new scala.util.control.ControlThrowable { }) + testOnFailureWhenSpecialThrowable(7, new InterruptedException) + testOnFailureWhenTimeoutException() + +} + + +trait FutureCombinators extends TestBase { + +} + + +trait FutureProjections extends TestBase { + +} + + +trait Promises extends TestBase { + +} + + +trait Exceptions extends TestBase { + +} + + +object Test +extends App +with FutureCallbacks +with FutureCombinators +with FutureProjections +with Promises +with Exceptions +{ + + def future[T](body: =>T) = scala.concurrent.future(body) + +} + + |