summaryrefslogtreecommitdiff
path: root/test/files/jvm/actmig-public-methods.scala
diff options
context:
space:
mode:
authorVojin Jovanovic <vojin.jovanovic@epfl.ch>2012-09-24 17:06:08 +0200
committerVojin Jovanovic <vojin.jovanovic@epfl.ch>2012-09-25 11:14:46 +0200
commit3ba88113f23a1cd614366d770cb22fd2c6336771 (patch)
treef1bfb46d34f3538ffdc1f5b567b33e889febfd96 /test/files/jvm/actmig-public-methods.scala
parentb92becd757d8319129fa8bd0a93af8c6fd2b23b7 (diff)
downloadscala-3ba88113f23a1cd614366d770cb22fd2c6336771.tar.gz
scala-3ba88113f23a1cd614366d770cb22fd2c6336771.tar.bz2
scala-3ba88113f23a1cd614366d770cb22fd2c6336771.zip
Additional Actor Migration Tests.
Review by @phaller.
Diffstat (limited to 'test/files/jvm/actmig-public-methods.scala')
-rw-r--r--test/files/jvm/actmig-public-methods.scala74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/files/jvm/actmig-public-methods.scala b/test/files/jvm/actmig-public-methods.scala
new file mode 100644
index 0000000000..58d7a1a9d4
--- /dev/null
+++ b/test/files/jvm/actmig-public-methods.scala
@@ -0,0 +1,74 @@
+/**
+ * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change
+ * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov.
+ */
+import scala.collection.mutable.ArrayBuffer
+import scala.actors.Actor._
+import scala.actors._
+import scala.actors.migration.MigrationSystem
+import scala.util.continuations._
+import java.util.concurrent.{ TimeUnit, CountDownLatch }
+
+object Test {
+ val NUMBER_OF_TESTS = 6
+
+ // used for sorting non-deterministic output
+ val buff = ArrayBuffer[String]()
+ val latch = new CountDownLatch(NUMBER_OF_TESTS)
+ val toStop = ArrayBuffer[Actor]()
+
+ def append(v: String) = synchronized {
+ buff += v
+ }
+
+ def main(args: Array[String]) = {
+
+ val respActor = actor {
+ loop {
+ react {
+ case (x: String, time: Long) =>
+ Thread.sleep(time)
+ reply(x + " after " + time)
+ case str: String =>
+ append(str)
+ latch.countDown()
+ case _ => exit()
+ }
+ }
+ }
+
+ toStop += respActor
+
+ respActor ! ("bang")
+
+ val res1 = respActor !? (("bang qmark", 0L))
+ append(res1.toString)
+ latch.countDown()
+
+ val res2 = respActor !? (5000, ("bang qmark", 1L))
+ append(res2.toString)
+ latch.countDown()
+
+ // this one should timeout
+ val res21 = respActor !? (1, ("bang qmark", 5000L))
+ append(res21.toString)
+ latch.countDown()
+
+ val fut1 = respActor !! (("bang bang in the future", 0L))
+ append(fut1().toString())
+ latch.countDown()
+
+ val fut2 = respActor !! (("typed bang bang in the future", 0L), { case x: String => x })
+ append(fut2())
+ latch.countDown()
+
+ // output
+ latch.await(10, TimeUnit.SECONDS)
+ if (latch.getCount() > 0) {
+ println("Error: Tasks have not finished!!!")
+ }
+
+ buff.sorted.foreach(println)
+ toStop.foreach(_ ! 'stop)
+ }
+} \ No newline at end of file