use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorServletTest method testDoGetNameAndTagInPath.
@Test
public void testDoGetNameAndTagInPath() throws ServletException, IOException {
final String testTag = "testTag";
final String testName = "test name";
doReturn(testTag + "," + testName).when(request).getPathInfo();
doReturn("false").when(request).getParameter(HealthCheckExecutorServlet.PARAM_COMBINE_TAGS_WITH_OR.name);
final List<HealthCheckExecutionResult> executionResults = getExecutionResults(Result.Status.CRITICAL);
doReturn(executionResults).when(healthCheckExecutor).execute(selector(new String[] { testTag }, new String[] { testName }), eq(new HealthCheckExecutionOptions()));
healthCheckExecutorServlet.doGet(request, response);
verify(request, never()).getParameter(HealthCheckExecutorServlet.PARAM_TAGS.name);
verify(request, never()).getParameter(HealthCheckExecutorServlet.PARAM_NAMES.name);
verifyZeroInteractions(jsonSerializer);
verifyZeroInteractions(txtSerializer);
verifyZeroInteractions(verboseTxtSerializer);
verify(htmlSerializer).serialize(resultEquals(new Result(Result.Status.CRITICAL, "Overall Status CRITICAL")), eq(executionResults), contains("Supported URL parameters"), eq(false));
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorServletTest method getExecutionResults.
private List<HealthCheckExecutionResult> getExecutionResults(Result.Status worstStatus) {
List<HealthCheckExecutionResult> results = new ArrayList<HealthCheckExecutionResult>();
results.add(new ExecutionResult(new HealthCheckMetadata(hcServiceRef), new Result(worstStatus, worstStatus.name()), 100));
results.add(new ExecutionResult(new HealthCheckMetadata(hcServiceRef), new Result(Result.Status.OK, "OK"), 100));
return results;
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorServletTest method testDoGetJson.
@Test
public void testDoGetJson() throws ServletException, IOException {
final String testTag = "testTag";
doReturn("true").when(request).getParameter(HealthCheckExecutorServlet.PARAM_COMBINE_TAGS_WITH_OR.name);
int timeout = 5000;
doReturn(timeout + "").when(request).getParameter(HealthCheckExecutorServlet.PARAM_OVERRIDE_GLOBAL_TIMEOUT.name);
doReturn("/" + testTag + ".json").when(request).getPathInfo();
final List<HealthCheckExecutionResult> executionResults = getExecutionResults(Result.Status.WARN);
HealthCheckExecutionOptions options = new HealthCheckExecutionOptions();
options.setCombineTagsWithOr(true);
options.setOverrideGlobalTimeout(timeout);
doReturn(executionResults).when(healthCheckExecutor).execute(selector(new String[] { testTag }, new String[0]), eq(options));
healthCheckExecutorServlet.doGet(request, response);
verifyZeroInteractions(htmlSerializer);
verifyZeroInteractions(txtSerializer);
verifyZeroInteractions(verboseTxtSerializer);
verify(jsonSerializer).serialize(resultEquals(new Result(Result.Status.WARN, "Overall Status WARN")), eq(executionResults), anyString(), eq(false));
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckResultCache method useValidCacheResults.
/**
* Get the valid cache results
*/
public void useValidCacheResults(final List<HealthCheckMetadata> metadatas, final Collection<HealthCheckExecutionResult> results, final long resultCacheTtlInMs) {
final Set<HealthCheckExecutionResult> cachedResults = new TreeSet<HealthCheckExecutionResult>();
final Iterator<HealthCheckMetadata> checksIt = metadatas.iterator();
while (checksIt.hasNext()) {
final HealthCheckMetadata md = checksIt.next();
final HealthCheckExecutionResult result = getValidCacheResult(md, resultCacheTtlInMs);
if (result != null) {
cachedResults.add(result);
checksIt.remove();
}
}
logger.debug("Adding {} results from cache", cachedResults.size());
results.addAll(cachedResults);
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckResultCache method get.
private HealthCheckExecutionResult get(final HealthCheckMetadata metadata, final long globalResultCacheTtlInMs) {
final Long key = metadata.getServiceId();
final HealthCheckExecutionResult cachedResult = cache.get(key);
if (cachedResult != null) {
Date finishedAt = cachedResult.getFinishedAt();
if (finishedAt == null) {
// never cache without proper meta data -> remove it
cache.remove(key);
return null;
}
long effectiveTtl = getEffectiveTtl(metadata, globalResultCacheTtlInMs);
long validUntilLong = finishedAt.getTime() + effectiveTtl;
if (validUntilLong < 0) {
// if Long.MAX_VALUE is configured, this can become negative
validUntilLong = Long.MAX_VALUE;
}
Date validUntil = new Date(validUntilLong);
Date now = new Date();
if (validUntil.after(now)) {
logger.debug("Cache hit: validUntil={} cachedResult={}", validUntil, cachedResult);
return cachedResult;
} else {
logger.debug("Outdated result: validUntil={} cachedResult={}", validUntil, cachedResult);
// not removing result for key as out-dated results are shown for timed out checks if available
}
}
// null => no cache hit
return null;
}
Aggregations