use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class HealthCheckTestsProviderTest method getMockReferences.
/** Return ServiceReferences that point to our test HealthChecks */
private ServiceReference[] getMockReferences(BundleContext bc, String OSGiFilter) {
final List<ServiceReference> refs = new ArrayList<ServiceReference>();
for (String key : LOG_SETTERS.keySet()) {
if (OSGiFilter.contains(key)) {
final HcLogSetter hls = LOG_SETTERS.get(key);
final ServiceReference ref = Mockito.mock(ServiceReference.class);
Mockito.when(ref.getProperty(Constants.SERVICE_ID)).thenReturn(random.nextLong());
Mockito.when(ref.getProperty(HealthCheck.NAME)).thenReturn("someTest");
final HealthCheck hc = new HealthCheck() {
@Override
public Result execute() {
final FormattingResultLog log = new FormattingResultLog();
return new Result(hls.setLog(log));
}
};
Mockito.when(bc.getService(ref)).thenReturn(hc);
refs.add(ref);
}
}
return refs.toArray(new ServiceReference[] {});
}
use of org.apache.sling.hc.util.FormattingResultLog in project sling by apache.
the class AsyncHealthCheckSample method execute.
@Override
public Result execute() {
final long toWait = (long) (Math.random() * 2 * PERIOD_SECONDS);
log.info("{} - Waiting {} seconds to simulate an expensive operation...", this, toWait);
try {
Thread.sleep(toWait * 1000L);
} catch (InterruptedException iex) {
log.warn("Sleep interrupted", iex);
}
final int value = counter.incrementAndGet();
log.info("{} - counter set to {}", this, value);
final FormattingResultLog resultLog = new FormattingResultLog();
resultLog.info("{} - counter value set to {} at {}", this, value, new Date());
if (value % 2 != 0) {
resultLog.warn("Counter value ({}) is not even", value);
}
return new Result(resultLog);
}
Aggregations