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

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


    public void setup() {
    }

    @Test
    public void cacheSingleObjectTest() {
        Cache cache = CacheImpl.newInstance();

        String id = "1";
        // String path = "/1";
        String cacheKey = "key";

        // add object
        CmisObject obj1 = this.createCmisObject(id);
        cache.put(obj1, cacheKey);

        // access object
        Assert.assertTrue(cache.containsId(id, cacheKey));

        // access object
        CmisObject obj2 = cache.getById(id, cacheKey);
        Assert.assertEquals(obj1, obj2);

        // clear cache
        cache.clear();

        // access object (not found)
        Assert.assertFalse(cache.containsId(id, cacheKey));

        // access object (not found)
        CmisObject obj4 = cache.getById(id, cacheKey);
        Assert.assertNull(obj4);
    }
View Full Code Here


    }

    @Test
    public void cacheSizeTest() {
        int cacheSize = 50000;
        Cache cache = CacheImpl.newInstance(cacheSize);
        Assert.assertEquals(cacheSize, cache.getCacheSize());
    }
View Full Code Here

    }

    @Test
    public void lruTest() {
        int cacheSize = 3;
        Cache cache = CacheImpl.newInstance(cacheSize);

        String cacheKey = "key";

        for (int i = 0; i < cacheSize + 1; i++) {
            CmisObject obj = this.createCmisObject("id" + i);
            cache.put(obj, cacheKey);
        }

        Assert.assertNull(cache.getById("id0", cacheKey)); // thrown out
        Assert.assertNotNull(cache.getById("id1", cacheKey));
        Assert.assertNotNull(cache.getById("id2", cacheKey));
        Assert.assertNotNull(cache.getById("id3", cacheKey));
    }
View Full Code Here

    }

    @Test
    public void serializationTest() throws IOException, ClassNotFoundException {
        int cacheSize = 10;
        Cache cache = CacheImpl.newInstance(cacheSize);

        String cacheKey = "key";

        for (int i = 0; i < cacheSize; i++) {
            CmisObject obj = this.createCmisObject("id" + i);
            cache.put(obj, cacheKey);
        }

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(buffer);
        out.writeObject(cache);
        out.close();

        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        Cache cache2 = (Cache) in.readObject();
        in.close();

        for (int k = 0; k < cacheSize; k++) {
            CmisObject o1 = cache.getById("id" + k, cacheKey);
            CmisObject o2 = cache2.getById("id" + k, cacheKey);
            Assert.assertEquals(o1.getId(), o2.getId());
        }

    }
View Full Code Here

    public void setup() {
    }

    @Test
    public void cacheSingleObjectTest() {
        Cache cache = createCache(100, 3600 * 1000);

        String id = "1";
        // String path = "/1";
        String cacheKey = "key";

        // add object
        CmisObject obj1 = this.createCmisObject(id);
        cache.put(obj1, cacheKey);

        // access object
        Assert.assertTrue(cache.containsId(id, cacheKey));

        // access object
        CmisObject obj2 = cache.getById(id, cacheKey);
        Assert.assertEquals(obj1, obj2);

        // clear cache
        cache.clear();

        // access object (not found)
        Assert.assertFalse(cache.containsId(id, cacheKey));

        // access object (not found)
        CmisObject obj4 = cache.getById(id, cacheKey);
        Assert.assertNull(obj4);
    }
View Full Code Here

    }

    @Test
    public void cacheSizeTest() {
        int cacheSize = 50000;
        Cache cache = createCache(cacheSize, 3600 * 1000);
        Assert.assertEquals(cacheSize, cache.getCacheSize());
    }
View Full Code Here

    }

    @Test
    public void lruTest() {
        int cacheSize = 3;
        Cache cache = createCache(cacheSize, 3600 * 1000);

        String cacheKey = "key";

        for (int i = 0; i < cacheSize + 1; i++) {
            CmisObject obj = this.createCmisObject("id" + i);
            cache.put(obj, cacheKey);
        }

        Assert.assertNull(cache.getById("id0", cacheKey)); // thrown out
        Assert.assertNotNull(cache.getById("id1", cacheKey));
        Assert.assertNotNull(cache.getById("id2", cacheKey));
        Assert.assertNotNull(cache.getById("id3", cacheKey));
    }
View Full Code Here

    }

    @SuppressWarnings("static-access")
    @Test
    public void ttlTest() throws InterruptedException {
        Cache cache = createCache(10, 500);

        String cacheKey = "key";
        String id = "id";

        CmisObject obj = this.createCmisObject(id);
        cache.put(obj, cacheKey);

        Assert.assertNotNull(cache.getById(id, cacheKey));

        Thread.currentThread().sleep(501);

        Assert.assertNull(cache.getById(id, cacheKey));
    }
View Full Code Here

    }

    @Test
    public void serializationTest() throws IOException, ClassNotFoundException {
        int cacheSize = 10;
        Cache cache = createCache(cacheSize, 3600 * 1000);

        String cacheKey = "key";

        for (int i = 0; i < cacheSize; i++) {
            CmisObject obj = this.createCmisObject("id" + i);
            cache.put(obj, cacheKey);
        }

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(buffer);
        out.writeObject(cache);
        out.close();

        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        Cache cache2 = (Cache) in.readObject();
        in.close();

        for (int k = 0; k < cacheSize; k++) {
            CmisObject o1 = cache.getById("id" + k, cacheKey);
            CmisObject o2 = cache2.getById("id" + k, cacheKey);
            Assert.assertEquals(o1.getId(), o2.getId());
        }
    }
View Full Code Here

    private CmisObject createCmisObject(final String id) {
        return new CmisObjectMock(id);
    }

    private Cache createCache(int cacheSize, int ttl) {
        Cache cache = new CacheImpl();

        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put(SessionParameter.CACHE_SIZE_OBJECTS, "" + cacheSize);
        parameters.put(SessionParameter.CACHE_TTL_OBJECTS, "" + ttl);

        cache.initialize(null, parameters);

        return cache;
    }
View Full Code Here

TOP

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