Search in sources :

Example 26 with HealthCheckExecutionResult

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));
}
Also used : HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) Matchers.anyString(org.mockito.Matchers.anyString) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) ExecutionResult(org.apache.sling.hc.core.impl.executor.ExecutionResult) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Example 27 with HealthCheckExecutionResult

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());
}
Also used : HealthCheckFilter(org.apache.sling.hc.util.HealthCheckFilter) Method(java.lang.reflect.Method) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 28 with HealthCheckExecutionResult

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));
}
Also used : TreeSet(java.util.TreeSet) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) LinkedList(java.util.LinkedList) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Example 29 with HealthCheckExecutionResult

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);
}
Also used : HealthCheckMetadata(org.apache.sling.hc.util.HealthCheckMetadata) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Date(java.util.Date) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Example 30 with HealthCheckExecutionResult

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));
}
Also used : HealthCheckExecutionOptions(org.apache.sling.hc.api.execution.HealthCheckExecutionOptions) Matchers.anyString(org.mockito.Matchers.anyString) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) ExecutionResult(org.apache.sling.hc.core.impl.executor.ExecutionResult) Result(org.apache.sling.hc.api.Result) HealthCheckExecutionResult(org.apache.sling.hc.api.execution.HealthCheckExecutionResult) Test(org.junit.Test)

Aggregations

HealthCheckExecutionResult (org.apache.sling.hc.api.execution.HealthCheckExecutionResult)34 Result (org.apache.sling.hc.api.Result)18 Test (org.junit.Test)16 Date (java.util.Date)9 HealthCheckExecutionOptions (org.apache.sling.hc.api.execution.HealthCheckExecutionOptions)9 HealthCheckMetadata (org.apache.sling.hc.util.HealthCheckMetadata)8 ExecutionResult (org.apache.sling.hc.core.impl.executor.ExecutionResult)7 ArrayList (java.util.ArrayList)6 TreeSet (java.util.TreeSet)6 LinkedList (java.util.LinkedList)5 Matchers.anyString (org.mockito.Matchers.anyString)5 SimpleDateFormat (java.text.SimpleDateFormat)4 DateFormat (java.text.DateFormat)3 HealthCheckSelector (org.apache.sling.hc.api.execution.HealthCheckSelector)3 ServiceReference (org.osgi.framework.ServiceReference)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HashSet (java.util.HashSet)2 ResultLog (org.apache.sling.hc.api.ResultLog)2 FormattingResultLog (org.apache.sling.hc.util.FormattingResultLog)2