incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1513189 - in /sling/trunk/contrib/extensions/healthcheck: api/src/main/java/org/apache/sling/hc/impl/ api/src/main/java/org/apache/sling/hc/util/ api/src/main/resources/ api/src/test/java/org/apache/sling/hc/util/ it/src/test/java/org/apac...
Date Mon, 12 Aug 2013 16:22:26 GMT
Author: bdelacretaz
Date: Mon Aug 12 16:22:26 2013
New Revision: 1513189

URL: http://svn.apache.org/r1513189
Log:
SLING-2987 - split into several bundles

Added:
    sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckFilter.java
      - copied, changed from r1513181, sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java
    sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckFilterTest.java
    sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/resources/OSGI-INF/
      - copied from r1513181, sling/trunk/contrib/extensions/healthcheck/api/src/main/resources/OSGI-INF/
Removed:
    sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/impl/
    sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java
    sling/trunk/contrib/extensions/healthcheck/api/src/main/resources/
    sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckSelectorTest.java
Modified:
    sling/trunk/contrib/extensions/healthcheck/api/src/test/java/org/apache/sling/hc/util/SimpleConstraintCheckerTest.java
    sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
    sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java

Copied: sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckFilter.java
(from r1513181, sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckFilter.java?p2=sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckFilter.java&p1=sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java&r1=1513181&r2=1513189&rev=1513189&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckSelector.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/api/src/main/java/org/apache/sling/hc/util/HealthCheckFilter.java
Mon Aug 12 16:22:26 2013
@@ -29,13 +29,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** Select from available {@link HealthCheck} services */
-public class HealthCheckSelector {
+public class HealthCheckFilter {
     
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final BundleContext bundleContext;
     public static final String OMIT_PREFIX = "-";
     
-    public HealthCheckSelector(BundleContext bc) {
+    public HealthCheckFilter(BundleContext bc) {
         bundleContext = bc;
     }
     

Modified: sling/trunk/contrib/extensions/healthcheck/api/src/test/java/org/apache/sling/hc/util/SimpleConstraintCheckerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/api/src/test/java/org/apache/sling/hc/util/SimpleConstraintCheckerTest.java?rev=1513189&r1=1513188&r2=1513189&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/api/src/test/java/org/apache/sling/hc/util/SimpleConstraintCheckerTest.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/api/src/test/java/org/apache/sling/hc/util/SimpleConstraintCheckerTest.java
Mon Aug 12 16:22:26 2013
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.sling.hc.impl;
+package org.apache.sling.hc.util;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;

Added: sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckFilterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckFilterTest.java?rev=1513189&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckFilterTest.java
(added)
+++ sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/HealthCheckFilterTest.java
Mon Aug 12 16:22:26 2013
@@ -0,0 +1,228 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.sling.hc.api.Constants;
+import org.apache.sling.hc.api.HealthCheck;
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.util.HealthCheckFilter;
+import org.junit.After;
+import org.junit.Before;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(PaxExam.class)
+public class HealthCheckFilterTest {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private HealthCheckFilter filter;
+
+    @Inject
+    private BundleContext bundleContext;
+
+    private List<TestHealthCheck> testServices = new ArrayList<TestHealthCheck>();
+    private static int instanceCounter = 0;
+
+    class TestHealthCheck implements HealthCheck {
+
+        private final int id;
+        private final ServiceRegistration<?> reg;
+        final String[] tags;
+
+        TestHealthCheck(String... tags) {
+            id = instanceCounter++;
+            this.tags = tags;
+            final Dictionary<String, Object> props = new Hashtable<String, Object>();
+            if (tags != null) {
+                props.put(Constants.HC_TAGS, tags);
+            }
+            props.put(Constants.HC_TAGS, tags);
+            reg = bundleContext.registerService(HealthCheck.class.getName(),
+                    this, props);
+            log.info("Registered {} with {}={}", new Object[] { this,
+                    Constants.HC_TAGS, props.get(Constants.HC_TAGS) });
+        }
+
+        @Override
+        public String toString() {
+            return Arrays.asList(tags).toString();
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            return other instanceof TestHealthCheck
+                    && ((TestHealthCheck) other).id == id;
+        }
+
+        @Override
+        public int hashCode() {
+            return id;
+        }
+
+        @Override
+        public Result execute() {
+            return null;
+        }
+
+        @Override
+        public Map<String, String> getInfo() {
+            return null;
+        }
+
+        void unregister() {
+            reg.unregister();
+        }
+    }
+
+    @Configuration
+    public Option[] config() {
+        return U.config();
+    }
+
+    @Before
+    public void setup() {
+        testServices.add(new TestHealthCheck("foo"));
+        testServices.add(new TestHealthCheck("bar"));
+        testServices.add(new TestHealthCheck("foo", "bar"));
+        testServices.add(new TestHealthCheck("other", "thing"));
+        testServices.add(new TestHealthCheck());
+        filter = new HealthCheckFilter(bundleContext);
+    }
+
+    @After
+    public void cleanup() {
+        for (TestHealthCheck tc : testServices) {
+            tc.unregister();
+        }
+    }
+
+    /**
+     * @param included
+     *            true or false, in the same order as testServices
+     */
+    private void assertServices(List<HealthCheck> s, boolean... included) {
+        final Iterator<TestHealthCheck> it = testServices.iterator();
+        for (boolean inc : included) {
+            final TestHealthCheck thc = it.next();
+            if (inc) {
+                assertTrue("Expecting list of services to include " + thc,
+                        s.contains(thc));
+            } else {
+                assertFalse("Not expecting list of services to include " + thc,
+                        s.contains(thc));
+            }
+        }
+    }
+
+    @Test
+    public void testSelectorService() {
+        assertNotNull("Expecting HealthCheckSelector service to be provided",
+                filter);
+    }
+
+    @Test
+    public void testAllServices() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck();
+        assertServices(s, true, true, true, true, true);
+    }
+
+    @Test
+    public void testEmptyTags() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("", "", "");
+        assertServices(s, true, true, true, true, true);
+    }
+
+    @Test
+    public void testFooTag() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("foo");
+        assertServices(s, true, false, true, false, false);
+    }
+
+    @Test
+    public void testBarTag() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("bar");
+        assertServices(s, false, true, true, false, false);
+    }
+
+    @Test
+    public void testFooAndBar() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("foo", "bar");
+        assertServices(s, false, false, true, false, false);
+    }
+
+    @Test
+    public void testFooMinusBar() {
+        final List<HealthCheck> s = filter
+                .getTaggedHealthCheck("foo", "-bar");
+        assertServices(s, true, false, false, false, false);
+    }
+
+    @Test
+    public void testWhitespace() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck(
+                "\t \n\r foo  \t", "", " \t-bar\n", "");
+        assertServices(s, true, false, false, false, false);
+    }
+
+    @Test
+    public void testOther() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("other");
+        assertServices(s, false, false, false, true, false);
+    }
+
+    @Test
+    public void testMinusOther() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("-other");
+        assertServices(s, true, true, true, false, true);
+    }
+
+    @Test
+    public void testMinusOtherFoo() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("-other",
+                "-foo");
+        assertServices(s, false, true, false, false, true);
+    }
+
+    @Test
+    public void testNoResults() {
+        final List<HealthCheck> s = filter.getTaggedHealthCheck("NOT A TAG");
+        assertTrue("Expecting no services", s.isEmpty());
+    }
+}

