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