summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2010-03-09 14:03:02 +0000
committerPhilipp Haller <hallerp@gmail.com>2010-03-09 14:03:02 +0000
commitc3d86bfed31856f8b82348ee7fe64e46fd6bd098 (patch)
treedda59709c1dafb55dc75ba1b7acd9d460702f762 /test/files/jvm
parent0708b61d19f1d69f4017d0f4a5778ed805c0922b (diff)
downloadscala-c3d86bfed31856f8b82348ee7fe64e46fd6bd098.tar.gz
scala-c3d86bfed31856f8b82348ee7fe64e46fd6bd098.tar.bz2
scala-c3d86bfed31856f8b82348ee7fe64e46fd6bd098.zip
New attempt at fixing the tests. No review.
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/actor-executor4.check21
-rw-r--r--test/files/jvm/actor-executor4.scala64
-rw-r--r--test/files/jvm/actor-getstate.scala108
3 files changed, 60 insertions, 133 deletions
diff --git a/test/files/jvm/actor-executor4.check b/test/files/jvm/actor-executor4.check
deleted file mode 100644
index da78f45836..0000000000
--- a/test/files/jvm/actor-executor4.check
+++ /dev/null
@@ -1,21 +0,0 @@
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-Two: OK
-One: OK
-One exited
diff --git a/test/files/jvm/actor-executor4.scala b/test/files/jvm/actor-executor4.scala
deleted file mode 100644
index a912d76094..0000000000
--- a/test/files/jvm/actor-executor4.scala
+++ /dev/null
@@ -1,64 +0,0 @@
-import scala.actors.{Actor, Exit}
-import scala.actors.scheduler.ExecutorScheduler
-import java.util.concurrent.Executors
-
-object One extends AdaptedActor {
- def act() {
- Two.start()
- var i = 0
- loopWhile (i < Test.NUM_MSG) {
- i += 1
- Two ! 'MsgForTwo
- react {
- case 'MsgForOne =>
- if (i % (Test.NUM_MSG/10) == 0)
- println("One: OK")
- }
- }
- }
-}
-
-object Two extends AdaptedActor {
- def act() {
- var i = 0
- loopWhile (i < Test.NUM_MSG) {
- i += 1
- react {
- case 'MsgForTwo =>
- if (i % (Test.NUM_MSG/10) == 0)
- println("Two: OK")
- One ! 'MsgForOne
- }
- }
- }
-}
-
-trait AdaptedActor extends Actor {
- override def scheduler =
- Test.scheduler
-}
-
-object Test {
- val NUM_MSG = 100000
-
- val scheduler =
- ExecutorScheduler(
- Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()),
- false)
-
- def main(args: Array[String]) {
- (new AdaptedActor {
- def act() {
- trapExit = true
- link(One)
- One.start()
-
- receive {
- case Exit(from, reason) =>
- println("One exited")
- Test.scheduler.shutdown()
- }
- }
- }).start()
- }
-}
diff --git a/test/files/jvm/actor-getstate.scala b/test/files/jvm/actor-getstate.scala
index 8d2ee0ae3c..a6e15a8721 100644
--- a/test/files/jvm/actor-getstate.scala
+++ b/test/files/jvm/actor-getstate.scala
@@ -1,4 +1,5 @@
import scala.actors.{Reactor, Actor, TIMEOUT}
+import Actor._
object Test {
@@ -7,67 +8,78 @@ object Test {
println("FAIL ["+hint+"]")
}
+ def expectActorState(a: Reactor[T] forSome { type T }, s: Actor.State.Value) {
+ var done = false
+ var i = 0
+ while (!done) {
+ i = i + 1
+ if (i == 10) { // only wait for 2 seconds total
+ println("FAIL ["+a+": expected "+s+"]")
+ done = true
+ }
+
+ Thread.sleep(200)
+ if (a.getState == s) // success
+ done = true
+ }
+ }
+
def main(args: Array[String]) {
- val a = new Reactor[Any] {
- def act() {
- assert(getState == Actor.State.Runnable, "runnable1")
- react {
- case 'go =>
- println("OK")
+ actor {
+ val a = new Reactor[Any] {
+ def act() {
+ assert(getState == Actor.State.Runnable, "runnable1")
+ react {
+ case 'go =>
+ println("OK")
+ }
}
}
- }
- assert(a.getState == Actor.State.New, "new1")
+ expectActorState(a, Actor.State.New)
- a.start()
- Thread.sleep(200)
- assert(a.getState == Actor.State.Suspended, "suspend1")
+ a.start()
+ expectActorState(a, Actor.State.Suspended)
- a ! 'go
- Thread.sleep(200)
- assert(a.getState == Actor.State.Terminated, "terminated1")
+ a ! 'go
+ expectActorState(a, Actor.State.Terminated)
- val b = new Actor {
- def act() {
- assert(getState == Actor.State.Runnable, "runnable2")
- react {
- case 'go =>
- reactWithin(100000) {
- case TIMEOUT =>
- case 'go =>
- receive {
- case 'go =>
- }
- receiveWithin(100000) {
- case TIMEOUT =>
- case 'go =>
- println("OK")
- }
- }
+ val b = new Actor {
+ def act() {
+ assert(getState == Actor.State.Runnable, "runnable2: "+getState)
+ react {
+ case 'go =>
+ reactWithin(100000) {
+ case TIMEOUT =>
+ case 'go =>
+ receive {
+ case 'go =>
+ }
+ receiveWithin(100000) {
+ case TIMEOUT =>
+ case 'go =>
+ println("OK")
+ }
+ }
+ }
}
}
- }
- assert(b.getState == Actor.State.New, "new2")
+ expectActorState(b, Actor.State.New)
- b.start()
- Thread.sleep(200)
- assert(b.getState == Actor.State.Suspended, "suspend2")
+ b.start()
+ expectActorState(b, Actor.State.Suspended)
- b ! 'go
- Thread.sleep(200)
- assert(b.getState == Actor.State.TimedSuspended, "timedsuspend2")
+ b ! 'go
+ expectActorState(b, Actor.State.TimedSuspended)
- b ! 'go
- Thread.sleep(200)
- assert(b.getState == Actor.State.Blocked, "blocked2")
+ b ! 'go
+ expectActorState(b, Actor.State.Blocked)
- b ! 'go
- Thread.sleep(200)
- assert(b.getState == Actor.State.TimedBlocked, "timedblocked2")
+ b ! 'go
+ expectActorState(b, Actor.State.TimedBlocked)
- b ! 'go
- Thread.sleep(200)
- assert(b.getState == Actor.State.Terminated, "terminated2")
+ b ! 'go
+ expectActorState(b, Actor.State.Terminated)
+ }
}
}