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());
}
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());
}
Aggregations