summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2010-03-04 11:40:16 +0000
committerPhilipp Haller <hallerp@gmail.com>2010-03-04 11:40:16 +0000
commitacf89aafe568f76a44ddb0e44ca91f8180d1d825 (patch)
tree3be5818b97dcc2f6930a5dc084864c8f14d08465 /test/files/jvm
parent66509d1f6847c8fa4785bcdfa9bce8f5586e1a0e (diff)
downloadscala-acf89aafe568f76a44ddb0e44ca91f8180d1d825.tar.gz
scala-acf89aafe568f76a44ddb0e44ca91f8180d1d825.tar.bz2
scala-acf89aafe568f76a44ddb0e44ca91f8180d1d825.zip
Clean-ups in scheduler hierarchy.
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/actor-executor.check20
-rw-r--r--test/files/jvm/actor-executor.scala59
-rw-r--r--test/files/jvm/actor-executor2.check21
-rw-r--r--test/files/jvm/actor-executor2.scala67
-rw-r--r--test/files/jvm/actor-executor3.check20
-rw-r--r--test/files/jvm/actor-executor3.scala52
-rw-r--r--test/files/jvm/actor-executor4.check21
-rw-r--r--test/files/jvm/actor-executor4.scala64
-rw-r--r--test/files/jvm/reactor.scala2
9 files changed, 325 insertions, 1 deletions
diff --git a/test/files/jvm/actor-executor.check b/test/files/jvm/actor-executor.check
new file mode 100644
index 0000000000..bdbdb5c6a2
--- /dev/null
+++ b/test/files/jvm/actor-executor.check
@@ -0,0 +1,20 @@
+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
diff --git a/test/files/jvm/actor-executor.scala b/test/files/jvm/actor-executor.scala
new file mode 100644
index 0000000000..e650043382
--- /dev/null
+++ b/test/files/jvm/actor-executor.scala
@@ -0,0 +1,59 @@
+import java.util.concurrent.Executors
+import scala.actors.{Actor, SchedulerAdapter}
+import Actor._
+
+trait AdaptedActor extends Actor {
+ override def scheduler =
+ Test.scheduler
+}
+
+object One extends AdaptedActor {
+ def act() {
+ Two.start()
+ var i = 0
+ loopWhile (i < 10000) {
+ i += 1
+ Two ! 'MsgForTwo
+ react {
+ case 'MsgForOne =>
+ if (i % 1000 == 0)
+ println("One: OK")
+ if (i == 10000)
+ Test.executor.shutdown()
+ }
+ }
+ }
+}
+
+object Two extends AdaptedActor {
+ def act() {
+ var i = 0
+ loopWhile (i < 10000) {
+ i += 1
+ react {
+ case 'MsgForTwo =>
+ if (i % 1000 == 0)
+ println("Two: OK")
+ One ! 'MsgForOne
+ }
+ }
+ }
+}
+
+object Test {
+ val executor =
+ Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
+
+ val scheduler =
+ new SchedulerAdapter {
+ def execute(block: => Unit) {
+ executor.execute(new Runnable {
+ def run() { block }
+ })
+ }
+ }
+
+ def main(args: Array[String]) {
+ One.start()
+ }
+}
diff --git a/test/files/jvm/actor-executor2.check b/test/files/jvm/actor-executor2.check
new file mode 100644
index 0000000000..da78f45836
--- /dev/null
+++ b/test/files/jvm/actor-executor2.check
@@ -0,0 +1,21 @@
+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-executor2.scala b/test/files/jvm/actor-executor2.scala
new file mode 100644
index 0000000000..9e99e167aa
--- /dev/null
+++ b/test/files/jvm/actor-executor2.scala
@@ -0,0 +1,67 @@
+import scala.actors.{Actor, SchedulerAdapter, Exit}
+import Actor._
+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 executor =
+ Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
+
+ val scheduler =
+ new SchedulerAdapter {
+ def execute(block: => Unit) {
+ executor.execute(new Runnable {
+ def run() { block }
+ })
+ }
+ }
+
+ def main(args: Array[String]) {
+ self.trapExit = true
+ link(One)
+ One.start()
+
+ receive {
+ case Exit(from, reason) =>
+ println("One exited")
+ Test.executor.shutdown()
+ }
+ }
+}
diff --git a/test/files/jvm/actor-executor3.check b/test/files/jvm/actor-executor3.check
new file mode 100644
index 0000000000..bdbdb5c6a2
--- /dev/null
+++ b/test/files/jvm/actor-executor3.check
@@ -0,0 +1,20 @@
+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
diff --git a/test/files/jvm/actor-executor3.scala b/test/files/jvm/actor-executor3.scala
new file mode 100644
index 0000000000..bf060b8ac5
--- /dev/null
+++ b/test/files/jvm/actor-executor3.scala
@@ -0,0 +1,52 @@
+import scala.actors.Actor
+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 executor =
+ Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
+
+ val scheduler = ExecutorScheduler(executor)
+
+ def main(args: Array[String]) {
+ One.start()
+ }
+}
diff --git a/test/files/jvm/actor-executor4.check b/test/files/jvm/actor-executor4.check
new file mode 100644
index 0000000000..da78f45836
--- /dev/null
+++ b/test/files/jvm/actor-executor4.check
@@ -0,0 +1,21 @@
+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
new file mode 100644
index 0000000000..a912d76094
--- /dev/null
+++ b/test/files/jvm/actor-executor4.scala
@@ -0,0 +1,64 @@
+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/reactor.scala b/test/files/jvm/reactor.scala
index 2fc54d8344..919263b65a 100644
--- a/test/files/jvm/reactor.scala
+++ b/test/files/jvm/reactor.scala
@@ -6,7 +6,7 @@ case object Pong
case object Stop
/**
- * Ping pong example for OutputChannelActor.
+ * Ping pong example for Reactor.
*
* @author Philipp Haller
*/