SLING-3501 - prepare for more HealthCheckExecutor testing
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1649564 13f79535-47bb-0310-9956-ffa450edef68
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 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 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 @@
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.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");