Package org.apache.jackrabbit.core.data

Examples of org.apache.jackrabbit.core.data.CachingDataStore


        return dataStore;
    }

    private DataStore wrapInCachingDataStore(final DataStore dataStore, BlobStoreConfiguration config) throws Exception {
        CachingDataStore cachingStore = new CachingDataStore() {
            @Override
            protected Backend createBackend() {
                return new DataStoreWrapperBackend(dataStore);
            }

            @Override
            protected String getMarkerFile() {
                return "db.init.done";
            }
        };

        BeanUtils.populate(cachingStore, config.getConfigMap());
        cachingStore.init(null);

        return cachingStore;
    }
View Full Code Here


        }

    }
   
    private CachingDataStore createDataStore() throws RepositoryException {
        CachingDataStore ds = memoryBackend
                ? new InMemoryDataStore()
                : new S3DataStore();
        ds.setConfig(config);
        if (noCache) {
            ds.setCacheSize(0);
        }
        ds.init(TEST_DIR);
        return ds;
    }
View Full Code Here

    /**
     * Test {@link DataStore#addRecord(InputStream)} and assert length of added
     * record.
     */
    protected void doAddRecordTest() throws Exception {
        CachingDataStore ds = createDataStore();
        byte[] data = new byte[12345];
        new Random(12345).nextBytes(data);
        DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
        assertEquals(data.length, rec.getLength());
        assertRecord(data, rec);
        ds.close();
    }
View Full Code Here

    /**
     * Test {@link DataStore#getRecord(DataIdentifier)} and assert length and
     * inputstream.
     */
    protected void doGetRecordTest() throws Exception {
        CachingDataStore ds = createDataStore();
        byte[] data = new byte[12345];
        new Random(12345).nextBytes(data);
        DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
        rec = ds.getRecord(rec.getIdentifier());
        assertEquals(data.length, rec.getLength());
        assertRecord(data, rec);
        ds.close();
    }
View Full Code Here

    /**
     * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
     */
    protected void doDeleteRecordTest() throws Exception {
        CachingDataStore ds = createDataStore();
        Random random = new Random(12345);
        byte[] data1 = new byte[12345];
        random.nextBytes(data1);
        DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));

        byte[] data2 = new byte[12345];
        random.nextBytes(data2);
        DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));

        byte[] data3 = new byte[12345];
        random.nextBytes(data3);
        DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));

        ds.deleteRecord(rec2.getIdentifier());

        assertNull("rec2 should be null",
            ds.getRecordIfStored(rec2.getIdentifier()));
        assertEquals(new ByteArrayInputStream(data1),
            ds.getRecord(rec1.getIdentifier()).getStream());
        assertEquals(new ByteArrayInputStream(data3),
            ds.getRecord(rec3.getIdentifier()).getStream());
        ds.close();
    }
View Full Code Here

    /**
     * Test {@link DataStore#getAllIdentifiers()} and asserts all identifiers
     * are returned.
     */
    protected void doGetAllIdentifiersTest() throws Exception {
        CachingDataStore ds = createDataStore();
        List<DataIdentifier> list = new ArrayList<DataIdentifier>();
        Random random = new Random(12345);
        byte[] data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
        list.add(rec.getIdentifier());

        data = new byte[12345];
        random.nextBytes(data);
        rec = ds.addRecord(new ByteArrayInputStream(data));
        list.add(rec.getIdentifier());

        data = new byte[12345];
        random.nextBytes(data);
        rec = ds.addRecord(new ByteArrayInputStream(data));
        list.add(rec.getIdentifier());

        Iterator<DataIdentifier> itr = ds.getAllIdentifiers();
        while (itr.hasNext()) {
            assertTrue("record found on list", list.remove(itr.next()));
        }
        assertEquals(0, list.size());
        ds.close();
    }
View Full Code Here

    /**
     * Asserts that timestamp of all records accessed after
     * {@link DataStore#updateModifiedDateOnAccess(long)} invocation.
     */
    protected void doUpdateLastModifiedOnAccessTest() throws Exception {
        CachingDataStore ds = createDataStore();
        Random random = new Random(12345);
        byte[] data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data));

        data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data));

        Thread.sleep(1000);
        long updateTime = System.currentTimeMillis();
        ds.updateModifiedDateOnAccess(updateTime);
        Thread.sleep(1000);
        data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data));

        data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec4 = ds.addRecord(new ByteArrayInputStream(data));

        rec1 = ds.getRecord(rec1.getIdentifier());

        assertEquals("rec1 touched", true,
            ds.getLastModified(rec1.getIdentifier()) > updateTime);
        assertEquals("rec2 not touched", true,
            ds.getLastModified(rec2.getIdentifier()) < updateTime);
        assertEquals("rec3 touched", true,
            ds.getLastModified(rec3.getIdentifier()) > updateTime);
        assertEquals("rec4 touched", true,
            ds.getLastModified(rec4.getIdentifier()) > updateTime);
        ds.close();

    }
View Full Code Here

    /**
     * Asserts that {@link DataStore#deleteAllOlderThan(long)} only deleted
     * records older than argument passed.
     */
    protected void doDeleteAllOlderThan() throws Exception {
        CachingDataStore ds = createDataStore();
        Random random = new Random(12345);
        byte[] data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data));

        data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data));
       
        Thread.sleep(2000);
        long updateTime = System.currentTimeMillis();
        ds.updateModifiedDateOnAccess(updateTime);

        data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data));

        data = new byte[12345];
        random.nextBytes(data);
        DataRecord rec4 = ds.addRecord(new ByteArrayInputStream(data));

        rec1 = ds.getRecord(rec1.getIdentifier());
        ds.clearInUse();
        assertEquals("only rec2 should be deleted", 1,
            ds.deleteAllOlderThan(updateTime));
        assertNull("rec2 should be null",
            ds.getRecordIfStored(rec2.getIdentifier()));

        Iterator<DataIdentifier> itr = ds.getAllIdentifiers();
        List<DataIdentifier> list = new ArrayList<DataIdentifier>();
        list.add(rec1.getIdentifier());
        list.add(rec3.getIdentifier());
        list.add(rec4.getIdentifier());
        while (itr.hasNext()) {
            assertTrue("record found on list", list.remove(itr.next()));
        }

        assertEquals("touched records found", 0, list.size());
        assertEquals("rec1 touched", true,
            ds.getLastModified(rec1.getIdentifier()) > updateTime);
        assertEquals("rec3 touched", true,
            ds.getLastModified(rec3.getIdentifier()) > updateTime);
        assertEquals("rec4 touched", true,
            ds.getLastModified(rec4.getIdentifier()) > updateTime);
        ds.close();

    }
View Full Code Here

    /**
     * Test if record can be accessed via
     * {@link DataStore#getRecordFromReference(String)}
     */
    public void doReferenceTest() throws Exception {
        CachingDataStore ds = createDataStore();
        ds.setSecret("12345");
        byte[] data = new byte[12345];
        new Random(12345).nextBytes(data);
        String reference;
        DataRecord record = ds.addRecord(new ByteArrayInputStream(data));
        reference = record.getReference();
        assertReference(data, reference, ds);
        ds.close();
    }
View Full Code Here

    /**
     * Method to validate mixed scenario use of {@link DataStore}.
     */
    protected void doTestSingleThread() throws Exception {
        CachingDataStore ds = createDataStore();
        doTestMultiThreaded(ds, 1);
        ds.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.data.CachingDataStore

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.