diff options
author | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-05-18 17:53:05 +0200 |
---|---|---|
committer | Vojin Jovanovic <vojin.jovanovic@epfl.ch> | 2012-05-18 17:53:05 +0200 |
commit | e99fb0c93842d517b8a185458f405bace2bbb46b (patch) | |
tree | 070e9117c43fc09e3c850594b76f1957fb68c045 /test/files/jvm/actmig-public-methods.scala | |
parent | ef7708812fac32ca0c2a05330222a6b0806c9054 (diff) | |
download | scala-e99fb0c93842d517b8a185458f405bace2bbb46b.tar.gz scala-e99fb0c93842d517b8a185458f405bace2bbb46b.tar.bz2 scala-e99fb0c93842d517b8a185458f405bace2bbb46b.zip |
Adding the Actor Migration Kit.
Kit consists of:
1) The StashingActor which adopts an interface similar to Akka.
2) Props mockup for creating Akka like code
3) Pattern mockup
4) Test cases for every step in the migration.
5) MigrationSystem which will paired on the Akka side.
Review of the code : @phaller
Review of the build: @jsuereth
Diffstat (limited to 'test/files/jvm/actmig-public-methods.scala')
-rw-r--r-- | test/files/jvm/actmig-public-methods.scala | 69 |
1 files changed, 69 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..c4c8560122 --- /dev/null +++ b/test/files/jvm/actmig-public-methods.scala @@ -0,0 +1,69 @@ +import scala.collection.mutable.ArrayBuffer +import scala.actors.Actor._ +import scala.actors._ +import scala.actors.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 !? (200, ("bang qmark", 1L)) + append(res2.toString) + latch.countDown() + + val res21 = respActor !? (1, ("bang qmark", 200L)) + append(res21.toString) + latch.countDown() + + val fut1 = respActor !! (("bang qmark in future", 0L)) + append(fut1().toString()) + latch.countDown() + + val fut2 = respActor !! (("typed bang qmark in future", 0L), { case x: String => x }) + append(fut2()) + latch.countDown() + + // output + latch.await(10, TimeUnit.MILLISECONDS) + if (latch.getCount() > 0) { + println("Error: Tasks have not finished!!!") + } + + buff.sorted.foreach(println) + toStop.foreach(_ ! 'stop) + } +} |