Modified: sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java?rev=1513189&r1=1513188&r2=1513189&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/U.java
Mon Aug 12 16:22:26 2013
@@ -53,13 +53,14 @@ public class U {
                     mavenBundle("org.apache.sling", "org.apache.sling.jcr.jcr-wrapper", "2.0.0"),
                     mavenBundle("org.apache.sling", "org.apache.sling.api", "2.4.2"),
                     mavenBundle("org.apache.sling", "org.apache.sling.jcr.api", "2.1.0"),
-                    mavenBundle("org.apache.sling", "org.apache.sling.engine", "2.2.0"),
+                    mavenBundle("org.apache.sling", "org.apache.sling.engine", "2.2.8"),
                     mavenBundle("org.apache.sling", "org.apache.sling.auth.core", "1.1.2"),
                     mavenBundle("org.apache.sling", "org.apache.sling.commons.mime", "2.1.4"),
                     mavenBundle("org.apache.sling", "org.apache.sling.settings", "1.2.2"),
                     mavenBundle("org.apache.sling", "org.apache.sling.launchpad.api", "1.1.0"),
                     mavenBundle("commons-collections", "commons-collections", "3.2.1"),
                     mavenBundle("commons-io", "commons-io", "1.4"),
+                    mavenBundle("commons-fileupload", "commons-fileupload", "1.2.2"),
                     mavenBundle("org.mortbay.jetty", "servlet-api-2.5", "6.1.14")
             )
         );

Modified: sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java?rev=1513189&r1=1513188&r2=1513189&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/webconsole/src/main/java/org/apache/sling/hc/webconsole/impl/HealthCheckWebconsolePlugin.java
Mon Aug 12 16:22:26 2013
@@ -38,7 +38,7 @@ import org.apache.sling.hc.api.Constants
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
 import org.apache.sling.hc.api.ResultLogEntry;
-import org.apache.sling.hc.util.HealthCheckSelector;
+import org.apache.sling.hc.util.HealthCheckFilter;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 
@@ -104,7 +104,7 @@ public class HealthCheckWebconsolePlugin
         
         // Execute health checks only if tags are specified (even if empty)
         if(req.getParameter(PARAM_TAGS) != null) {
-            final List<HealthCheck> checks = new HealthCheckSelector(bundleContext).getTaggedHealthCheck(tags.split(","));
+            final List<HealthCheck> checks = new HealthCheckFilter(bundleContext).getTaggedHealthCheck(tags.split(","));
             final PrintWriter pw = resp.getWriter();
             pw.println("<table class='content healthcheck' cellpadding='0' cellspacing='0'
width='100%'>");
             int total = 0;



Mime
View raw message