Search in sources :

Example 6 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class ExtendedHealthCheckExecutorIT method testSingleExecution.

@Test
public void testSingleExecution() throws Exception {
    final HealthCheckFilter filter = new HealthCheckFilter(bundleContext);
    final ServiceReference[] refs = filter.getHealthCheckServiceReferences(HealthCheckSelector.tags(testTag));
    assertNotNull(refs);
    assertEquals(1, refs.length);
    // The ExtendedHealthCheckExecutor interface is not public, so we cheat
    // to be able to test its implementation
    final Method m = executor.getClass().getMethod("execute", ServiceReference.class);
    final HealthCheckExecutionResult result = (HealthCheckExecutionResult) m.invoke(executor, refs[0]);
    assertEquals(testResult, result.getHealthCheckResult().getStatus());
}
Also used : HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) Method(java.lang.reflect.Method) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 7 with HealthCheckFilter

use of org.apache.sling.hc.util.HealthCheckFilter in project sling by apache.

the class CompositeHealthCheckTest method testCyclicRecursion.

@Test
public void testCyclicRecursion() {
    // three checks, cyclic
    final String[] filterTags = new String[] { "check2" };
    final DummyHcServiceReference hcRef1 = new DummyHcServiceReference("Check 1", new String[] { "check1" }, filterTags);
    final DummyHcServiceReference hcRef2 = new DummyHcServiceReference("Check 2", new String[] { "check2" }, new String[] { "check3" });
    final DummyHcServiceReference hcRef3 = new DummyHcServiceReference("Check 3", new String[] { "check3" }, new String[] { "check1" });
    // test check is hcRef1
    doReturn(hcRef1).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[] { hcRef2 };
                } else if (tags[0].equals("check3")) {
                    result = new ServiceReference[] { hcRef3 };
                } else if (tags[0].equals("check1")) {
                    result = new ServiceReference[] { hcRef1 };
                }
            }
            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)

Aggregations

HealthCheckFilter (org.apache.sling.hc.util.HealthCheckFilter)7 ServiceReference (org.osgi.framework.ServiceReference)5 HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)3 Test (org.junit.Test)3 Activate (org.apache.felix.scr.annotations.Activate)2 Result (org.apache.sling.hc.api.Result)2 HealthCheckSelector (org.apache.sling.hc.api.execution.HealthCheckSelector)2 ExecutionResult (org.apache.sling.hc.core.impl.executor.ExecutionResult)2 Method (java.lang.reflect.Method)1 HealthCheckMetadata (org.apache.sling.hc.util.HealthCheckMetadata)1 Before (org.junit.Before)1