Add caching test
This commit is contained in:
parent
72c4726328
commit
e7b7ba1a6d
|
@ -99,7 +99,7 @@ public class BaseDstu2Config extends BaseConfig {
|
|||
@Bean(name = "myResourceCountsCache")
|
||||
public ResourceCountCache resourceCountsCache() {
|
||||
ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoDstu2().getResourceCounts());
|
||||
retVal.setCacheMillis(60 * DateUtils.MILLIS_PER_SECOND);
|
||||
retVal.setCacheMillis(4 * DateUtils.MILLIS_PER_HOUR);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ public class BaseDstu3Config extends BaseConfig {
|
|||
@Bean(name = "myResourceCountsCache")
|
||||
public ResourceCountCache resourceCountsCache() {
|
||||
ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoDstu3().getResourceCounts());
|
||||
retVal.setCacheMillis(60 * DateUtils.MILLIS_PER_SECOND);
|
||||
retVal.setCacheMillis(4 * DateUtils.MILLIS_PER_HOUR);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public class BaseR4Config extends BaseConfig {
|
|||
@Bean(name = "myResourceCountsCache")
|
||||
public ResourceCountCache resourceCountsCache() {
|
||||
ResourceCountCache retVal = new ResourceCountCache(() -> systemDaoR4().getResourceCounts());
|
||||
retVal.setCacheMillis(10 * DateUtils.MILLIS_PER_MINUTE);
|
||||
retVal.setCacheMillis(4 * DateUtils.MILLIS_PER_HOUR);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SingleItemLoadingCache<T> {
|
|||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
ourLog.info("Clearning cache");
|
||||
ourLog.info("Clearing cache");
|
||||
myCapabilityStatement.set(null);
|
||||
myLastFetched = 0;
|
||||
}
|
||||
|
|
|
@ -6,13 +6,12 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
|
@ -62,4 +61,32 @@ public class SingleItemLoadingCacheTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithLoadingDisabled() {
|
||||
long start = System.currentTimeMillis();
|
||||
SingleItemLoadingCache.setNowForUnitTest(start);
|
||||
|
||||
// Cache of 0 means "never load"
|
||||
SingleItemLoadingCache<CapabilityStatement> cache = new SingleItemLoadingCache<>(myFetcher);
|
||||
cache.setCacheMillis(0);
|
||||
|
||||
/*
|
||||
* No matter how long we wait it should never load...
|
||||
*/
|
||||
|
||||
assertEquals(null, cache.get());
|
||||
|
||||
cache.update();
|
||||
assertEquals(null, cache.get());
|
||||
|
||||
SingleItemLoadingCache.setNowForUnitTest(start + 400);
|
||||
cache.update();
|
||||
assertEquals(null, cache.get());
|
||||
|
||||
SingleItemLoadingCache.setNowForUnitTest(start + 80000);
|
||||
cache.update();
|
||||
assertEquals(null, cache.get());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue