This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hc-it.git

commit 3c1434435831bc249a888d6f52b07b09b6a537f1
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Mon Jan 5 15:59:18 2015 +0000

    SLING-3501 - prepare for more HealthCheckExecutor testing
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1649564 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/hc/it/core/AsyncHealthCheckTest.java     | 18 ++---------------
 src/test/java/org/apache/sling/hc/it/core/U.java   | 23 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git 
a/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java 
b/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
index 38068f1..acbd8c9 100644
--- a/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
+++ b/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.Dictionary;
 import java.util.Hashtable;
-import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -29,7 +28,6 @@ import javax.inject.Inject;
 
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
-import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
 import org.apache.sling.hc.api.execution.HealthCheckExecutor;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -75,20 +73,8 @@ public class AsyncHealthCheckTest {
         final ServiceRegistration reg = 
bundleContext.registerService(HealthCheck.class, hc, props);
         
         try {
-            {
-                // Wait for HC to be registered
-                final long timeout = System.currentTimeMillis() + 10000L;
-                boolean hcFound = false;
-                while(System.currentTimeMillis() < timeout) {
-                    final List<HealthCheckExecutionResult> results = 
executor.execute(id);
-                    if(!results.isEmpty()) {
-                        hcFound = true;
-                        break;
-                    }
-                    Thread.sleep(100L);
-                }
-                assertTrue("Expecting HC to become active", hcFound);
-            }
+            // Wait for HC to be registered
+            U.expectHealthChecks(1, executor, id);
             
             // Now reset the counter and check that HC increments it even if 
we don't
             // use the executor
diff --git a/src/test/java/org/apache/sling/hc/it/core/U.java 
b/src/test/java/org/apache/sling/hc/it/core/U.java
index cb9f445..99dc4ab 100644
--- a/src/test/java/org/apache/sling/hc/it/core/U.java
+++ b/src/test/java/org/apache/sling/hc/it/core/U.java
@@ -17,6 +17,7 @@
  */
 package org.apache.sling.hc.it.core;
 
+import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
@@ -24,10 +25,32 @@ import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import static org.ops4j.pax.exam.CoreOptions.when;
 
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
+import org.apache.sling.hc.api.execution.HealthCheckExecutor;
 import org.ops4j.pax.exam.Option;
 
 /** Test utilities */
 public class U {
+
+    /** Wait until the specified number of health checks are seen by supplied 
executor */
+    static void expectHealthChecks(int howMany, HealthCheckExecutor executor, 
String ... tags) {
+        final long timeout = System.currentTimeMillis() + 10000L;
+        while(System.currentTimeMillis() < timeout) {
+            final List<HealthCheckExecutionResult> results = 
executor.execute(tags);
+            if(results.size() == howMany) {
+                return;
+            }
+            try {
+                Thread.sleep(100L);
+            } catch(InterruptedException iex) {
+                throw new RuntimeException("Unexpected InterruptedException");
+            }
+        }
+        fail("Did not get " + howMany + " health checks with tags " + 
Arrays.asList(tags) + " after " + timeout + " msec");
+    }
     
     static Option[] config() {
         final String coreVersion = System.getProperty("sling.hc.core.version");

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to