You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by dr...@apache.org on 2011/09/18 13:55:07 UTC

svn commit: r1172261 - /tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy

Author: drobiazko
Date: Sun Sep 18 11:55:07 2011
New Revision: 1172261

URL: http://svn.apache.org/viewvc?rev=1172261&view=rev
Log:
Refactored PeriodicExecutorTests to use CountDownLatch instead of pausing the test's thread.

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy?rev=1172261&r1=1172260&r2=1172261&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/PeriodicExecutorTests.groovy Sun Sep 18 11:55:07 2011
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry.ioc.services
 
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit
 import org.apache.tapestry5.ioc.Registry
 import org.apache.tapestry5.ioc.services.cron.IntervalSchedule
 import org.apache.tapestry5.ioc.services.cron.PeriodicExecutor
@@ -32,16 +34,15 @@ class PeriodicExecutorTests extends IOCT
     {
         Registry r = buildRegistry()
 
-        int count = 0
+        def countDownLatch = new CountDownLatch(5);
 
         def schedule = new IntervalSchedule(10)
 
-        PeriodicJob job = r.getService(PeriodicExecutor.class).addJob(schedule, "count incrementer", { count++; })
+        PeriodicJob job = r.getService(PeriodicExecutor.class).addJob(schedule, "count incrementer", { countDownLatch.countDown(); })
 
-        while (count < 10)
-        {
-            sleep 10
-        }
+        countDownLatch.await 30, TimeUnit.SECONDS
+
+        assertEquals countDownLatch.getCount(), 0
 
         job.cancel()