Package org.castor.cache

Examples of org.castor.cache.Cache


        cache.clear();
        assertTrue(cache.isEmpty());
    }

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

        assertEquals("first value", cache.get("first key"));
        assertEquals("second value", cache.get("second key"));
        assertEquals("third value", cache.get("third key"));
        assertNull(cache.get("fourth key"));
        assertNull(cache.get("fifth key"));
    }
View Full Code Here


        assertNull(cache.get("fourth key"));
        assertNull(cache.get("fifth key"));
    }

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

        assertEquals("third value", cache.put("third key", "alternate third value"));
        assertNull(cache.put("fourth key", "forth value"));

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

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

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

        assertEquals("third value", cache.remove("third key"));

        assertTrue(cache.containsKey("first key"));
        assertTrue(cache.containsKey("second key"));
        assertFalse(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 testPutAll() throws CacheAcquireException {
        Cache cache = initialize();

        HashMap map = new HashMap();
        map.put("fourth key", "forth value");
        map.put("fifth key", "fifth value");
       
        cache.putAll(map);
       
        assertTrue(cache.containsKey("first key"));
        assertTrue(cache.containsKey("second key"));
        assertTrue(cache.containsKey("third key"));
        assertTrue(cache.containsKey("fourth key"));
        assertTrue(cache.containsKey("fifth key"));
    }
View Full Code Here

    public void testBasics() throws CacheAcquireException {
        assertEquals("time-limited", TimeLimited.TYPE);
        assertEquals("ttl", TimeLimited.PARAM_TTL);
        assertEquals(30, TimeLimited.DEFAULT_TTL);

        Cache cache = new TimeLimited();
        assertTrue(cache instanceof TimeLimited);

        assertEquals("time-limited", cache.getType());
        assertEquals(30, ((TimeLimited) cache).getTTL());
        assertEquals(Cache.DEFAULT_NAME, cache.getName());
       
        Properties params = new Properties();
        params.put(Cache.PARAM_NAME, "dummy1");
        cache.initialize(params);
        assertEquals(30, ((TimeLimited) cache).getTTL());
        assertEquals("dummy1", cache.getName());
       
        params.clear();
        params.put(Cache.PARAM_NAME, "dummy2");
        params.put(TimeLimited.PARAM_TTL, "-10");
        cache.initialize(params);
        assertEquals(30, ((TimeLimited) cache).getTTL());
        assertEquals("dummy2", cache.getName());
       
        params.clear();
        params.put(Cache.PARAM_NAME, "dummy3");
        params.put(TimeLimited.PARAM_TTL, "0");
        cache.initialize(params);
        assertEquals(30, ((TimeLimited) cache).getTTL());
        assertEquals("dummy3", cache.getName());
       
        params.clear();
        params.put(Cache.PARAM_NAME, "dummy4");
        params.put(TimeLimited.PARAM_TTL, "10");
        cache.initialize(params);
        assertEquals(10, ((TimeLimited) cache).getTTL());
        assertEquals("dummy4", cache.getName());
       
        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

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

    public void testKeySet() throws CacheAcquireException {
        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() throws CacheAcquireException {
        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() throws CacheAcquireException {
        Cache cache = initialize();

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

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

    private Cache initialize() {
        Cache cache = new TimeLimited();

        try {
            Properties params = new Properties();
            params.put(Cache.PARAM_NAME, "dummy");
            params.put(TimeLimited.PARAM_TTL, new Integer(10));
            cache.initialize(params);
        } catch (CacheAcquireException ex) {
            fail("Unexpected CacheAcquireException at initialization.");
        }
       
        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() {
        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

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.