From 8c23908ebb28540e89d3eec8ef699d6af55c3d55 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Sun, 31 May 2009 13:20:43 +0000 Subject: New tests for exceptions and Actor.receiveWithin. --- test/files/jvm/actor-receivewithin.check | 16 +++++++ test/files/jvm/actor-receivewithin.scala | 67 ++++++++++++++++++++++++++++ test/files/jvm/outputchannelactor.scala | 8 ++-- test/files/jvm/reactor-exceptionOnSend.check | 2 + test/files/jvm/reactor-exceptionOnSend.scala | 44 ++++++++++++++++++ 5 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 test/files/jvm/actor-receivewithin.check create mode 100644 test/files/jvm/actor-receivewithin.scala create mode 100644 test/files/jvm/reactor-exceptionOnSend.check create mode 100644 test/files/jvm/reactor-exceptionOnSend.scala (limited to 'test/files/jvm') diff --git a/test/files/jvm/actor-receivewithin.check b/test/files/jvm/actor-receivewithin.check new file mode 100644 index 0000000000..a6a3e88c61 --- /dev/null +++ b/test/files/jvm/actor-receivewithin.check @@ -0,0 +1,16 @@ +'msg +'msg +'msg +'msg +'msg +TIMEOUT +TIMEOUT +TIMEOUT +TIMEOUT +TIMEOUT +'msg2 +'msg2 +'msg2 +'msg2 +'msg2 +TIMEOUT diff --git a/test/files/jvm/actor-receivewithin.scala b/test/files/jvm/actor-receivewithin.scala new file mode 100644 index 0000000000..c6818cf211 --- /dev/null +++ b/test/files/jvm/actor-receivewithin.scala @@ -0,0 +1,67 @@ +import scala.actors.{Actor, TIMEOUT} + +object A extends Actor { + def act() { + receive { + case 'done => + var cnt = 0 + while (cnt < 500) { + cnt += 1 + receiveWithin (0) { + case 'msg => + if (cnt % 100 == 0) + println("'msg") + case TIMEOUT => + // should not happen + println("FAIL1") + } + } + cnt = 0 + while (cnt < 500) { + cnt += 1 + receiveWithin (0) { + case 'msg => + // should not happen + println("FAIL2") + case TIMEOUT => + if (cnt % 100 == 0) + println("TIMEOUT") + } + } + B ! 'next + cnt = 0 + while (cnt < 501) { + cnt += 1 + receiveWithin (500) { + case 'msg2 => + if (cnt % 100 == 0) + println("'msg2") + case TIMEOUT => + println("TIMEOUT") + } + } + } + } +} + +object B extends Actor { + def act() { + A.start() + for (_ <- 1 to 500) { + A ! 'msg + } + A ! 'done + receive { + case 'next => + for (_ <- 1 to 500) { + A ! 'msg2 + } + } + } +} + +object Test { + def main(args:Array[String]) { + B.start() + } +} diff --git a/test/files/jvm/outputchannelactor.scala b/test/files/jvm/outputchannelactor.scala index 6a982b7a94..d8970c4231 100644 --- a/test/files/jvm/outputchannelactor.scala +++ b/test/files/jvm/outputchannelactor.scala @@ -1,8 +1,8 @@ -import scala.actors.OutputChannelActor +import scala.actors.Reactor import scala.actors.Actor._ -case class Ping(from: OutputChannelActor) +case class Ping(from: Reactor) case object Pong case object Stop @@ -20,7 +20,7 @@ object Test { } } -class PingActor(count: Int, pong: OutputChannelActor) extends OutputChannelActor { +class PingActor(count: Int, pong: Reactor) extends Reactor { ignoreSender = true def act() { var pingsLeft = count - 1 @@ -43,7 +43,7 @@ class PingActor(count: Int, pong: OutputChannelActor) extends OutputChannelActor } } -class PongActor extends OutputChannelActor { +class PongActor extends Reactor { ignoreSender = true def act() { var pongCount = 0 diff --git a/test/files/jvm/reactor-exceptionOnSend.check b/test/files/jvm/reactor-exceptionOnSend.check new file mode 100644 index 0000000000..45d62e26a7 --- /dev/null +++ b/test/files/jvm/reactor-exceptionOnSend.check @@ -0,0 +1,2 @@ +receiver handles exception +process diff --git a/test/files/jvm/reactor-exceptionOnSend.scala b/test/files/jvm/reactor-exceptionOnSend.scala new file mode 100644 index 0000000000..3684943b9b --- /dev/null +++ b/test/files/jvm/reactor-exceptionOnSend.scala @@ -0,0 +1,44 @@ +import scala.actors.Reactor +import scala.actors.Actor._ + +case class MyException(text: String) extends Exception(text) + +object A extends Reactor { + override def exceptionHandler = { + case MyException(text) => + println("receiver handles exception") + } + + def guard(): Boolean = + if (state == 0) { + state = 1 + throw MyException("illegal state") + } else + true + + var state = 0 + + def act() { + loop { + react { + case 'hello if guard() => + println("process") + exit() + } + } + } +} + +object B extends Reactor { + def act() { + A.start() + A ! 'hello + A ! 'hello + } +} + +object Test { + def main(args: Array[String]) { + B.start() + } +} -- cgit v1.2.3