propsMap
.put("openjpa.DataCache", "true(EvictionSchedule=\"" + sched + "\")");
propsMap.put("openjpa.RemoteCommitProvider", "sjvm");
propsMap.put("openjpa.FlushBeforeQueries", "true");
propsMap.put("openjpa.BrokerImpl", CacheTestBroker.class.getName());
OpenJPAEntityManagerFactory emf =
(OpenJPAEntityManagerFactory) getEmf(propsMap);
((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf))
.getConfiguration().getDataCacheManagerInstance()
.getDataCacheScheduler().setInterval(1);
DataCache cache = JPAFacadeHelper.getMetaData(emf,
ScheduledEviction.class).getDataCache();
OpenJPAEntityManager em = (OpenJPAEntityManager) emf
.createEntityManager();
startTx(em);
ScheduledEviction pc = new ScheduledEviction("Foo");
em.persist(pc);
Object oid = em.getObjectId(pc);
Object oidwithclass = new Id(ScheduledEviction.class, oid.toString());
endTx(em);
endEm(em);
cache.clear();// clear and wait until next run.
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
if (cal.get(Calendar.MINUTE) % 2 == 0)
Thread.currentThread().sleep
((60 - cal.get(Calendar.SECOND)) * 1000);
cal.setTime(new Date());
assertTrue(cal.get(Calendar.MINUTE) % 2 == 1);
em = (OpenJPAEntityManager) emf.createEntityManager();
em.find(ScheduledEviction.class, oid);
endEm(em);
assertTrue(cache.contains(oidwithclass));
Thread.currentThread().sleep(130 * 1000);
assertFalse(cache.contains(oidwithclass));
emf.close();
}