sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1649564 - in /sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core: AsyncHealthCheckTest.java U.java
Date Mon, 05 Jan 2015 15:59:18 GMT
Author: bdelacretaz
Date: Mon Jan  5 15:59:18 2015
New Revision: 1649564

URL: http://svn.apache.org/r1649564
Log:
SLING-3501 - prepare for more HealthCheckExecutor testing

Modified:
    sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
    sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java

Modified: sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java?rev=1649564&r1=1649563&r2=1649564&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
(original)
+++ sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/AsyncHealthCheckTest.java
Mon Jan  5 15:59:18 2015
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertTru
 
 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

Modified: sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java?rev=1649564&r1=1649563&r2=1649564&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
(original)
+++ sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
Mon Jan  5 15:59:18 2015
@@ -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.CoreOpt
 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");



Mime
View raw message