summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-05-31 13:20:43 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-05-31 13:20:43 +0000
commit8c23908ebb28540e89d3eec8ef699d6af55c3d55 (patch)
treec85f2c566330a996b940e16a2013530952fba9c9
parent63031aa7f0f1f32c7b998d118c832cb181b4e99e (diff)
downloadscala-8c23908ebb28540e89d3eec8ef699d6af55c3d55.tar.gz
scala-8c23908ebb28540e89d3eec8ef699d6af55c3d55.tar.bz2
scala-8c23908ebb28540e89d3eec8ef699d6af55c3d55.zip
New tests for exceptions and Actor.receiveWithin.
-rw-r--r--test/files/jvm/actor-receivewithin.check16
-rw-r--r--test/files/jvm/actor-receivewithin.scala67
-rw-r--r--test/files/jvm/outputchannelactor.scala8
-rw-r--r--test/files/jvm/reactor-exceptionOnSend.check2
-rw-r--r--test/files/jvm/reactor-exceptionOnSend.scala44
5 files changed, 133 insertions, 4 deletions
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()
+ }
+}