Author: ghenzler
Date: Mon Oct 17 22:30:50 2016
New Revision: 1765377

URL: http://svn.apache.org/viewvc?rev=1765377&view=rev
Log:
SLING-6126  Introduce HC service property hc.resultCacheTtlInMs for per-HC TTL 
configuration. Thanks Evgeniy Fitsner for your contribution.

Added:
    
sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCacheTest.java
   (with props)
Modified:
    sling/trunk/bundles/extensions/healthcheck/annotations/pom.xml
    
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java
    
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java
    
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
    
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
    
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java
    
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java
    
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java

Modified: sling/trunk/bundles/extensions/healthcheck/annotations/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/annotations/pom.xml?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/annotations/pom.xml (original)
+++ sling/trunk/bundles/extensions/healthcheck/annotations/pom.xml Mon Oct 17 
22:30:50 2016
@@ -64,7 +64,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.hc.core</artifactId>
-            <version>1.1.0</version>
+            <version>1.2.4</version>
             <scope>provided</scope>
         </dependency>
      </dependencies>

Modified: 
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java
 Mon Oct 17 22:30:50 2016
@@ -47,6 +47,14 @@ public @interface SlingHealthCheck {
      * This attribute is converted to values for the 
<code>hc.async.cronExpression</code> property. */
     String asyncCronExpression() default "";       
     
+    /**
+     * Overrides the global result TTL as configured in 
+     * {@link org.apache.sling.hc.core.impl.executor.HealthCheckExecutorImpl} 
for this individual check.
+     * <p>
+     * The value of this property must be of type {@link Long} and is 
configured in ms.
+     */
+    long resultCacheTtlInMs() default -1;
+    
     // handling of service and component properties (optional)
 
     /** Whether to generate a default SCR component tag. If set to false, a 
{@link org.apache.felix.scr.annotations.Component} annotation can be added 
manually
@@ -80,4 +88,6 @@ public @interface SlingHealthCheck {
     /** This is generally used as a description for the object described by 
the meta type. This name may be localized by prepending a % sign to the name. 
Default
      * value: %&lt;name&gt;.description */
     String description() default "";
+
+
 }

Modified: 
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/annotations/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java
 Mon Oct 17 22:30:50 2016
@@ -38,10 +38,10 @@ public class SlingHealthCheckProcessor i
 
     @Override
     public void process(final ScannedClass scannedClass, final 
ClassDescription classDescription) throws SCRDescriptorException, 
SCRDescriptorFailureException {
-        final List<ClassAnnotation> servlets = 
scannedClass.getClassAnnotations(SlingHealthCheck.class.getName());
-        scannedClass.processed(servlets);
+        final List<ClassAnnotation> healthChecks = 
scannedClass.getClassAnnotations(SlingHealthCheck.class.getName());
+        scannedClass.processed(healthChecks);
 
-        for (final ClassAnnotation cad : servlets) {
+        for (final ClassAnnotation cad : healthChecks) {
             processHealthCheck(cad, classDescription);
         }
     }
@@ -86,22 +86,22 @@ public class SlingHealthCheckProcessor i
         }
 
         // generate HC PropertyDescriptions
