### Question:
ScheduledRefreshCacheExtension implements CacheExtension { @Override public void init() { if (config.getUniqueNamePart() != null) { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName() + "_" + config.getUniqueNamePart(); } else { this.name = "scheduledRefresh_" + underlyingCache.getCacheManager().getName() + "_" + underlyingCache.getName(); } this.groupName = name + "_grp"; try { makeAndStartQuartzScheduler(); try { JobDetail seed = addOverseerJob(); try { scheduleOverseerJob(seed); status = Status.STATUS_ALIVE; } catch (SchedulerException e) { LOG.error("Unable to schedule control job for Scheduled Refresh", e); } } catch (SchedulerException e) { LOG.error("Unable to add Scheduled Refresh control job to Quartz Job Scheduler", e); } } catch (SchedulerException e) { LOG.error("Unable to instantiate Quartz Job Scheduler for Scheduled Refresh", e); } } ScheduledRefreshCacheExtension(ScheduledRefreshConfiguration config,
                                          Ehcache cache); @Override void init(); @Override void dispose(); @Override CacheExtension clone(Ehcache cache); @Override Status getStatus();  }### Answer:
@Test public void testSimpleCaseProgrammatic() { CacheManager manager = new CacheManager(); manager.removalAll(); manager.addCache(new Cache(new CacheConfiguration().name("test").eternal(true).maxEntriesLocalHeap(5000))); Ehcache cache = manager.getEhcache("test"); cache.registerCacheLoader(stupidCacheLoaderEvens); cache.registerCacheLoader(stupidCacheLoaderOdds); int second = (new GregorianCalendar().get(Calendar.SECOND) + 5) % 60; ScheduledRefreshConfiguration config = new ScheduledRefreshConfiguration().batchSize(100).quartzThreadCount (4).cronExpression(second + "/5 * * * * ?").build(); ScheduledRefreshCacheExtension cacheExtension = new ScheduledRefreshCacheExtension(config, cache); cache.registerCacheExtension(cacheExtension); cacheExtension.init(); for (int i = 0; i < 10; i++) { cache.put(new Element(new Integer(i), i + "")); } sleepySeconds(8); for (Object key : cache.getKeys()) { Element val = cache.get(key); int iVal = ((Number) key).intValue(); if ((iVal & 0x01) == 0) { Assert.assertEquals(iVal + 20000, Long.parseLong((String) val.getObjectValue())); } else { Assert.assertEquals(iVal + 10000, Long.parseLong((String) val.getObjectValue())); } } manager.removalAll(); manager.shutdown(); }
@Test public void testPolling() { CacheManager manager = new CacheManager(); manager.removalAll(); manager.addCache(new Cache(new CacheConfiguration().name("tt").eternal(true).maxEntriesLocalHeap(5000).overflowToDisk(false))); Ehcache cache = manager.getEhcache("tt"); stupidCacheLoaderEvens.setMsDelay(100); cache.registerCacheLoader(stupidCacheLoaderEvens); cache.registerCacheLoader(stupidCacheLoaderOdds); int second = (new GregorianCalendar().get(Calendar.SECOND) + 5) % 60; ScheduledRefreshConfiguration config = new ScheduledRefreshConfiguration().batchSize(2).quartzThreadCount (2).pollTimeMs(100).cronExpression(second + "/1 * * * * ?").build(); ScheduledRefreshCacheExtension cacheExtension = new ScheduledRefreshCacheExtension(config, cache); cache.registerCacheExtension(cacheExtension); cacheExtension.init(); final int ELEMENT_COUNT=50; long[] orig=new long[ELEMENT_COUNT]; for (int i = 0; i < ELEMENT_COUNT; i++) { Element elem = new Element(new Integer(i), i + ""); orig[i]=elem.getCreationTime(); cache.put(elem); } sleepySeconds(20); manager.removalAll(); manager.shutdown(); }