use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorServletTest method testDoGetHtml.
@Test
public void testDoGetHtml() throws ServletException, IOException {
final String testTag = "testTag";
doReturn(testTag).when(request).getParameter(HealthCheckExecutorServlet.PARAM_TAGS.name);
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[0]), eq(new HealthCheckExecutionOptions()));
healthCheckExecutorServlet.doGet(request, response);
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 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.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorImplTest method testCollectResultsFromFutures.
@Test
public void testCollectResultsFromFutures() throws Exception {
List<HealthCheckFuture> futures = new LinkedList<HealthCheckFuture>();
futures.add(future);
Collection<HealthCheckExecutionResult> results = new TreeSet<HealthCheckExecutionResult>();
when(future.isDone()).thenReturn(true);
ExecutionResult testResult = new ExecutionResult(HealthCheckMetadata, new Result(Result.Status.OK, "test"), 10L);
when(future.get()).thenReturn(testResult);
healthCheckExecutorImpl.collectResultsFromFutures(futures, results);
verify(future, times(1)).get();
assertEquals(1, results.size());
assertTrue(results.contains(testResult));
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckResultCacheTest method testHealthCheckResultCacheTtl.
@Test
public void testHealthCheckResultCacheTtl() {
//-- test cache miss due to HC TTL
HealthCheckMetadata hcWithTtl = setupHealthCheckMetadata(1, DUR_1_MIN);
ExecutionResult executionResult = spy(new ExecutionResult(hcWithTtl, new Result(Result.Status.OK, "result for hc"), 1));
doReturn(new Date(new Date().getTime() - DUR_2_MIN)).when(executionResult).getFinishedAt();
healthCheckResultCache.updateWith(executionResult);
HealthCheckExecutionResult result = healthCheckResultCache.getValidCacheResult(hcWithTtl, DUR_3_MIN);
// even though global timeout would be ok (2min<3min, the hc timeout of 1min invalidates the result)
assertNull(result);
//-- test cache hit due to HC TTL
hcWithTtl = setupHealthCheckMetadata(2, DUR_3_MIN);
executionResult = spy(new ExecutionResult(hcWithTtl, new Result(Result.Status.OK, "result for hc"), 1));
doReturn(new Date(new Date().getTime() - DUR_2_MIN)).when(executionResult).getFinishedAt();
healthCheckResultCache.updateWith(executionResult);
result = healthCheckResultCache.getValidCacheResult(hcWithTtl, DUR_1_MIN);
// even though global timeout would invalidate this result (1min<2min, the hc timeout of 3min allows the result)
assertEquals(executionResult, result);
//-- test Long.MAX_VALUE
hcWithTtl = setupHealthCheckMetadata(3, Long.MAX_VALUE);
executionResult = spy(new ExecutionResult(hcWithTtl, new Result(Result.Status.OK, "result for hc"), 1));
doReturn(new Date(new Date().getTime() - DUR_4_MIN)).when(executionResult).getFinishedAt();
healthCheckResultCache.updateWith(executionResult);
result = healthCheckResultCache.getValidCacheResult(hcWithTtl, DUR_1_MIN);
assertEquals(executionResult, result);
}
use of org.apache.sling.hc.api.execution.HealthCheckExecutionResult in project sling by apache.
the class HealthCheckExecutorServletTest method testDoGetVerboseTxt.
@Test
public void testDoGetVerboseTxt() throws ServletException, IOException {
String testTag = "testTag";
doReturn(testTag).when(request).getParameter(HealthCheckExecutorServlet.PARAM_TAGS.name);
doReturn(HealthCheckExecutorServlet.FORMAT_VERBOSE_TXT).when(request).getParameter(HealthCheckExecutorServlet.PARAM_FORMAT.name);
List<HealthCheckExecutionResult> executionResults = getExecutionResults(Result.Status.WARN);
doReturn(executionResults).when(healthCheckExecutor).execute(selector(new String[] { testTag }, new String[0]), any(HealthCheckExecutionOptions.class));
healthCheckExecutorServlet.doGet(request, response);
verifyZeroInteractions(htmlSerializer);
verifyZeroInteractions(jsonSerializer);
verifyZeroInteractions(txtSerializer);
verify(verboseTxtSerializer).serialize(resultEquals(new Result(Result.Status.WARN, "Overall Status WARN")), eq(executionResults), eq(false));
}
Aggregations