final CacheProcessConfiguration cpc = new CacheProcessConfiguration();
final String cacheName = "cache";
cpc.createCache(cacheName, "10", "0");
final Cache cache = cpc.getCache("cache");
AsyncResult async = cache.asyncQuery(cacheKey, Period.inSeconds(30));
assertFalse(async.isReady());
CacheEntry entry = async.getEntry();
assertNotNull(entry);
final SystemClock clock = SystemClock.getDefaultInstance();
ProviderResult result = new ProviderResult(new Integer(1),
cache.getRootGroup(), true,
new PipelineCacheState(
clock.getCurrentTime().addPeriod(Period.inSeconds(2))));
async.update(result);
CacheableObjectProvider cacheableObjectProvider =
new ExpiredObjectsRemainExpiredCacheableObjectProvider(cache.getRootGroup());
assertNotNull("Integer object is retrievable via the cache",
cache.retrieve(cacheKey, cacheableObjectProvider));
Thread.sleep(3000);
// Slightly messy.
// Done this way so that we don't get a NullPointerException, and have
// to do the code below. Both ways are a little messy in that they know
// a bit too much about the internals.
//
// try {
// cache.retrieve(cacheKey);
// fail("Should throw a NullPointerException when the cache "
// + "doesn't contain the object and falls back to the null "
// + "provider");
// } catch (NullPointerException expected) {
// // expected
// }
assertNull("object has expired from cache and the provider doesn't "
+ "put it back in",
cache.retrieve(cacheKey, cacheableObjectProvider));
}