Package org.castor.cache

Examples of org.castor.cache.Cache


        assertTrue(cache.containsKey("fourth key"));
        assertTrue(cache.containsKey("fifth key"));
    }

    public void testKeySet() {
        Cache cache = initialize();

        Set set = cache.keySet();
       
        assertEquals(3, set.size());
        assertTrue(set.contains("first key"));
        assertTrue(set.contains("second key"));
        assertTrue(set.contains("third key"));
View Full Code Here


        assertTrue(set.contains("second key"));
        assertTrue(set.contains("third key"));
    }

    public void testValues() {
        Cache cache = initialize();

        Collection col = cache.values();
       
        assertEquals(3, col.size());
        assertTrue(col.contains("first value"));
        assertTrue(col.contains("second value"));
        assertTrue(col.contains("third value"));
View Full Code Here

        assertTrue(col.contains("second value"));
        assertTrue(col.contains("third value"));
    }

    public void testEntrySet() {
        Cache cache = initialize();

        Set set = cache.entrySet();
       
        assertEquals(3, set.size());
       
        Object[] objs = set.toArray();
        HashMap map = new HashMap();
View Full Code Here

        assertTrue(map.containsKey("third key"));
        assertEquals("third value", map.get("third key"));
    }
   
    public void testExpire() throws InterruptedException {
        Cache cache = new TimeLimited();

        try {
            Properties params = new Properties();
            params.put(Cache.PARAM_NAME, "dummy");
            params.put(TimeLimited.PARAM_TTL, "5");
            cache.initialize(params);
        } catch (CacheAcquireException ex) {
            fail("Unexpected CacheAcquireException at initialization.");
        }

        assertEquals(0, cache.size());
       
        assertNull(cache.put("a", "#a"));
        assertEquals(1, cache.size());
        assertTrue(cache.containsKey("a"));
       
        Thread.sleep(500);

        assertEquals("#a", cache.put("a", "#a"));
        assertEquals(1, cache.size());
        assertTrue(cache.containsKey("a"));

        Thread.sleep(500);

        assertNull(cache.put("b", "#b"));
        assertEquals(2, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));

        Thread.sleep(500);

        assertNull(cache.put("c", "#c"));
        assertEquals(3, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));
        assertTrue(cache.containsKey("c"));

        Thread.sleep(500);

        assertNull(cache.put("d", "#d"));
        assertEquals(4, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));
        assertTrue(cache.containsKey("c"));
        assertTrue(cache.containsKey("d"));

        Thread.sleep(500);
       
        assertNull(cache.put("e", "#e"));
        assertEquals(5, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));
        assertTrue(cache.containsKey("c"));
        assertTrue(cache.containsKey("d"));
        assertTrue(cache.containsKey("e"));

        Thread.sleep(500);

        assertNull(cache.put("f", "#f"));
        assertEquals(6, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));
        assertTrue(cache.containsKey("c"));
        assertTrue(cache.containsKey("d"));
        assertTrue(cache.containsKey("e"));
        assertTrue(cache.containsKey("f"));

        Thread.sleep(500);

        assertNull(cache.put("g", "#g"));
        assertEquals(7, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));
        assertTrue(cache.containsKey("c"));
        assertTrue(cache.containsKey("d"));
        assertTrue(cache.containsKey("e"));
        assertTrue(cache.containsKey("f"));
        assertTrue(cache.containsKey("g"));

        Thread.sleep(500);
       
        assertNull(cache.put("h", "#h"));
        assertEquals(8, cache.size());
        assertTrue(cache.containsKey("a"));
        assertTrue(cache.containsKey("b"));
        assertTrue(cache.containsKey("c"));
        assertTrue(cache.containsKey("d"));
        assertTrue(cache.containsKey("e"));
        assertTrue(cache.containsKey("f"));
        assertTrue(cache.containsKey("g"));
        assertTrue(cache.containsKey("h"));

       
        while (cache.size() > 0) {
            Thread.sleep(500);
            checkKeys(cache);
        }
    }
