Package org.apache.openjpa.datacache

Examples of org.apache.openjpa.datacache.DataCacheScheduler


            (OpenJPAEntityManagerFactory) getEmf();
        OpenJPAConfiguration conf =
            ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf))
                .getConfiguration();

        DataCacheScheduler scheduler = new DataCacheScheduler(conf);
        scheduler.setInterval(1);

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        String sched = ((cal.get(Calendar.MINUTE) + 1) % 60) + " ";
        DummyCache validCache = new DummyCache();
        scheduler.scheduleEviction(validCache, sched + valid);
        DummyCache invalidCache = new DummyCache();
        scheduler.scheduleEviction(invalidCache, sched + invalid);
        Thread thread = new Thread(scheduler);
        thread.setDaemon(true);
        thread.start();
        // test that it did not run yet...
        Thread.currentThread().sleep(70 * 1000); // 70 seconds
        scheduler.stop();
//        assertEquals(2, validCache.clearCount);
        assertTrue("Wrong invocation count: " + validCache.clearCount,
            validCache.clearCount == 1 || validCache.clearCount == 2);
        assertEquals(0, invalidCache.clearCount);
    }
View Full Code Here


            (OpenJPAEntityManagerFactory) getEmf();
        OpenJPAConfiguration conf =
            ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf))
                .getConfiguration();

        DataCacheScheduler scheduler = new DataCacheScheduler(conf);
        scheduler.setInterval(1);

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        String sched = ((cal.get(Calendar.MINUTE) + 1) % 60) + " ";
        DummyCache validCache = new DummyCache();
        scheduler.scheduleEviction(validCache, sched + valid);
        DummyCache invalidCache = new DummyCache();
        scheduler.scheduleEviction(invalidCache, sched + invalid);
        Thread thread = new Thread(scheduler);
        thread.setDaemon(true);
        thread.start();
        // test that it did not run yet...
        Thread.currentThread().sleep(70 * 1000); // 70 seconds
        scheduler.stop();
//        assertEquals(2, validCache.clearCount);
        assertTrue("Wrong invocation count: " + validCache.clearCount,
            validCache.clearCount == 1 || validCache.clearCount == 2);
        assertEquals(0, invalidCache.clearCount);
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.datacache.DataCacheScheduler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.