From 22cf40a97142484bb6b9f5d75bdcf1e6d42c6407 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Mon, 9 Aug 2010 23:08:22 +0200 Subject: [PATCH] Closing ticket #372, added tests --- .../src/test/scala/misc/SchedulerSpec.scala | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/akka-core/src/test/scala/misc/SchedulerSpec.scala b/akka-core/src/test/scala/misc/SchedulerSpec.scala index 1cedb27354..e1219d708a 100644 --- a/akka-core/src/test/scala/misc/SchedulerSpec.scala +++ b/akka-core/src/test/scala/misc/SchedulerSpec.scala @@ -44,6 +44,39 @@ class SchedulerSpec extends JUnitSuite { // should still be 1 left assert(countDownLatch.getCount == 1) } + + /** + * ticket #372 + */ + @Test def schedulerShouldntCreateActors = withCleanEndState { + object Ping + val ticks = new CountDownLatch(1000) + val actor = actorOf(new Actor { + def receive = { case Ping => ticks.countDown } + }).start + val numActors = ActorRegistry.actors.length + (1 to 1000).foreach( _ => Scheduler.scheduleOnce(actor,Ping,1,TimeUnit.MILLISECONDS) ) + assert(ticks.await(10,TimeUnit.SECONDS)) + assert(ActorRegistry.actors.length === numActors) + } + + /** + * ticket #372 + */ + @Test def schedulerShouldBeCancellable = withCleanEndState { + object Ping + val ticks = new CountDownLatch(1) + + val actor = actorOf(new Actor { + def receive = { case Ping => ticks.countDown } + }).start + + (1 to 10).foreach { i => + val future = Scheduler.scheduleOnce(actor,Ping,1,TimeUnit.SECONDS) + future.cancel(true) + } + assert(ticks.await(3,TimeUnit.SECONDS) == false) //No counting down should've been made + } /** * ticket #307