Package org.apache.jackrabbit.core.data

Examples of org.apache.jackrabbit.core.data.LocalCache$PurgeJob


    /**
     * Test to validate store retrieve in cache.
     */
    public void testStoreRetrieve() {
        try {
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70);
            Random random = new Random(12345);
            byte[] data = new byte[100];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a3", data);

            cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
            cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
            cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }

View Full Code Here


     * cachePurgeTrigFactor * size.
     */
    public void testAutoPurge() {
        try {

            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70);
            Random random = new Random(12345);
            byte[] data = new byte[100];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a3", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a4", data);

            cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
            cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
            cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));

            data = new byte[90];
            random.nextBytes(data);
            byteMap.put("a4", data);
            // storing a4 should purge cache
            cache.store("a4", new ByteArrayInputStream(byteMap.get("a4")));
            Thread.sleep(1000);

            assertNull("a1 should be null", cache.getIfStored("a1"));
            assertNull("a2 should be null", cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a4")),
                cache.getIfStored("a4"));
            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a5", data);
            cache.store("a5", new ByteArrayInputStream(byteMap.get("a5")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

    public void testStoreRetrieve() {
        try {
            AsyncUploadCache pendingFiles = new AsyncUploadCache();
            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
            pendingFiles.reset();
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70, pendingFiles);
            Random random = new Random(12345);
            byte[] data = new byte[100];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a3", data);

            cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
            cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
            cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

    public void testAutoPurge() {
        try {
            AsyncUploadCache pendingFiles = new AsyncUploadCache();
            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
            pendingFiles.reset();
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70, pendingFiles);
            Random random = new Random(12345);
            byte[] data = new byte[100];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a3", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a4", data);

            cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
            cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
            cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));

            data = new byte[90];
            random.nextBytes(data);
            byteMap.put("a4", data);
            // storing a4 should purge cache
            cache.store("a4", new ByteArrayInputStream(byteMap.get("a4")));
            Thread.sleep(1000);
            assertNull("a1 should be null", cache.getIfStored("a1"));
            assertNull("a2 should be null", cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a4")),
                cache.getIfStored("a4"));
            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a5", data);
            cache.store("a5", new ByteArrayInputStream(byteMap.get("a5")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

    public void testAutoPurgeWithPendingUpload() {
        try {
            AsyncUploadCache pendingFiles = new AsyncUploadCache();
            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
            pendingFiles.reset();
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70, pendingFiles);
            Random random = new Random(12345);
            byte[] data = new byte[125];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[125];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[125];
            random.nextBytes(data);
            byteMap.put("a3", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a4", data);
            File tempDir = new File(TEMP_DIR);
            File f = File.createTempFile("test", "tmp", tempDir);
            FileOutputStream fos = new FileOutputStream(f);
            fos.write(byteMap.get("a1"));
            fos.close();
            AsyncUploadCacheResult result = cache.store("a1", f, true);
            assertTrue("should be able to add to pending upload",
                result.canAsyncUpload());

            f = File.createTempFile("test", "tmp", tempDir);
            fos = new FileOutputStream(f);
            fos.write(byteMap.get("a2"));
            fos.close();
            result = cache.store("a2", f, true);
            assertTrue("should be able to add to pending upload",
                result.canAsyncUpload());

            f = File.createTempFile("test", "tmp", tempDir);
            fos = new FileOutputStream(f);
            fos.write(byteMap.get("a3"));
            fos.close();
            result = cache.store("a3", f, true);
            assertTrue("should be able to add to pending upload",
                result.canAsyncUpload());

            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));

            data = new byte[90];
            random.nextBytes(data);
            byteMap.put("a4", data);

            f = File.createTempFile("test", "tmp", tempDir);
            fos = new FileOutputStream(f);
            fos.write(byteMap.get("a4"));
            fos.close();

            result = cache.store("a4", f, true);
            assertFalse("should not be able to add to pending upload",
                result.canAsyncUpload());
            Thread.sleep(1000);

            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
            assertNull("a4 should be null", cache.getIfStored("a4"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

        }
        try {
            AsyncUploadCache pendingFiles = new AsyncUploadCache();
            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
            pendingFiles.reset();
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70, pendingFiles);
            Random random = new Random(12345);
            byte[] data = new byte[100];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a3", data);

            cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
            cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
            cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

        }
        try {
            AsyncUploadCache pendingFiles = new AsyncUploadCache();
            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
            pendingFiles.reset();
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70, pendingFiles);
            Random random = new Random(12345);
            byte[] data = new byte[100];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a3", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a4", data);

            cache.store("a1", new ByteArrayInputStream(byteMap.get("a1")));
            cache.store("a2", new ByteArrayInputStream(byteMap.get("a2")));
            cache.store("a3", new ByteArrayInputStream(byteMap.get("a3")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));

            data = new byte[90];
            random.nextBytes(data);
            byteMap.put("a4", data);
            // storing a4 should purge cache
            cache.store("a4", new ByteArrayInputStream(byteMap.get("a4")));
            Thread.sleep(1000);
            assertNull("a1 should be null", cache.getIfStored("a1"));
            assertNull("a2 should be null", cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a4")),
                cache.getIfStored("a4"));
            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a5", data);
            cache.store("a5", new ByteArrayInputStream(byteMap.get("a5")));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

        }
        try {
            AsyncUploadCache pendingFiles = new AsyncUploadCache();
            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
            pendingFiles.reset();
            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
                0.70, pendingFiles);
            Random random = new Random(12345);
            byte[] data = new byte[125];
            Map<String, byte[]> byteMap = new HashMap<String, byte[]>();
            random.nextBytes(data);
            byteMap.put("a1", data);

            data = new byte[125];
            random.nextBytes(data);
            byteMap.put("a2", data);

            data = new byte[125];
            random.nextBytes(data);
            byteMap.put("a3", data);

            data = new byte[100];
            random.nextBytes(data);
            byteMap.put("a4", data);
            File tempDir = new File(TEMP_DIR);
            File f = File.createTempFile("test", "tmp", tempDir);
            FileOutputStream fos = new FileOutputStream(f);
            fos.write(byteMap.get("a1"));
            fos.close();
            AsyncUploadCacheResult result = cache.store("a1", f, true);
            assertTrue("should be able to add to pending upload",
                result.canAsyncUpload());

            f = File.createTempFile("test", "tmp", tempDir);
            fos = new FileOutputStream(f);
            fos.write(byteMap.get("a2"));
            fos.close();
            result = cache.store("a2", f, true);
            assertTrue("should be able to add to pending upload",
                result.canAsyncUpload());

            f = File.createTempFile("test", "tmp", tempDir);
            fos = new FileOutputStream(f);
            fos.write(byteMap.get("a3"));
            fos.close();
            result = cache.store("a3", f, true);
            assertTrue("should be able to add to pending upload",
                result.canAsyncUpload());

            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));

            data = new byte[90];
            random.nextBytes(data);
            byteMap.put("a4", data);

            f = File.createTempFile("test", "tmp", tempDir);
            fos = new FileOutputStream(f);
            fos.write(byteMap.get("a4"));
            fos.close();

            result = cache.store("a4", f, true);
            assertFalse("should not be able to add to pending upload",
                result.canAsyncUpload());
            Thread.sleep(1000);

            assertEquals(new ByteArrayInputStream(byteMap.get("a1")),
                cache.getIfStored("a1"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a2")),
                cache.getIfStored("a2"));
            assertEquals(new ByteArrayInputStream(byteMap.get("a3")),
                cache.getIfStored("a3"));
            assertNull("a4 should be null", cache.getIfStored("a4"));
        } catch (Exception e) {
            LOG.error("error:", e);
            fail();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.data.LocalCache$PurgeJob

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.