-        generateStringPropertyDescriptor(cad, classDescription, metatype, 
"name", HealthCheck.NAME, "Name", "Name", false);
-        generateStringPropertyDescriptor(cad, classDescription, metatype, 
"tags", HealthCheck.TAGS, "Tags", "Tags", true);
-        generateStringPropertyDescriptor(cad, classDescription, metatype, 
"mbeanName", HealthCheck.MBEAN_NAME, "MBean", "MBean name (leave empty for not 
using JMX)", false);
-        generateStringPropertyDescriptor(cad, classDescription, metatype, 
"asyncCronExpression", "hc.async.cronExpression" /* use constant once API is 
released */ , "Cron expression", "Cron expression for asynchronous execution 
(leave empty for synchronous execution)", false);
+        generatePropertyDescriptor(cad, classDescription, metatype, "name", 
HealthCheck.NAME, PropertyType.String, "Name", "Name of the Health Check", 
false);
+        generatePropertyDescriptor(cad, classDescription, metatype, "tags", 
HealthCheck.TAGS, PropertyType.String, "Tags", "List of tags", true);
+        generatePropertyDescriptor(cad, classDescription, metatype, 
"mbeanName", HealthCheck.MBEAN_NAME, PropertyType.String, "MBean", "MBean name 
(leave empty for not using JMX)", false);
+        generatePropertyDescriptor(cad, classDescription, metatype, 
"asyncCronExpression",  HealthCheck.ASYNC_CRON_EXPRESSION, PropertyType.String, 
"Cron expression", "Cron expression for asynchronous execution (leave empty for 
synchronous execution)", false);
+        generatePropertyDescriptor(cad, classDescription, metatype, 
"resultCacheTtlInMs", "hc.resultCacheTtlInMs" /* use constant once API is 
released */, PropertyType.Long , "Result Cache TTL", "TTL for results. The 
value -1 (default) uses the global configuration in health check executor. 
Redeployment of a HC always invalidates its cached result.", false);
     }
 
-    /** Generates a property descriptor of type {@link PropertyType#String[]} 
*/
-    private void generateStringPropertyDescriptor(final ClassAnnotation cad, 
final ClassDescription classDescription,
-            final boolean metatype, final String propertyName, final String 
propertyDescriptorName, String label, String description, boolean isArray) {
-
+    /** Generates a property descriptor of type {@link PropertyType} */
+    private void generatePropertyDescriptor(final ClassAnnotation cad, final 
ClassDescription classDescription,
+            final boolean metatype, final String propertyName, final String 
propertyDescriptorName, PropertyType propertyType, String label, String 
description, boolean isArray) {
 
         final PropertyDescription pd = new PropertyDescription(cad);
         pd.setName(propertyDescriptorName);
         pd.setLabel(label);
         pd.setDescription(description);
-        pd.setType(PropertyType.String);
+        pd.setType(propertyType);
 
         if(isArray) {
             final String[] values = (String[]) cad.getValue(propertyName);
@@ -109,8 +109,10 @@ public class SlingHealthCheckProcessor i
             pd.setUnbounded(PropertyUnbounded.ARRAY);
             pd.setCardinality(Integer.MAX_VALUE);
         } else {
-            final String propertyVal = (String) cad.getValue(propertyName);
-            pd.setValue(propertyVal);
+            final Object propertyVal = cad.getValue(propertyName);
+            String pdValue = (propertyVal instanceof String) ? (String) 
propertyVal :
+                propertyVal!=null ? propertyVal.toString() : null;
+            pd.setValue(pdValue);
             pd.setUnbounded(PropertyUnbounded.DEFAULT);
         }
         
@@ -119,7 +121,6 @@ public class SlingHealthCheckProcessor i
         }
         classDescription.add(pd);
     }
-
     
     @Override
     public int getRanking() {

Modified: 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/HealthCheck.java
 Mon Oct 17 22:30:50 2016
@@ -66,7 +66,14 @@ public interface HealthCheck {
      * will be executed asynchronously using the cron expression provided.
      */
     String ASYNC_CRON_EXPRESSION = "hc.async.cronExpression";
-    
+
+    /**
+     * Optional service property: TTL for health check {@link Result}.
+     * The value of this property must be of type {@link Long} and is 
+     * specified in ms.
+     */
+    String RESULT_CACHE_TTL_IN_MS = "hc.resultCacheTtlInMs";
+
     /**
      * Execute this health check and return a {@link Result}
      * This is meant to execute quickly, access to external

Modified: 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/api/package-info.java
 Mon Oct 17 22:30:50 2016
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("1.0.1")
+@Version("1.1.0")
 package org.apache.sling.hc.api;
 
 import aQute.bnd.annotation.Version;

Modified: 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCache.java
 Mon Oct 17 22:30:50 2016
@@ -82,7 +82,7 @@ public class HealthCheckResultCache {
         return get(metadata, resultCacheTtlInMs);
     }
 
-    private HealthCheckExecutionResult get(final HealthCheckMetadata metadata, 
final long resultCacheTtlInMs) {
+    private HealthCheckExecutionResult get(final HealthCheckMetadata metadata, 
final long globalResultCacheTtlInMs) {
         final Long key = metadata.getServiceId();
         final HealthCheckExecutionResult cachedResult = cache.get(key);
         if (cachedResult != null) {
@@ -93,8 +93,12 @@ public class HealthCheckResultCache {
                 return null;
             }
 
-            // Option: add resultCacheTtlInMs as property to health check to 
make it configurable per check
-            Date validUntil = new Date(finishedAt.getTime() + 
resultCacheTtlInMs);
+            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);
@@ -110,6 +114,24 @@ public class HealthCheckResultCache {
     }
 
     /**
+     * Obtains the effective TTL for a given Metadata descriptor.
+     *
+     * @param metadata Metadata descriptor of health check 
+     * @param globalTtl TTL from service configuration of health check 
executor (used as default)
+     * @return effective TTL
+     */
+    private long getEffectiveTtl(HealthCheckMetadata metadata, long globalTtl) 
{
+        final long ttl;
+        Long hcTtl = metadata.getResultCacheTtlInMs();
+        if (hcTtl != null && hcTtl > 0) {
+            ttl = hcTtl;
+        } else {
+            ttl = globalTtl;
+        }
+        return ttl;
+    }
+
+    /**
      * Clear the whole cache
      */
     public void clear() {

Modified: 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/HealthCheckMetadata.java
 Mon Oct 17 22:30:50 2016
@@ -47,6 +47,8 @@ public class HealthCheckMetadata {
 
     private final transient ServiceReference serviceReference;
 
+    private final Long resultCacheTtlInMs;
+
     public HealthCheckMetadata(final ServiceReference ref) {
         this.serviceId = (Long) ref.getProperty(Constants.SERVICE_ID);
         this.name = (String) ref.getProperty(HealthCheck.NAME);
@@ -54,6 +56,7 @@ public class HealthCheckMetadata {
         this.title = getHealthCheckTitle(ref);
         this.tags = 
arrayPropertyToListOfStr(ref.getProperty(HealthCheck.TAGS));
         this.asyncCronExpression = (String) 
ref.getProperty(HealthCheck.ASYNC_CRON_EXPRESSION);
+        this.resultCacheTtlInMs = 
(Long)ref.getProperty(HealthCheck.RESULT_CACHE_TTL_IN_MS);
         this.serviceReference = ref;
     }
 
@@ -116,6 +119,15 @@ public class HealthCheckMetadata {
         return this.serviceReference;
     }
 
+    /**
+     * TTL for the result cache in ms. 
+     * 
+     * @return TTL for the result cache or <code>null</code> if not configured.
+     */
+    public Long getResultCacheTtlInMs() {
+        return resultCacheTtlInMs;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;

Modified: 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java?rev=1765377&r1=1765376&r2=1765377&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
 (original)
+++ 
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/util/package-info.java
 Mon Oct 17 22:30:50 2016
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("1.2.0")
+@Version("1.3.0")
 package org.apache.sling.hc.util;
 
 import aQute.bnd.annotation.Version;

Added: 
sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCacheTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCacheTest.java?rev=1765377&view=auto
==============================================================================
--- 
sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCacheTest.java
 (added)
+++ 
sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCacheTest.java
 Mon Oct 17 22:30:50 2016
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.hc.core.impl.executor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.sling.hc.api.HealthCheck;
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.api.execution.HealthCheckExecutionResult;
+import org.apache.sling.hc.util.HealthCheckMetadata;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+public class HealthCheckResultCacheTest {
+
+    private static final int HC_TIMEOUT_NOT_SET = -1;
+    private static final int DUR_1_MIN = 60 * 1000;
+    private static final int DUR_2_MIN = 2 * DUR_1_MIN;
+    private static final int DUR_3_MIN = 3 * DUR_1_MIN;
+    private static final int DUR_4_MIN = 4 * DUR_1_MIN;
+
+    private HealthCheckResultCache healthCheckResultCache = new 
HealthCheckResultCache();
+    
+    @Mock 
+    ServiceReference serviceRef;
+    
+    @Before
+    public void setup() {
+        initMocks(this);
+    }
+    
+    private HealthCheckMetadata setupHealthCheckMetadata(long id, long ttl) {
+        reset(serviceRef);
+        doReturn(id).when(serviceRef).getProperty(Constants.SERVICE_ID);
+        
doReturn(ttl).when(serviceRef).getProperty(HealthCheck.RESULT_CACHE_TTL_IN_MS);
+        doReturn("HC id="+id).when(serviceRef).getProperty(HealthCheck.NAME);
+        return new HealthCheckMetadata(serviceRef);
+    }
+
+    @Test
+    public void testHealthCheckResultCache() {
+
+        HealthCheckMetadata hc1 = setupHealthCheckMetadata(1, 
HC_TIMEOUT_NOT_SET);
+        ExecutionResult executionResult1 = spy(new ExecutionResult(hc1, new 
Result(Result.Status.OK, "result for hc1"), 1));
+        doReturn(new Date(new Date().getTime() - 
DUR_1_MIN)).when(executionResult1).getFinishedAt();
+        healthCheckResultCache.updateWith(executionResult1);
+
+        HealthCheckMetadata hc2 = setupHealthCheckMetadata(2, 
HC_TIMEOUT_NOT_SET); 
+        ExecutionResult executionResult2 = spy(new ExecutionResult(hc2, new 
Result(Result.Status.OK, "result for hc2"), 1));
+        doReturn(new Date(new Date().getTime() - 
DUR_3_MIN)).when(executionResult2).getFinishedAt();
+        healthCheckResultCache.updateWith(executionResult2);
+        
+        HealthCheckMetadata hc3 = setupHealthCheckMetadata(3, DUR_4_MIN);
+        ExecutionResult executionResult3 = spy(new ExecutionResult(hc3, new 
Result(Result.Status.OK, "result for hc3"), 1));
+        doReturn(new Date(new Date().getTime() - 
DUR_3_MIN)).when(executionResult3).getFinishedAt();
+        healthCheckResultCache.updateWith(executionResult3);
+        
+        HealthCheckMetadata hc4 = setupHealthCheckMetadata(4, 
HC_TIMEOUT_NOT_SET);   
+        // no result for this yet
+        
+        List<HealthCheckMetadata> hcList = new 
ArrayList<HealthCheckMetadata>(Arrays.asList(hc1,hc2,hc3,hc4));
+        List<HealthCheckExecutionResult> results = new 
ArrayList<HealthCheckExecutionResult>();
+        
+        healthCheckResultCache.useValidCacheResults(hcList, results, 
DUR_2_MIN);
+        
+        assertTrue(hcList.contains(hc2)); // result too old, left in hcList 
for later execution
+        assertTrue(hcList.contains(hc4)); // no result was added to cache via 
updateWith()
+        
+        assertTrue(results.contains(executionResult1)); // true <= result one 
min old, global timeout 2min
+        assertFalse(results.contains(executionResult2)); // false <= result 
three min old, global timeout 2min
+        assertTrue(results.contains(executionResult3)); // true <= result one 
three old, HC timeout 4min
+
+        // values not found in cache are left in hcList
+        assertEquals(2, hcList.size()); 
+        assertEquals(2, results.size()); 
+   
+    }
+
+    @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);
+        assertNull(result); // even though global timeout would be ok 
(2min<3min, the hc timeout of 1min invalidates the 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);
+        assertEquals(executionResult, result); // even though global timeout 
would invalidate this result (1min<2min, the hc timeout of 3min allows the 
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); 
+        
+    }
+    
+}

Propchange: 
sling/trunk/bundles/extensions/healthcheck/core/src/test/java/org/apache/sling/hc/core/impl/executor/HealthCheckResultCacheTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to