Package org.castor.cache

Examples of org.castor.cache.Cache


        Cache c = new OsCache(null);
        assertTrue(c instanceof OsCache);
    }

    public void testGetType() {
        Cache c = new OsCache(null);
        assertEquals("oscache", c.getType());
    }
View Full Code Here


        Cache c = new OsCache(null);
        assertEquals("oscache", c.getType());
    }

    public void testUnsupported() {
        Cache c = new OsCache(null);
       
        try {
            c.size();
            fail("UnsupportedOperationException should have been thrown.");
        } catch (UnsupportedOperationException ex) {
            assertEquals("size()", ex.getMessage());
        } catch (Throwable t) {
            fail("UnsupportedOperationException should have been thrown.");
        }
       
        try {
            c.isEmpty();
            fail("UnsupportedOperationException should have been thrown.");
        } catch (UnsupportedOperationException ex) {
            assertEquals("isEmpty()", ex.getMessage());
        } catch (Throwable t) {
            fail("UnsupportedOperationException should have been thrown.");
        }
       
        try {
            c.containsValue("test");
            fail("UnsupportedOperationException should have been thrown.");
        } catch (UnsupportedOperationException ex) {
            assertEquals("containsValue(Object)", ex.getMessage());
        } catch (Throwable t) {
            fail("UnsupportedOperationException should have been thrown.");
        }
       
        try {
            c.keySet();
            fail("UnsupportedOperationException should have been thrown.");
        } catch (UnsupportedOperationException ex) {
            assertEquals("keySet()", ex.getMessage());
        } catch (Throwable t) {
            fail("UnsupportedOperationException should have been thrown.");
        }
       
        try {
            c.values();
            fail("UnsupportedOperationException should have been thrown.");
        } catch (UnsupportedOperationException ex) {
            assertEquals("values()", ex.getMessage());
        } catch (Throwable t) {
            fail("UnsupportedOperationException should have been thrown.");
        }
       
        try {
            c.entrySet();
            fail("UnsupportedOperationException should have been thrown.");
        } catch (UnsupportedOperationException ex) {
            assertEquals("entrySet()", ex.getMessage());
        } catch (Throwable t) {
            fail("UnsupportedOperationException should have been thrown.");
View Full Code Here

            fail("Failed to initialize OsCache instance");
        }
    }

    public void testClose() {
        Cache c = new OsCache(null);
        c.close();
    }
View Full Code Here

    public void testGet() {
        Logger logger = Logger.getLogger(OsCache.class);
        Level level = logger.getLevel();
       
        Cache c = initialize();
       
        if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }

        try {
            DistributedOsCacheMock.setException(new Exception("dummy"));
            c.get("first key");
            fail("Failed to trow exception at get() of OsCache instance");
        } catch (IllegalStateException ex) {
            assertTrue(true);
        }
       
        logger.setLevel(level);
       
        DistributedOsCacheMock.setException(null);
        int counter = DistributedOsCacheMock.getCounter();
        assertEquals("first value", c.get("first key"));
        assertEquals(counter + 1, DistributedOsCacheMock.getCounter());
        assertEquals("second value", c.get("second key"));
        assertEquals(counter + 2, DistributedOsCacheMock.getCounter());
        assertEquals("third value", c.get("third key"));
        assertEquals(counter + 3, DistributedOsCacheMock.getCounter());
        assertNull(c.get("fourth key"));
        assertEquals(counter + 4, DistributedOsCacheMock.getCounter());
        assertNull(c.get("fifth key"));
        assertEquals(counter + 5, DistributedOsCacheMock.getCounter());
    }