View Full Code Here

    public TestRefreshingReaper(final String name) { super(name); }
   
    public void test() {
        RefreshingReaperMock.getExpiredObjects().clear();
       
        Cache cache = new Unlimited();
       
        Container container = new MapContainer();
        for (int i = 0; i < 10; i++) {
            container.put(new Integer(i), Integer.toString(i));
        }
       
        AbstractReaper reaper = new RefreshingReaperMock();
        reaper.setCache(cache);
        reaper.handleExpiredContainer(container);
        assertEquals(10, container.size());
       
        assertEquals(10, cache.size());
        for (int i = 0; i < 10; i++) {
            Object key = new Integer(i);
            assertTrue(cache.containsKey(key));
            assertEquals(cache.get(key), Integer.toString(i) + " refreshed");
        }

        List expired = RefreshingReaperMock.getExpiredObjects();
        assertEquals(10, expired.size());
        for (int i = 0; i < 10; i++) {
View Full Code Here

        assertEquals("ttl", AbstractHashbelt.PARAM_TTL);
        assertEquals(60, AbstractHashbelt.DEFAULT_TTL);
        assertEquals("monitor", AbstractHashbelt.PARAM_MONITOR);
        assertEquals(0, AbstractHashbelt.DEFAULT_MONITOR);

        Cache cache = new FIFOHashbelt();
        assertTrue(cache instanceof FIFOHashbelt);
        assertEquals("fifo", cache.getType());

        Properties params = new Properties();
        params.put(Cache.PARAM_NAME, "dummy1");
        try {
            cache.initialize(params);
        } catch (CacheAcquireException ex) {
            fail("Failed to initialize FIFOHashbelt instance");
        }

        assertFalse(cache.containsKey("first key"));
        assertFalse(cache.containsKey("second key"));

        assertNull(cache.put("first key", "first value"));

        assertTrue(cache.containsKey("first key"));
        assertFalse(cache.containsKey("second key"));

        assertNull(cache.put("second key", "second value"));

        assertTrue(cache.containsKey("first key"));
        assertTrue(cache.containsKey("second key"));
    }
View Full Code Here

   
    public void test() {
        AbstractReaper reaper = new AbstractReaperMock();
       
        assertNull(reaper.getCache());
        Cache cache = new NoCache();
        reaper.setCache(cache);
        assertNotNull(reaper.getCache());
        assertTrue(cache == reaper.getCache());
    }
View Full Code Here

        assertTrue(cache.containsKey("first key"));
        assertTrue(cache.containsKey("second key"));
    }

    private Cache initialize() throws CacheAcquireException {
        Cache cache = new FIFOHashbelt();
        Properties params = new Properties();
        params.put(Cache.PARAM_NAME, "dummy1");
        cache.initialize(params);

        assertNull(cache.put("first key", "first value"));
        assertNull(cache.put("second key", "second value"));
        assertNull(cache.put("third key", "third value"));
       
        return cache;
    }
View Full Code Here

       
        return cache;
    }
   
    public void testContainsKey() throws CacheAcquireException {
        Cache cache = initialize();

        assertTrue(cache.containsKey("first key"));
        assertTrue(cache.containsKey("second key"));
        assertTrue(cache.containsKey("third key"));
        assertFalse(cache.containsKey("fourth key"));
        assertFalse(cache.containsKey("fifth key"));
    }
View Full Code Here

        assertFalse(cache.containsKey("fourth key"));
        assertFalse(cache.containsKey("fifth key"));
    }

    public void testContainsValue() throws CacheAcquireException {
        Cache cache = initialize();

        assertTrue(cache.containsValue("first value"));
        assertTrue(cache.containsValue("second value"));
        assertTrue(cache.containsValue("third value"));
        assertFalse(cache.containsValue("fourth value"));
        assertFalse(cache.containsValue("fifth value"));
    }
View Full Code Here

TOP

Related Classes of org.castor.cache.Cache

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.