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_1.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_1.scala')
-rw-r--r-- | test/files/jvm/actmig-public-methods_1.scala | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/test/files/jvm/actmig-public-methods_1.scala b/test/files/jvm/actmig-public-methods_1.scala new file mode 100644 index 0000000000..41798c4c37 --- /dev/null +++ b/test/files/jvm/actmig-public-methods_1.scala @@ -0,0 +1,88 @@ +import scala.collection.mutable.ArrayBuffer +import scala.actors.Actor._ +import scala.actors._ +import scala.util._ +import java.util.concurrent.{ TimeUnit, CountDownLatch } +import scala.concurrent.util.Duration +import scala.actors.pattern._ + +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[ActorRef]() + + def append(v: String) = synchronized { + buff += v + } + + def main(args: Array[String]) = { + + val respActor = MigrationSystem.actorOf(Props(() => actor { + loop { + react { + case (x: String, time: Long) => + Thread.sleep(time) + reply(x + " after " + time) + case str: String => + append(str) + latch.countDown() + case x => + exit() + } + } + }, "akka.actor.default-stash-dispatcher")) + + toStop += respActor + + respActor ! "bang" + + implicit val timeout = Timeout(Duration(200, TimeUnit.MILLISECONDS)) + val msg = ("bang qmark", 0L) + val res1 = respActor.?(msg)(Timeout(Duration.Inf)) + append(res1().toString) + latch.countDown() + + val msg1 = ("bang qmark", 1L) + val res2 = respActor.?(msg1)(Timeout(Duration(200, TimeUnit.MILLISECONDS))) + append((res2() match { + case x: AskTimeoutException => None + case v => Some(v) + }).toString) + latch.countDown() + + // this one should time out + val msg11 = ("bang qmark", 200L) + val res21 = respActor.?(msg11)(Timeout(Duration(1, TimeUnit.MILLISECONDS))) + append((res21() match { + case x: AskTimeoutException => None + case v => Some(v) + }).toString) + latch.countDown() + + val msg2 = ("bang qmark in future", 0L) + val fut1 = respActor.?(msg2)(Duration.Inf) + append(fut1().toString()) + latch.countDown() + + val handler: PartialFunction[Any, String] = { + case x: String => x.toString + } + + val msg3 = ("typed bang qmark in future", 0L) + val fut2 = (respActor.?(msg3)(Duration.Inf)) + append(Futures.future { handler.apply(fut2()) }().toString) + latch.countDown() + + // output + latch.await(10, TimeUnit.MILLISECONDS) + if (latch.getCount() > 0) { + println("Error: Tasks have not finished!!!") + } + + buff.sorted.foreach(println) + toStop.foreach(_ ! PoisonPill) + } +} |