Package org.apache.chemistry.opencmis.client.bindings.cache

Examples of org.apache.chemistry.opencmis.client.bindings.cache.Cache


        // no keys
        assertNull(cache.get((String[]) null));
    }

    public void testCacheConfig() throws Exception {
        Cache cache;

        // empty config
        try {
            cache = new CacheImpl();
            cache.initialize(new String[] {});
        } catch (IllegalArgumentException e) {
        }

        // null config
        try {
            cache = new CacheImpl();
            cache.initialize(null);
        } catch (IllegalArgumentException e) {
        }

        // unknown class
        try {
            cache = new CacheImpl();
            cache.initialize(new String[] { "this.is.not.a.valid.class" });
        } catch (IllegalArgumentException e) {
        }

        // not a CacheLevel class
        try {
            cache = new CacheImpl();
            cache.initialize(new String[] { "org.apache.chemistry.opencmis.client.provider.cache.CacheTest" });
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here


        } catch (IllegalArgumentException e) {
        }
    }

    public void testMapCache() throws Exception {
        Cache cache;

        cache = new CacheImpl();
        cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10,"
                + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" });

        for (int i = 0; i < 100; i++) {
            cache.put("value" + i, "key" + i);
        }

        for (int i = 0; i < 100; i++) {
            Object valueObj = cache.get("key" + i);
            assertTrue(valueObj instanceof String);
            assertEquals("value" + i, valueObj);
        }
    }
View Full Code Here

            assertEquals("value" + i, valueObj);
        }
    }

    public void testURLCache() throws Exception {
        Cache cache;

        cache = new CacheImpl();
        cache.initialize(new String[] { LRU_CACHE_LEVEL + " " + LruCacheLevelImpl.MAX_ENTRIES + "=10" });

        for (int i = 0; i < 100; i++) {
            cache.put("value" + i, "key" + i);
        }

        for (int i = 0; i < 90; i++) {
            Object valueObj = cache.get("key" + i);
            assertNull(valueObj);
        }

        for (int i = 90; i < 100; i++) {
            Object valueObj = cache.get("key" + i);
            assertTrue(valueObj instanceof String);
            assertEquals("value" + i, valueObj);
        }
    }
View Full Code Here

            assertEquals("value" + i, valueObj);
        }
    }

    public void XtestFallback() throws Exception {
        Cache cache;

        cache = new CacheImpl();
        cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10,"
                + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" });

        cache.put("value1", new String[] { null });
        cache.put("value2", "key2");

        assertEquals("value1", cache.get(new String[] { null }));
        assertEquals("value2", cache.get("key2"));
        assertEquals("value1", cache.get("key3"));
    }
View Full Code Here

    public final static String MAP_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl";
    public final static String LRU_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl";

    public void testCache() throws Exception {
        Cache cache;

        cache = new CacheImpl();
        cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL, MAP_CACHE_LEVEL });

        String value1 = "value1";
        String value2 = "value2";
        String value3 = "value3";
        Object valueObj;

        // put and get
        cache.put(value1, "l1", "l2a", "l3", "l4");
        cache.put(value2, "l1", "l2b", "l3", "l4");
        cache.put(value3, "l1", "l2c", "l3", "l4");

        valueObj = cache.get("l1", "l2a", "l3", "l4");
        assertTrue(valueObj instanceof String);
        assertTrue(value1 == valueObj);

        valueObj = cache.get("l1", "l2b", "l3", "l4");
        assertTrue(valueObj instanceof String);
        assertTrue(value2 == valueObj);

        valueObj = cache.get("l1", "l2c", "l3", "l4");
        assertTrue(valueObj instanceof String);
        assertTrue(value3 == valueObj);

        // remove leaf
        cache.remove("l1", "l2", "l3", "l4");
        valueObj = cache.get("l1", "l2", "l3", "l4");
        assertNull(valueObj);

        // put and get
        cache.put(value1, "l1", "l2", "l3", "l4");
        valueObj = cache.get("l1", "l2", "l3", "l4");
        assertTrue(valueObj instanceof String);
        assertTrue(value1 == valueObj);

        // remove branch
        cache.remove("l1", "l2");
        valueObj = cache.get("l1", "l2", "l3", "l4");
        assertNull(valueObj);
    }
View Full Code Here

        valueObj = cache.get("l1", "l2", "l3", "l4");
        assertNull(valueObj);
    }

    public void testCacheBadUsage() throws Exception {
        Cache cache;

        cache = new CacheImpl();
        cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL, MAP_CACHE_LEVEL });

        // insufficient number of keys
        try {
            cache.put("value", "l1", "l2", "l3");
        } catch (IllegalArgumentException e) {
        }

        // too many number of keys
        try {
            cache.put("value", "l1", "l2", "l3", "l4", "l5");
        } catch (IllegalArgumentException e) {
        }

        // no keys
        assertNull(cache.get((String[]) null));
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.client.bindings.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.