sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1649570 - in /sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core: HealthCheckExecutorSelectionTest.java U.java
Date Mon, 05 Jan 2015 16:20:44 GMT
Author: bdelacretaz
Date: Mon Jan  5 16:20:43 2015
New Revision: 1649570

URL: http://svn.apache.org/r1649570
Log:
SLING-3501 - HealthCheckExecutorSelectionTest added

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

Added: sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckExecutorSelectionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckExecutorSelectionTest.java?rev=1649570&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckExecutorSelectionTest.java
(added)
+++ sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckExecutorSelectionTest.java
Mon Jan  5 16:20:43 2015
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.hc.it.core;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.UUID;
+
+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.HealthCheckExecutor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/** Test the HealthCheckExecutor selection mechanism */
+@RunWith(PaxExam.class)
+public class HealthCheckExecutorSelectionTest {
+
+    @Inject
+    private HealthCheckExecutor executor;
+    
+    @Inject
+    private BundleContext bundleContext;
+    
+    private static String idA;
+    private static String idB;
+    
+    @SuppressWarnings("rawtypes")
+    private List<ServiceRegistration> regs = new ArrayList<ServiceRegistration>();
+
+    @Configuration
+    public Option[] config() {
+        return U.config();
+    }
+    
+    private void registerHC(final String id) {
+        final HealthCheck hc = new HealthCheck() {
+            @Override
+            public Result execute() {
+                return new Result(Result.Status.OK, "All good for " + id);
+            }
+            
+        };
+        
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(HealthCheck.NAME, "name_" + id);
+        props.put(HealthCheck.TAGS, id);
+        
+        regs.add(bundleContext.registerService(HealthCheck.class, hc, props));
+    }
+
+    @BeforeClass
+    public static void setId() {
+        idA = UUID.randomUUID().toString();
+        idB = UUID.randomUUID().toString();
+    }
+    
+    @Before
+    public void setup() {
+        U.expectHealthChecks(0, executor, idA);
+        U.expectHealthChecks(0, executor, idB);
+        
+        registerHC(idA);
+        registerHC(idB);
+        registerHC(idB);
+        registerHC(idB);
+    }
+    
+    @After
+    @SuppressWarnings("rawtypes")
+    public void cleanup() {
+        for(ServiceRegistration r : regs) {
+            r.unregister();
+        }
+        regs.clear();
+        
+        U.expectHealthChecks(0, executor, idA);
+        U.expectHealthChecks(0, executor, idB);
+    }
+
+    @Test
+    public void testDefaultSelectionA(){
+        U.expectHealthChecks(1, executor, idA);
+    }
+    
+    @Test
+    public void testDefaultSelectionB(){
+        U.expectHealthChecks(3, executor, idB);
+    }
+    @Test
+    public void testDefaultSelectionAandB(){
+        U.expectHealthChecks(0, executor, idA, idB);
+    }
+}

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=1649570&r1=1649569&r2=1649570&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 16:20:43 2015
@@ -38,9 +38,11 @@ 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;
+        int count = 0;
         while(System.currentTimeMillis() < timeout) {
             final List<HealthCheckExecutionResult> results = executor.execute(tags);
-            if(results.size() == howMany) {
+            count = results.size();
+            if(count== howMany) {
                 return;
             }
             try {
@@ -49,7 +51,7 @@ public class U {
                 throw new RuntimeException("Unexpected InterruptedException");
             }
         }
-        fail("Did not get " + howMany + " health checks with tags " + Arrays.asList(tags)
+ " after " + timeout + " msec");
+        fail("Did not get " + howMany + " health checks with tags " + Arrays.asList(tags)
+ " after " + timeout + " msec (last count=" + count + ")");
     }
     
     static Option[] config() {



Mime
View raw message