View Full Code Here

    public void testContainsKey() {
        Logger logger = Logger.getLogger(OsCache.class);
        Level level = logger.getLevel();
       
        Cache c = initialize();
       
        if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }

        try {
            DistributedOsCacheMock.setException(new Exception("dummy"));
            c.containsKey("first key");
            fail("Failed to trow exception at containsKey() of OsCache instance");
        } catch (IllegalStateException ex) {
            assertTrue(true);
        }
       
        logger.setLevel(level);
       
        DistributedOsCacheMock.setException(null);
        assertTrue(c.containsKey("first key"));
        assertTrue(c.containsKey("second key"));
        assertTrue(c.containsKey("third key"));
        assertFalse(c.containsKey("fourth key"));
        assertFalse(c.containsKey("fifth key"));
    }
View Full Code Here

    public void testPut() {
        Logger logger = Logger.getLogger(OsCache.class);
        Level level = logger.getLevel();
       
        Cache c = initialize();
       
        if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }

        try {
            DistributedOsCacheMock.setException(new Exception("dummy"));
            c.put("fourth key", "forth value");
            fail("Failed to trow exception at put() of OsCache instance");
        } catch (IllegalStateException ex) {
            DistributedOsCacheMock.setException(null);
            assertFalse(c.containsKey("fourth key"));
        }
       
        logger.setLevel(level);
       
        DistributedOsCacheMock.setException(null);
        assertEquals("third value", c.put("third key", "alternate third value"));
        assertNull(c.put("fourth key", "forth value"));

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

    public void testRemove() {
        Logger logger = Logger.getLogger(OsCache.class);
        Level level = logger.getLevel();
       
        Cache c = initialize();
       
        if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }

        try {
            DistributedOsCacheMock.setException(new Exception("dummy"));
            c.remove("third key");
            fail("Failed to trow exception at remove() of OsCache instance");
        } catch (IllegalStateException ex) {
            DistributedOsCacheMock.setException(null);
            assertTrue(c.containsKey("third key"));
        }
       
        logger.setLevel(level);
       
        DistributedOsCacheMock.setException(null);
        assertEquals("third value", c.remove("third key"));

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

    public void testPutAll() {
        Logger logger = Logger.getLogger(OsCache.class);
        Level level = logger.getLevel();
       
        Cache c = initialize();
       
        HashMap map = new HashMap();
        map.put("fourth key", "forth value");
        map.put("fifth key", "fifth value");
       
        if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }

        try {
            DistributedOsCacheMock.setException(new Exception("dummy"));
            c.putAll(map);
            fail("Failed to trow exception at put() of JcsCache instance");
        } catch (IllegalStateException ex) {
            DistributedOsCacheMock.setException(null);
            assertFalse(c.containsKey("fourth key"));
            assertFalse(c.containsKey("fifth key"));
        }
       
        logger.setLevel(level);
       
        DistributedOsCacheMock.setException(null);
        c.putAll(map);
        assertTrue(c.containsKey("first key"));
        assertTrue(c.containsKey("second key"));
        assertTrue(c.containsKey("third key"));
        assertTrue(c.containsKey("fourth key"));
        assertTrue(c.containsKey("fifth key"));
    }
View Full Code Here

    public void testClear() {
        Logger logger = Logger.getLogger(OsCache.class);
        Level level = logger.getLevel();
       
        Cache c = initialize();
       
        if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }

        try {
            DistributedOsCacheMock.setException(new Exception("dummy"));
            c.clear();
            fail("Failed to trow exception at clear() of JcsCache instance");
        } catch (IllegalStateException ex) {
            DistributedOsCacheMock.setException(null);
            assertTrue(c.containsKey("first key"));
            assertTrue(c.containsKey("second key"));
            assertTrue(c.containsKey("third key"));
            assertFalse(c.containsKey("fourth key"));
            assertFalse(c.containsKey("fifth key"));
        }
       
        logger.setLevel(level);
       
        DistributedOsCacheMock.setException(null);
        c.clear();

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

        assertEquals("ehcache", EHCache.TYPE);
        assertEquals("net.sf.ehcache.CacheManager", EHCache.IMPLEMENTATION);
    }

    public void testConstructor() throws Exception {
        Cache c = new EHCache();
        assertTrue(c instanceof EHCache);
    }
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.