diff options
Diffstat (limited to 'test')
26 files changed, 0 insertions, 1579 deletions
diff --git a/test/files/jvm/actmig-PinS.check b/test/files/jvm/actmig-PinS.check deleted file mode 100644 index bdbdf8a692..0000000000 --- a/test/files/jvm/actmig-PinS.check +++ /dev/null @@ -1,19 +0,0 @@ -I'm acting! -I'm acting! -I'm acting! -I'm acting! -I'm acting! -Post stop -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -That is the question. -That is the question. -That is the question. -That is the question. -That is the question. -received message: hi there -received message: 15 -Got an Int: 12 diff --git a/test/files/jvm/actmig-PinS.scala b/test/files/jvm/actmig-PinS.scala deleted file mode 100644 index 3f07fab12e..0000000000 --- a/test/files/jvm/actmig-PinS.scala +++ /dev/null @@ -1,116 +0,0 @@ -/** - * 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.actors._ -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -import scala.actors.Actor._ - -/* PinS, Listing 32.1: A simple actor - */ -object SillyActor extends Actor { - def act() { - for (i <- 1 to 5) - println("I'm acting!") - - println("Post stop") - } -} - -object SeriousActor extends Actor { - def act() { - for (i <- 1 to 5) - println("To be or not to be.") - } -} - -/* PinS, Listing 32.3: An actor that calls react - */ -object NameResolver extends Actor { - import java.net.{InetAddress, UnknownHostException} - - def act() { - react { - case (name: String, actor: Actor) => - actor ! getIp(name) - act() - case "EXIT" => - println("Name resolver exiting.") - // quit - case msg => - println("Unhandled message: " + msg) - act() - } - } - - def getIp(name: String): Option[InetAddress] = { - try { - Some(InetAddress.getByName(name)) - } catch { - case _: UnknownHostException => None - } - } - -} - -object Test extends App { - /* PinS, Listing 32.2: An actor that calls receive - */ - def makeEchoActor(): Actor = actor { - while (true) { - receive { - case 'stop => - exit() - case msg => - println("received message: " + msg) - } - } - } - - /* PinS, page 696 - */ - def makeIntActor(): Actor = actor { - receive { - case x: Int => // I only want Ints - println("Got an Int: " + x) - } - } - - actor { - self.trapExit = true - self.link(SillyActor) - SillyActor.start() - react { - case Exit(SillyActor, _) => - self.link(SeriousActor) - SeriousActor.start() - react { - case Exit(SeriousActor, _) => - val seriousPromise2 = Promise[Boolean] - // PinS, page 694 - val seriousActor2 = actor { - for (i <- 1 to 5) - println("That is the question.") - seriousPromise2.success(true) - } - - Await.ready(seriousPromise2.future, 5 seconds) - val echoActor = makeEchoActor() - self.link(echoActor) - echoActor ! "hi there" - echoActor ! 15 - echoActor ! 'stop - react { - case Exit(_, _) => - val intActor = makeIntActor() - intActor ! "hello" - intActor ! math.Pi - // only the following send leads to output - intActor ! 12 - } - } - } - } -} diff --git a/test/files/jvm/actmig-PinS_1.check b/test/files/jvm/actmig-PinS_1.check deleted file mode 100644 index bdbdf8a692..0000000000 --- a/test/files/jvm/actmig-PinS_1.check +++ /dev/null @@ -1,19 +0,0 @@ -I'm acting! -I'm acting! -I'm acting! -I'm acting! -I'm acting! -Post stop -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -That is the question. -That is the question. -That is the question. -That is the question. -That is the question. -received message: hi there -received message: 15 -Got an Int: 12 diff --git a/test/files/jvm/actmig-PinS_1.scala b/test/files/jvm/actmig-PinS_1.scala deleted file mode 100644 index 495852e812..0000000000 --- a/test/files/jvm/actmig-PinS_1.scala +++ /dev/null @@ -1,139 +0,0 @@ -/** - * 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.actors._ -import scala.actors.migration._ -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object SillyActor { - val startPromise = Promise[Boolean]() - val ref = ActorDSL.actor(new SillyActor) -} - -/* PinS, Listing 32.1: A simple actor - */ -class SillyActor extends Actor { - - def act() { - Await.ready(SillyActor.startPromise.future, 5 seconds) - for (i <- 1 to 5) - println("I'm acting!") - - println("Post stop") - } -} - -object SeriousActor { - val startPromise = Promise[Boolean]() - val ref = ActorDSL.actor(new SeriousActor) -} - -class SeriousActor extends Actor { - def act() { - // used to make this test deterministic - Await.ready(SeriousActor.startPromise.future, 5 seconds) - for (i <- 1 to 5) - println("To be or not to be.") - } -} - -/* PinS, Listing 32.3: An actor that calls react - */ -object NameResolver extends Actor { - import java.net.{ InetAddress, UnknownHostException } - - def act() { - react { - case (name: String, actor: Actor) => - actor ! getIp(name) - act() - case "EXIT" => - println("Name resolver exiting.") - // quit - case msg => - println("Unhandled message: " + msg) - act() - } - } - - def getIp(name: String): Option[InetAddress] = { - try { - Some(InetAddress.getByName(name)) - } catch { - case _: UnknownHostException => None - } - } - -} - -object Test extends App { - - /* PinS, Listing 32.2: An actor that calls receive - */ - def makeEchoActor(): ActorRef = ActorDSL.actor(new Actor { - def act() { - while (true) { - receive { - case 'stop => - exit() - case msg => - println("received message: " + msg) - } - } - } - }) - - /* PinS, page 696 - */ - def makeIntActor(): ActorRef = ActorDSL.actor(new Actor { - def act() { - receive { - case x: Int => // I only want Ints - println("Got an Int: " + x) - } - } - }) - - ActorDSL.actor(new Actor { - def act() { - trapExit = true - link(SillyActor.ref) - SillyActor.startPromise.success(true) - react { - case Exit(_: SillyActor, _) => - link(SeriousActor.ref) - SeriousActor.startPromise.success(true) - react { - case Exit(_: SeriousActor, _) => - val seriousPromise2 = Promise[Boolean]() - // PinS, page 694 - val seriousActor2 = ActorDSL.actor( - new Actor { - def act() { - for (i <- 1 to 5) - println("That is the question.") - seriousPromise2.success(true) - } - }) - - Await.ready(seriousPromise2.future, 5 seconds) - val echoActor = makeEchoActor() - link(echoActor) - echoActor ! "hi there" - echoActor ! 15 - echoActor ! 'stop - react { - case Exit(_, _) => - val intActor = makeIntActor() - intActor ! "hello" - intActor ! math.Pi - // only the following send leads to output - intActor ! 12 - } - } - } - } - }) -} diff --git a/test/files/jvm/actmig-PinS_2.check b/test/files/jvm/actmig-PinS_2.check deleted file mode 100644 index bdbdf8a692..0000000000 --- a/test/files/jvm/actmig-PinS_2.check +++ /dev/null @@ -1,19 +0,0 @@ -I'm acting! -I'm acting! -I'm acting! -I'm acting! -I'm acting! -Post stop -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -That is the question. -That is the question. -That is the question. -That is the question. -That is the question. -received message: hi there -received message: 15 -Got an Int: 12 diff --git a/test/files/jvm/actmig-PinS_2.scala b/test/files/jvm/actmig-PinS_2.scala deleted file mode 100644 index 508525463f..0000000000 --- a/test/files/jvm/actmig-PinS_2.scala +++ /dev/null @@ -1,159 +0,0 @@ -/** - * 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.actors._ -import scala.actors.migration._ -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object SillyActor { - val startPromise = Promise[Boolean]() - val ref = ActorDSL.actor(new SillyActor) -} - -/* PinS, Listing 32.1: A simple actor - */ -class SillyActor extends StashingActor { - - def receive = { case _ => println("Nop") } - - override def act() { - Await.ready(SillyActor.startPromise.future, 5 seconds) - for (i <- 1 to 5) - println("I'm acting!") - - println("Post stop") - } -} - -object SeriousActor { - val startPromise = Promise[Boolean]() - val ref = ActorDSL.actor(new SeriousActor) -} - -class SeriousActor extends StashingActor { - def receive = { case _ => println("Nop") } - override def act() { - Await.ready(SeriousActor.startPromise.future, 5 seconds) - for (i <- 1 to 5) - println("To be or not to be.") - } -} - -/* PinS, Listing 32.3: An actor that calls react - */ -object NameResolver { - val ref = ActorDSL.actor(new NameResolver) -} - -class NameResolver extends StashingActor { - import java.net.{ InetAddress, UnknownHostException } - - def receive = { case _ => println("Nop") } - - override def act() { - react { - case (name: String, actor: ActorRef) => - actor ! getIp(name) - act() - case "EXIT" => - println("Name resolver exiting.") - // quit - case msg => - println("Unhandled message: " + msg) - act() - } - } - - def getIp(name: String): Option[InetAddress] = { - try { - Some(InetAddress.getByName(name)) - } catch { - case _: UnknownHostException => None - } - } - -} - -object Test extends App { - - /* PinS, Listing 32.2: An actor that calls receive - */ - def makeEchoActor(): ActorRef = ActorDSL.actor( - new StashingActor { - def receive = { case _ => println("Nop") } - - override def act() { - loop { - react { - case 'stop => - exit() - case msg => - println("received message: " + msg) - } - } - } - }) - - /* PinS, page 696 - */ - def makeIntActor(): ActorRef = ActorDSL.actor(new StashingActor { - - def receive = { case _ => println("Nop") } - - override def act() { - react { - case x: Int => // I only want Ints - println("Got an Int: " + x) - } - } - }) - - ActorDSL.actor(new StashingActor { - - def receive = { case _ => println("Nop") } - - override def act() { - trapExit = true - link(SillyActor.ref) - SillyActor.startPromise.success(true) - react { - case Exit(_: SillyActor, _) => - link(SeriousActor.ref) - SeriousActor.startPromise.success(true) - react { - case Exit(_: SeriousActor, _) => - val seriousPromise2 = Promise[Boolean]() - // PinS, page 694 - val seriousActor2 = ActorDSL.actor( - new StashingActor { - - def receive = { case _ => println("Nop") } - - override def act() { - for (i <- 1 to 5) - println("That is the question.") - seriousPromise2.success(true) - } - }) - - Await.ready(seriousPromise2.future, 5 seconds) - val echoActor = makeEchoActor() - link(echoActor) - echoActor ! "hi there" - echoActor ! 15 - echoActor ! 'stop - react { - case Exit(_, _) => - val intActor = makeIntActor() - intActor ! "hello" - intActor ! math.Pi - // only the following send leads to output - intActor ! 12 - } - } - } - } - }) -} diff --git a/test/files/jvm/actmig-PinS_3.check b/test/files/jvm/actmig-PinS_3.check deleted file mode 100644 index bdbdf8a692..0000000000 --- a/test/files/jvm/actmig-PinS_3.check +++ /dev/null @@ -1,19 +0,0 @@ -I'm acting! -I'm acting! -I'm acting! -I'm acting! -I'm acting! -Post stop -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -To be or not to be. -That is the question. -That is the question. -That is the question. -That is the question. -That is the question. -received message: hi there -received message: 15 -Got an Int: 12 diff --git a/test/files/jvm/actmig-PinS_3.scala b/test/files/jvm/actmig-PinS_3.scala deleted file mode 100644 index 6c6ec6789b..0000000000 --- a/test/files/jvm/actmig-PinS_3.scala +++ /dev/null @@ -1,164 +0,0 @@ -/** - * 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.actors._ -import scala.actors.migration._ -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object SillyActor { - val startPromise = Promise[Boolean]() - val ref = ActorDSL.actor(new SillyActor) -} - -/* PinS, Listing 32.1: A simple actor - */ -class SillyActor extends StashingActor { - def receive = { case _ => println("Why are you not dead"); context.stop(self) } - - override def preStart() { - Await.ready(SillyActor.startPromise.future, 5 seconds) - for (i <- 1 to 5) - println("I'm acting!") - context.stop(self) - } - - override def postStop() { - println("Post stop") - } -} - -object SeriousActor { - val startPromise = Promise[Boolean]() - val ref = ActorDSL.actor(new SeriousActor) -} - -class SeriousActor extends StashingActor { - def receive = { case _ => println("Nop") } - override def preStart() { - Await.ready(SeriousActor.startPromise.future, 5 seconds) - for (i <- 1 to 5) - println("To be or not to be.") - context.stop(self) - } -} - -/* PinS, Listing 32.3: An actor that calls react - */ -object NameResolver { - val ref = ActorDSL.actor(new NameResolver) -} - -class NameResolver extends StashingActor { - import java.net.{ InetAddress, UnknownHostException } - - def receive = { - case (name: String, actor: ActorRef) => - actor ! getIp(name) - case "EXIT" => - println("Name resolver exiting.") - context.stop(self) // quit - case msg => - println("Unhandled message: " + msg) - } - - def getIp(name: String): Option[InetAddress] = { - try { - Some(InetAddress.getByName(name)) - } catch { - case _: UnknownHostException => None - } - } - -} - -object Test extends App { - - /* PinS, Listing 32.2: An actor that calls receive - */ - def makeEchoActor(): ActorRef = ActorDSL.actor(new StashingActor { - - def receive = { // how to handle receive - case 'stop => - context.stop(self) - case msg => - println("received message: " + msg) - } - }) - - /* PinS, page 696 - */ - def makeIntActor(): ActorRef = ActorDSL.actor(new StashingActor { - - def receive = { - case x: Int => // I only want Ints - unstashAll() - println("Got an Int: " + x) - context.stop(self) - case _ => stash() - } - }) - - ActorDSL.actor(new StashingActor { - val silly = SillyActor.ref - - override def preStart() { - context.watch(SillyActor.ref) - SillyActor.startPromise.success(true) - } - - def receive = { - case Terminated(`silly`) => - unstashAll() - val serious = SeriousActor.ref - context.watch(SeriousActor.ref) - SeriousActor.startPromise.success(true) - context.become { - case Terminated(`serious`) => - val seriousPromise2 = Promise[Boolean]() - // PinS, page 694 - val seriousActor2 = ActorDSL.actor( - new StashingActor { - - def receive = { case _ => context.stop(self) } - - override def preStart() = { - for (i <- 1 to 5) - println("That is the question.") - seriousPromise2.success(true) - context.stop(self) - } - }) - - Await.ready(seriousPromise2.future, 5 seconds) - val echoActor = makeEchoActor() - context.watch(echoActor) - echoActor ! "hi there" - echoActor ! 15 - echoActor ! 'stop - context.become { - case Terminated(_) => - unstashAll() - val intActor = makeIntActor() - intActor ! "hello" - intActor ! math.Pi - // only the following send leads to output - intActor ! 12 - context.unbecome() - context.unbecome() - context.stop(self) - case m => - println("Stash 1 " + m) - stash(m) - } - case m => - println("Stash 2 " + m) - stash(m) - } - case m => - println("Stash 3 " + m) - stash(m) - } - }) -} diff --git a/test/files/jvm/actmig-hierarchy.check b/test/files/jvm/actmig-hierarchy.check deleted file mode 100644 index 317e9677c3..0000000000 --- a/test/files/jvm/actmig-hierarchy.check +++ /dev/null @@ -1,2 +0,0 @@ -hello -hello diff --git a/test/files/jvm/actmig-hierarchy.scala b/test/files/jvm/actmig-hierarchy.scala deleted file mode 100644 index 17a44fda7a..0000000000 --- a/test/files/jvm/actmig-hierarchy.scala +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.actors._ - - -class ReactorActor extends Reactor[String] { - def act() { - var cond = true - loopWhile(cond) { - react { - case x if x == "hello1" => println("hello") - case "exit" => cond = false - } - } - } -} - -class ReplyActor extends ReplyReactor { - def act() { - var cond = true - loopWhile(cond) { - react { - case "hello" => println("hello") - case "exit" => cond = false; - } - } - } -} - - -object Test { - - def main(args: Array[String]) { - val reactorActor = new ReactorActor - val replyActor = new ReplyActor - reactorActor.start() - replyActor.start() - - reactorActor ! "hello1" - replyActor ! "hello" - - reactorActor ! "exit" - replyActor ! "exit" - } -}
\ No newline at end of file diff --git a/test/files/jvm/actmig-hierarchy_1.check b/test/files/jvm/actmig-hierarchy_1.check deleted file mode 100644 index 317e9677c3..0000000000 --- a/test/files/jvm/actmig-hierarchy_1.check +++ /dev/null @@ -1,2 +0,0 @@ -hello -hello diff --git a/test/files/jvm/actmig-hierarchy_1.scala b/test/files/jvm/actmig-hierarchy_1.scala deleted file mode 100644 index 14f03c9d48..0000000000 --- a/test/files/jvm/actmig-hierarchy_1.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.actors._ - -class ReactorActor extends Actor { - def act() { - var cond = true - loopWhile(cond) { - react { - case x: String if x == "hello1" => println("hello") - case "exit" => cond = false - } - } - } -} - -class ReplyActor extends Actor { - def act() { - var cond = true - loopWhile(cond) { - react { - case "hello" => println("hello") - case "exit" => cond = false; - } - } - } -} - -object Test { - - def main(args: Array[String]) { - val reactorActor = new ReactorActor - val replyActor = new ReplyActor - reactorActor.start() - replyActor.start() - - reactorActor ! "hello1" - replyActor ! "hello" - - reactorActor ! "exit" - replyActor ! "exit" - } -}
\ No newline at end of file diff --git a/test/files/jvm/actmig-instantiation.check b/test/files/jvm/actmig-instantiation.check deleted file mode 100644 index 08ef979794..0000000000 --- a/test/files/jvm/actmig-instantiation.check +++ /dev/null @@ -1,8 +0,0 @@ -OK error: java.lang.RuntimeException: In order to create a StashingActor one must use the ActorDSL object -OK error: java.lang.RuntimeException: Cannot create more than one actor -0 -100 -200 -300 -400 -500 diff --git a/test/files/jvm/actmig-instantiation.scala b/test/files/jvm/actmig-instantiation.scala deleted file mode 100644 index 2e3ffc3c30..0000000000 --- a/test/files/jvm/actmig-instantiation.scala +++ /dev/null @@ -1,95 +0,0 @@ -/** - * 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.actors.migration._ -import scala.actors.Actor._ -import scala.actors._ -import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.collection.mutable.ArrayBuffer - -class TestStashingActor extends StashingActor { - - def receive = { case v: Int => Test.append(v); Test.latch.countDown() } - -} - -object Test { - val NUMBER_OF_TESTS = 5 - - // used for sorting non-deterministic output - val buff = ArrayBuffer[Int](0) - val latch = new CountDownLatch(NUMBER_OF_TESTS) - val toStop = ArrayBuffer[ActorRef]() - - def append(v: Int) = synchronized { - buff += v - } - - def main(args: Array[String]) = { - // plain scala actor - val a1 = actor { - react { case v: Int => Test.append(v); Test.latch.countDown() } - } - a1 ! 100 - - // simple instantiation - val a2 = ActorDSL.actor(new TestStashingActor) - a2 ! 200 - toStop += a2 - - // actor of with scala actor - val a3 = ActorDSL.actor(actor { - react { case v: Int => Test.append(v); Test.latch.countDown() } - }) - a3 ! 300 - - // using the manifest - val a4 = ActorDSL.actor(new TestStashingActor) - a4 ! 400 - toStop += a4 - - // deterministic part of a test - // creation without actor - try { - val a3 = new TestStashingActor - a3 ! -1 - } catch { - case e: Throwable => println("OK error: " + e) - } - - // actor double creation - try { - val a3 = ActorDSL.actor({ - new TestStashingActor - new TestStashingActor - }) - a3 ! -1 - } catch { - case e: Throwable => println("OK error: " + e) - } - - // actor nesting - try { - val a5 = ActorDSL.actor({ - val a6 = ActorDSL.actor(new TestStashingActor) - toStop += a6 - new TestStashingActor - }) - - a5 ! 500 - toStop += a5 - } catch { - case e: Throwable => println("Should not throw an exception: " + e) - } - - // output - latch.await(5, TimeUnit.SECONDS) - if (latch.getCount() > 0) { - println("Error: Tasks have not finished!!!") - } - - buff.sorted.foreach(println) - toStop.foreach(_ ! PoisonPill) - } -} diff --git a/test/files/jvm/actmig-loop-react.check b/test/files/jvm/actmig-loop-react.check deleted file mode 100644 index 2474cbe71b..0000000000 --- a/test/files/jvm/actmig-loop-react.check +++ /dev/null @@ -1,16 +0,0 @@ -do task -do task -do task -do task -working -scala got exception -working -akka got exception -do task 1 -do string I am a String -do task 42 -after react -do task 1 -do string I am a String -do task 42 -after react diff --git a/test/files/jvm/actmig-loop-react.scala b/test/files/jvm/actmig-loop-react.scala deleted file mode 100644 index c9a3664526..0000000000 --- a/test/files/jvm/actmig-loop-react.scala +++ /dev/null @@ -1,195 +0,0 @@ -/** - * 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.actors.Actor._ -import scala.actors._ -import scala.actors.migration._ -import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.collection.mutable.ArrayBuffer -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object Test { - val finishedLWCR, finishedTNR, finishedEH = Promise[Boolean] - val finishedLWCR1, finishedTNR1, finishedEH1 = Promise[Boolean] - - def testLoopWithConditionReact() = { - // Snippet showing composition of receives - // Loop with Condition Snippet - before - val myActor = actor { - var c = true - loopWhile(c) { - react { - case x: Int => - // do task - println("do task") - if (x == 42) { - c = false - finishedLWCR1.success(true) - } - } - } - } - - myActor.start() - myActor ! 1 - myActor ! 42 - - Await.ready(finishedLWCR1.future, 5 seconds) - - // Loop with Condition Snippet - migrated - val myAkkaActor = ActorDSL.actor(new StashingActor { - - def receive = { - case x: Int => - // do task - println("do task") - if (x == 42) { - finishedLWCR.success(true) - context.stop(self) - } - } - }) - myAkkaActor ! 1 - myAkkaActor ! 42 - } - - def testNestedReact() = { - // Snippet showing composition of receives - // Loop with Condition Snippet - before - val myActor = actor { - var c = true - loopWhile(c) { - react { - case x: Int => - // do task - println("do task " + x) - if (x == 42) { - c = false - } else { - react { - case y: String => - println("do string " + y) - } - } - println("after react") - finishedTNR1.success(true) - } - } - } - myActor.start() - - myActor ! 1 - myActor ! "I am a String" - myActor ! 42 - - Await.ready(finishedTNR1.future, 5 seconds) - - // Loop with Condition Snippet - migrated - val myAkkaActor = ActorDSL.actor(new StashingActor { - - def receive = { - case x: Int => - // do task - println("do task " + x) - if (x == 42) { - println("after react") - finishedTNR.success(true) - context.stop(self) - } else - context.become(({ - case y: String => - println("do string " + y) - }: Receive).andThen(x => { - unstashAll() - context.unbecome() - }).orElse { case x => stash() }) - } - }) - - myAkkaActor ! 1 - myAkkaActor ! "I am a String" - myAkkaActor ! 42 - - } - - def exceptionHandling() = { - // Stashing actor with act and exception handler - val myActor = ActorDSL.actor(new StashingActor { - - def receive = { case _ => println("Dummy method.") } - override def act() = { - loop { - react { - case "fail" => - throw new Exception("failed") - case "work" => - println("working") - case "die" => - finishedEH1.success(true) - exit() - } - } - } - - override def exceptionHandler = { - case x: Exception => println("scala got exception") - } - - }) - - myActor ! "work" - myActor ! "fail" - myActor ! "die" - - Await.ready(finishedEH1.future, 5 seconds) - // Stashing actor in Akka style - val myAkkaActor = ActorDSL.actor(new StashingActor { - def receive = PFCatch({ - case "fail" => - throw new Exception("failed") - case "work" => - println("working") - case "die" => - finishedEH.success(true) - context.stop(self) - }, { case x: Exception => println("akka got exception") }) - }) - - myAkkaActor ! "work" - myAkkaActor ! "fail" - myAkkaActor ! "die" - } - - def main(args: Array[String]): Unit = { - testLoopWithConditionReact() - Await.ready(finishedLWCR.future, 5 seconds) - exceptionHandling() - Await.ready(finishedEH.future, 5 seconds) - testNestedReact() - Await.ready(finishedTNR.future, 5 seconds) - } - -} - -// As per Jim Mcbeath's blog (http://jim-mcbeath.blogspot.com/2008/07/actor-exceptions.html) -class PFCatch(f: PartialFunction[Any, Unit], - handler: PartialFunction[Exception, Unit]) - extends PartialFunction[Any, Unit] { - - def apply(x: Any) = { - try { - f(x) - } catch { - case e: Exception if handler.isDefinedAt(e) => handler(e) - } - } - - def isDefinedAt(x: Any) = f.isDefinedAt(x) -} - -object PFCatch { - def apply(f: PartialFunction[Any, Unit], - handler: PartialFunction[Exception, Unit]) = new PFCatch(f, handler) -} diff --git a/test/files/jvm/actmig-public-methods.check b/test/files/jvm/actmig-public-methods.check deleted file mode 100644 index c861c90e63..0000000000 --- a/test/files/jvm/actmig-public-methods.check +++ /dev/null @@ -1,6 +0,0 @@ -None -Some(bang qmark after 1) -bang -bang bang in the future after 0 -bang qmark after 0 -typed bang bang in the future after 0 diff --git a/test/files/jvm/actmig-public-methods.scala b/test/files/jvm/actmig-public-methods.scala deleted file mode 100644 index 8891c80668..0000000000 --- a/test/files/jvm/actmig-public-methods.scala +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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.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) - } -} diff --git a/test/files/jvm/actmig-public-methods_1.check b/test/files/jvm/actmig-public-methods_1.check deleted file mode 100644 index c861c90e63..0000000000 --- a/test/files/jvm/actmig-public-methods_1.check +++ /dev/null @@ -1,6 +0,0 @@ -None -Some(bang qmark after 1) -bang -bang bang in the future after 0 -bang qmark after 0 -typed bang bang in the future after 0 diff --git a/test/files/jvm/actmig-public-methods_1.scala b/test/files/jvm/actmig-public-methods_1.scala deleted file mode 100644 index db21ab983c..0000000000 --- a/test/files/jvm/actmig-public-methods_1.scala +++ /dev/null @@ -1,104 +0,0 @@ -/** - * 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._ -import scala.util._ -import scala.concurrent._ -import scala.concurrent.duration._ -import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.concurrent.duration._ -import scala.actors.migration.pattern._ -import scala.concurrent.ExecutionContext.Implicits.global - -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 = ActorDSL.actor(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() - } - } - }) - - toStop += respActor - - respActor ! "bang" - - { - val msg = ("bang qmark", 0L) - val res = respActor.?(msg)(Timeout(Duration.Inf)) - append(Await.result(res, Duration.Inf).toString) - latch.countDown() - } - - { - val msg = ("bang qmark", 1L) - val res = respActor.?(msg)(Timeout(5 seconds)) - - val promise = Promise[Option[Any]]() - res.onComplete(v => promise.success(v.toOption)) - append(Await.result(promise.future, Duration.Inf).toString) - - latch.countDown() - } - - { - val msg = ("bang qmark", 5000L) - val res = respActor.?(msg)(Timeout(1 millisecond)) - val promise = Promise[Option[Any]]() - res.onComplete(v => promise.success(v.toOption)) - append(Await.result(promise.future, Duration.Inf).toString) - latch.countDown() - } - - { - val msg = ("bang bang in the future", 0L) - val fut = respActor.?(msg)(Timeout(Duration.Inf)) - append(Await.result(fut, Duration.Inf).toString) - latch.countDown() - } - - { - val handler: PartialFunction[Any, String] = { - case x: String => x - } - - val msg = ("typed bang bang in the future", 0L) - val fut = (respActor.?(msg)(Timeout(Duration.Inf))) - append((Await.result(fut.map(handler), Duration.Inf)).toString) - latch.countDown() - } - - // output - latch.await(10, TimeUnit.SECONDS) - if (latch.getCount() > 0) { - println("Error: Tasks have not finished!!!") - } - - buff.sorted.foreach(println) - toStop.foreach(_ ! PoisonPill) - } -} diff --git a/test/files/jvm/actmig-react-receive.check b/test/files/jvm/actmig-react-receive.check deleted file mode 100644 index cc2a426e68..0000000000 --- a/test/files/jvm/actmig-react-receive.check +++ /dev/null @@ -1,16 +0,0 @@ -do before -do task -do after -do before -do task -do after -do before -do task -do in between -do string -do after -do before -do task -do in between -do string -do after diff --git a/test/files/jvm/actmig-react-receive.scala b/test/files/jvm/actmig-react-receive.scala deleted file mode 100644 index bf70ce0c46..0000000000 --- a/test/files/jvm/actmig-react-receive.scala +++ /dev/null @@ -1,115 +0,0 @@ -/** - * 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.actors.Actor._ -import scala.actors._ -import scala.actors.migration._ -import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.collection.mutable.ArrayBuffer -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object Test { - val finishedRS, finishedRS1, finishedRSC, finishedRSC1 = Promise[Boolean] - def testComposition() = { - // Snippet showing composition of receives - // React Snippet - before - val myActor = actor { - // do before - println("do before") - receive { - case x: Int => - // do task - println("do task") - } - println("do in between") - receive { - case x: String => - // do string now - println("do string") - } - println("do after") - finishedRSC1.success(true) - } - myActor.start() - myActor ! 1 - myActor ! "1" - Await.ready(finishedRSC1.future, 5 seconds) - - // React Snippet - migrated - val myAkkaActor = ActorDSL.actor(new StashingActor { - override def preStart() = { - println("do before") - } - - def receive = ({ - case x: Int => - // do task - println("do task") - }: Receive) andThen { v => - context.become { - case x: String => - //do string - println("do string") - context.stop(self) - } - println("do in between") - } - - override def postStop() = { - println("do after") - finishedRSC.success(true) - } - - }) - myAkkaActor ! 1 - myAkkaActor ! "1" - Await.ready(finishedRSC.future, 5 seconds) - } - - def main(args: Array[String]) = { - // React Snippet - before - val myActor = actor { - // do before - println("do before") - receive { - case x: Int => - // do task - println("do task") - } - println("do after") - finishedRS1.success(true) - } - myActor.start() - myActor ! 1 - - Await.ready(finishedRS1.future, 5 seconds) - - // React Snippet - migrated - val myAkkaActor = ActorDSL.actor(new StashingActor { - override def preStart() = { - println("do before") - } - - def receive = { - case x: Int => - // do task - println("do task") - context.stop(self) - } - - override def postStop() = { - println("do after") - finishedRS.success(true) - } - - }) - myAkkaActor ! 1 - - Await.ready(finishedRS.future, 5 seconds) - // Starting composition test - testComposition() - - } -} diff --git a/test/files/jvm/actmig-react-within.check b/test/files/jvm/actmig-react-within.check deleted file mode 100644 index 57798dbefb..0000000000 --- a/test/files/jvm/actmig-react-within.check +++ /dev/null @@ -1,2 +0,0 @@ -received -received diff --git a/test/files/jvm/actmig-react-within.scala b/test/files/jvm/actmig-react-within.scala deleted file mode 100644 index 3057398cb5..0000000000 --- a/test/files/jvm/actmig-react-within.scala +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.actors.Actor._ -import scala.actors._ -import scala.actors.migration._ -import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.collection.mutable.ArrayBuffer -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object Test { - val finished = Promise[Boolean] - - def testReactWithin() = { - val sActor = actor { - loop { - reactWithin(1) { - case scala.actors.TIMEOUT => - println("received") - exit() - case _ => - println("Should not occur.") - } - } - } - - val myActor = ActorDSL.actor(new StashingActor { - context.setReceiveTimeout(1 millisecond) - def receive = { - case ReceiveTimeout => - println("received") - finished.success(true) - context.stop(self) - case _ => - println("Should not occur.") - } - }) - } - - def main(args: Array[String]) = { - testReactWithin() - Await.ready(finished.future, 5 seconds) - } - -} diff --git a/test/files/jvm/actmig-receive.check b/test/files/jvm/actmig-receive.check deleted file mode 100644 index 30886140e1..0000000000 --- a/test/files/jvm/actmig-receive.check +++ /dev/null @@ -1,27 +0,0 @@ -Original -do before -receive 1 -do in between -receive 1 -do after -Transformed -do before -receive 1 -do in between -receive 1 -do after -Test Loop Receive -Original -do before body -receive 1 -do after receive -do before body -do after receive -after loop -Transformed -do before body -receive 1 -do after receive -do before body -do after receive -after loop diff --git a/test/files/jvm/actmig-receive.scala b/test/files/jvm/actmig-receive.scala deleted file mode 100644 index 308643cf41..0000000000 --- a/test/files/jvm/actmig-receive.scala +++ /dev/null @@ -1,119 +0,0 @@ -/** - * 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.actors.Actor._ -import scala.actors._ -import scala.actors.migration._ -import java.util.concurrent.{ TimeUnit, CountDownLatch } -import scala.collection.mutable.ArrayBuffer -import scala.concurrent.duration._ -import scala.concurrent.{ Promise, Await } - -object Test { - val finishedSingle, finishedSingle1, finishedLoop, finishedLoop1 = Promise[Boolean] - - def testDoubleReceive() = { - println("Original") - // Snippet that shows how to get rid of receive calls in Scala Actors. - // This snippet is used in the Actors Migration Kit. - val myActor = actor { - println("do before") - receive { - case "hello" => - println("receive 1") - } - println("do in between") - receive { - case "hello" => - println("receive 1") - } - println("do after") - finishedSingle.success(true) - } - - myActor ! "hello" - myActor ! "hello" - - Await.ready(finishedSingle.future, 5 seconds) - println("Transformed") - val myActorReact = actor { - println("do before") - react (({ - case "hello" => - println("receive 1") - }: PartialFunction[Any, Unit]).andThen { x => - println("do in between") - react (({ - case "hello" => - println("receive 1") - }: PartialFunction[Any, Unit]).andThen { x => - println("do after") - finishedSingle1.success(true) - }) - }) - } - - myActorReact ! "hello" - myActorReact ! "hello" - - Await.ready(finishedSingle1.future, 5 seconds) - } - - def testLoopReceive() = { - println("Test Loop Receive") - // Snippet that shows how to get rid of receive calls in loops. - // This snippet is used in the Actors Migration Kit. - println("Original") - val myActor = actor { - var c = true - while (c) { - println("do before body") - receive { - case "hello" => - println("receive 1") - case "exit" => - c = false - } - println("do after receive") - } - println("after loop") - finishedLoop.success(true) - } - - myActor ! "hello" - myActor ! "exit" - Await.ready(finishedLoop.future, 5 seconds) - println("Transformed") - - val myActorReact = actor { - var c = true - loopWhile(c) { - println("do before body") - react (({ - case "hello" => - println("receive 1") - case "exit" => - c = false - }: PartialFunction[Any, Unit]).andThen { x => - println("do after receive") - if (c == false) { - println("after loop") - finishedLoop1.success(true) - } - }) - } - } - - myActorReact ! "hello" - myActorReact ! "exit" - - Await.ready(finishedLoop1.future, 5 seconds) - } - - def main(args: Array[String]) = { - testDoubleReceive() - testLoopReceive() - } - -} |