Search in sources :

Example 6 with HealthCheckSelector

use of org.apache.sling.hc.api.execution.HealthCheckSelector in project sling by apache.

the class HealthCheckFilterTest method testWithTwoAndTagsAndTwoNames.

@Test
public void testWithTwoAndTagsAndTwoNames() {
    HealthCheckSelector selector = empty().withNames("foo", "bar").withTags("t1", "t2");
    assertStrEquals("(&(objectClass=org.apache.sling.hc.api.HealthCheck)(|(hc.name=foo)(hc.name=bar)(&(hc.tags=t1)(hc.tags=t2))))", filter.getServiceFilter(selector, false));
}
Also used : HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) Test(org.junit.Test)

Example 7 with HealthCheckSelector

use of org.apache.sling.hc.api.execution.HealthCheckSelector in project sling by apache.

the class HealthCheckFilterTest method testWithTagAndName.

@Test
public void testWithTagAndName() {
    HealthCheckSelector selector = empty().withTags("t1").withNames("foo");
    assertStrEquals("(&(objectClass=org.apache.sling.hc.api.HealthCheck)(|(hc.name=foo)(hc.tags=t1)))", filter.getServiceFilter(selector, false));
}
Also used : HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) Test(org.junit.Test)

Example 8 with HealthCheckSelector

use of org.apache.sling.hc.api.execution.HealthCheckSelector in project sling by apache.

the class HealthCheckFilterTest method testWithTwoTagsOr.

@Test
public void testWithTwoTagsOr() {
    HealthCheckSelector selector = tags("foo", "bar");
    assertStrEquals("(&(objectClass=org.apache.sling.hc.api.HealthCheck)(|(hc.tags=foo)(hc.tags=bar)))", filter.getServiceFilter(selector, true));
}
Also used : HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) Test(org.junit.Test)

Example 9 with HealthCheckSelector

use of org.apache.sling.hc.api.execution.HealthCheckSelector in project sling by apache.

the class CompositeHealthCheckTest method testSimpleRecursion.

@Test
public void testSimpleRecursion() {
    // composite check referencing itself
    final String[] filterTags = new String[] { "check1" };
    final DummyHcServiceReference hcRef = new DummyHcServiceReference("Check 1", new String[] { "check1" }, filterTags);
    // test check is hcRef
    doReturn(hcRef).when(componentContext).getServiceReference();
    compositeHealthCheck.setFilterTags(filterTags);
    compositeHealthCheck.setHealthCheckFilter(new HealthCheckFilter(null) {

        @Override
        public ServiceReference[] getHealthCheckServiceReferences(HealthCheckSelector selector) {
            String[] tags = selector.tags();
            ServiceReference[] result = new ServiceReference[] {};
            if (tags.length > 0) {
                if (tags[0].equals(filterTags[0])) {
                    result = new ServiceReference[] { hcRef };
                }
            }
            return result;
        }
    });
    Result result = compositeHealthCheck.execute();
    verify(healthCheckExecutor, never()).execute(any(HealthCheckSelector.class));
    assertEquals(Result.Status.HEALTH_CHECK_ERROR, result.getStatus());
}
Also used : HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) ServiceReference(org.osgi.framework.ServiceReference) ExecutionResult(org.apache.sling.hc.core.impl.executor.ExecutionResult) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Example 10 with HealthCheckSelector

use of org.apache.sling.hc.api.execution.HealthCheckSelector in project sling by apache.

the class HealthCheckMBeanTest method testBean.

@Test
public void testBean() throws Exception {
    final ServiceReference ref = new ServiceReference() {

        @Override
        public boolean isAssignableTo(Bundle bundle, String className) {
            return false;
        }

        @Override
        public Bundle[] getUsingBundles() {
            return null;
        }

        @Override
        public String[] getPropertyKeys() {
            return null;
        }

        @Override
        public Object getProperty(String key) {
            return null;
        }

        @Override
        public Bundle getBundle() {
            return null;
        }

        @Override
        public int compareTo(Object reference) {
            return 0;
        }
    };
    final HealthCheckMBean mbean = new HealthCheckMBean(ref, new ExtendedHealthCheckExecutor() {

        @SuppressWarnings("deprecation")
        @Override
        public List<HealthCheckExecutionResult> execute(String... tags) {
            return null;
        }

        @Override
        public HealthCheckExecutionResult execute(ServiceReference ref) {
            // TODO Auto-generated method stub
            return new HealthCheckExecutionResult() {

                @Override
                public Result getHealthCheckResult() {
                    // TODO Auto-generated method stub
                    return testHealthCheck.execute();
                }

                @Override
                public HealthCheckMetadata getHealthCheckMetadata() {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public Date getFinishedAt() {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public long getElapsedTimeInMs() {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public boolean hasTimedOut() {
                    // TODO Auto-generated method stub
                    return false;
                }
            };
        }

        @SuppressWarnings("deprecation")
        @Override
        public List<HealthCheckExecutionResult> execute(HealthCheckExecutionOptions options, String... tags) {
            return null;
        }

        @Override
        public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector) {
            return null;
        }

        @Override
        public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector, HealthCheckExecutionOptions options) {
            return null;
        }
    });
    final ObjectName name = new ObjectName(OBJECT_NAME);
    jmxServer.registerMBean(mbean, name);
    try {
        resultOk = true;
        assertJmxValue(OBJECT_NAME, "ok", "true", true);
        Thread.sleep(1500);
        resultOk = false;
        assertJmxValue(OBJECT_NAME, "ok", "true", false);
        Thread.sleep(1500);
        assertJmxValue(OBJECT_NAME, "log", "contains message=Result is not ok!", true);
    } finally {
        jmxServer.unregisterMBean(name);
    }
}
Also used : HealthCheckMetadata(org.apache.sling.hc.util.HealthCheckMetadata) Bundle(org.osgi.framework.Bundle) ExtendedHealthCheckExecutor(org.apache.sling.hc.core.impl.executor.ExtendedHealthCheckExecutor) Date(java.util.Date) ServiceReference(org.osgi.framework.ServiceReference) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) ObjectName(javax.management.ObjectName) HealthCheckSelector(org.apache.sling.hc.api.execution.HealthCheckSelector) HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) List(java.util.List) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Aggregations

HealthCheckSelector (org.apache.sling.hc.api.execution.HealthCheckSelector)14 Test (org.junit.Test)13 Result (org.apache.sling.hc.api.Result)4 HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)4 ServiceReference (org.osgi.framework.ServiceReference)3 HealthCheckExecutionOptions (org.apache.sling.hc.api.execution.HealthCheckExecutionOptions)2 ExecutionResult (org.apache.sling.hc.core.impl.executor.ExecutionResult)2 HealthCheckFilter (org.apache.sling.hc.util.HealthCheckFilter)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 ObjectName (javax.management.ObjectName)1 Status (org.apache.sling.hc.api.Result.Status)1 ExtendedHealthCheckExecutor (org.apache.sling.hc.core.impl.executor.ExtendedHealthCheckExecutor)1 HealthCheckMetadata (org.apache.sling.hc.util.HealthCheckMetadata)1 Bundle (org.osgi.framework.Bundle)1