diff options
Diffstat (limited to 'test/files/jvm')
-rw-r--r-- | test/files/jvm/future-awaitall-zero.scala | 4 | ||||
-rw-r--r-- | test/files/jvm/reactor-producer-consumer.check | 10 | ||||
-rw-r--r-- | test/files/jvm/reactor-producer-consumer.scala | 75 |
3 files changed, 87 insertions, 2 deletions
diff --git a/test/files/jvm/future-awaitall-zero.scala b/test/files/jvm/future-awaitall-zero.scala index 49c51f2c7e..125670d049 100644 --- a/test/files/jvm/future-awaitall-zero.scala +++ b/test/files/jvm/future-awaitall-zero.scala @@ -3,11 +3,11 @@ import scala.actors.Actor._ object Test { def main(args: Array[String]) { - val ft1 = future { reactWithin(1000) { + val ft1 = future { reactWithin(10000) { case _ => println("FAIL") } } - val ft2 = future { reactWithin(2000) { + val ft2 = future { reactWithin(20000) { case _ => println("FAIL") } } diff --git a/test/files/jvm/reactor-producer-consumer.check b/test/files/jvm/reactor-producer-consumer.check new file mode 100644 index 0000000000..d971cea19e --- /dev/null +++ b/test/files/jvm/reactor-producer-consumer.check @@ -0,0 +1,10 @@ +42 +42 +42 +42 +42 +42 +42 +42 +42 +42 diff --git a/test/files/jvm/reactor-producer-consumer.scala b/test/files/jvm/reactor-producer-consumer.scala new file mode 100644 index 0000000000..946e1561ce --- /dev/null +++ b/test/files/jvm/reactor-producer-consumer.scala @@ -0,0 +1,75 @@ +import scala.actors.Reactor + +object Test { + case class Stop() + case class Get(from: Reactor) + case class Put(x: Int) + + class UnboundedBuffer extends Reactor { + def act() { + react { + case Stop() => + case Get(from) => + val consumer = from + react { + case msg @ Put(x) => + consumer ! x + act() + } + } + } + } + + class Producer(buf: UnboundedBuffer, n: Int, delay: Long, parent: Reactor) extends Reactor { + def act() { + var i = 0 + while (i < n) { + i += 1 + if (delay > 0) Thread.sleep(delay) + buf ! Put(42) + } + parent ! Stop() + } + } + + class Consumer(buf: UnboundedBuffer, n: Int, delay: Long, parent: Reactor) extends Reactor { + val step = n / 10 + var i = 0 + def act() { + if (i < n) { + i += 1 + if (delay > 0) Thread.sleep(delay) + buf ! Get(this) + react { + case res => + if (i % step == 0) + println(res) + act() + } + } else { + parent ! Stop() + } + } + } + + def main(args: Array[String]) { + val parent = new Reactor { + def act() { + val buffer = new UnboundedBuffer + buffer.start() + val producer = new Producer(buffer, 10000, 0, this) + producer.start() + val consumer = new Consumer(buffer, 10000, 0, this) + consumer.start() + react { + case Stop() => + react { + case Stop() => + buffer ! Stop() + } + } + } + } + parent.start() + } +} |