Search in sources :

Example 41 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class LengthCachingDataStoreTest method mappingFileData.

@Test
public void mappingFileData() throws Exception {
    File root = tempFolder.getRoot();
    File mappingFile = new File(root, "mapping.txt");
    String text = "1000|foo\n2000|bar";
    Files.write(text, mappingFile, Charset.defaultCharset());
    LengthCachingDataStore fds = new LengthCachingDataStore();
    fds.setDelegateClass(FileDataStore.class.getName());
    fds.setMappingFilePath(mappingFile.getAbsolutePath());
    fds.init(tempFolder.getRoot().getAbsolutePath());
    DataRecord dr = fds.getRecord(new DataIdentifier("foo"));
    assertNotNull(dr);
    assertEquals(1000, dr.getLength());
    assertEquals(2000, fds.getRecord(new DataIdentifier("bar")).getLength());
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) Test(org.junit.Test)

Example 42 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class LengthCachingDataStoreTest method writeBackNewEntries.

@Test
public void writeBackNewEntries() throws Exception {
    //1. Add some entries to FDS
    FileDataStore fds1 = new FileDataStore();
    File fds1Dir = tempFolder.newFolder();
    int minSize = fds1.getMinRecordLength();
    fds1.init(fds1Dir.getAbsolutePath());
    DataRecord dr1 = fds1.addRecord(byteStream(minSize + 10));
    DataRecord dr2 = fds1.addRecord(byteStream(minSize + 100));
    //2. Try reading them so as to populate the new mappings
    LengthCachingDataStore fds2 = new LengthCachingDataStore();
    fds2.setDelegateClass(FileDataStore.class.getName());
    fds2.init(fds1Dir.getAbsolutePath());
    fds2.getRecord(new DataIdentifier(dr1.getIdentifier().toString()));
    fds2.getRecord(new DataIdentifier(dr2.getIdentifier().toString()));
    File mappingFile = fds2.getMappingFile();
    //3. Get the mappings pushed to file
    fds2.close();
    //4. Open a new FDS pointing to new directory. Read should still work fine
    //as they would be served by the mapping data
    LengthCachingDataStore fds3 = new LengthCachingDataStore();
    fds3.setDelegateClass(FileDataStore.class.getName());
    fds3.setMappingFilePath(mappingFile.getAbsolutePath());
    fds3.init(tempFolder.newFolder().getAbsolutePath());
    fds3.setReadOnly(false);
    assertEquals(dr1.getLength(), fds3.getRecord(dr1.getIdentifier()).getLength());
    assertEquals(dr2.getLength(), fds3.getRecord(dr2.getIdentifier()).getLength());
    DataRecord dr3 = fds3.addRecord(byteStream(minSize + 200));
    //5. Close again so see if update of existing file works
    fds3.close();
    LengthCachingDataStore fds4 = new LengthCachingDataStore();
    fds4.setDelegateClass(FileDataStore.class.getName());
    fds4.setMappingFilePath(mappingFile.getAbsolutePath());
    fds4.init(tempFolder.newFolder().getAbsolutePath());
    assertEquals(dr3.getLength(), fds4.getRecord(dr3.getIdentifier()).getLength());
    assertEquals(dr2.getLength(), fds4.getRecord(dr2.getIdentifier()).getLength());
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) File(java.io.File) Test(org.junit.Test)

Example 43 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class SafeDataStoreBlobStore method getStream.

@Override
protected InputStream getStream(String blobId) throws IOException {
    try {
        DataRecord record = getDataRecord(blobId);
        if (record == null) {
            log.warn("No blob found for id [{}]", blobId);
            return new ByteArrayInputStream(new byte[0]);
        }
        InputStream in = getDataRecord(blobId).getStream();
        if (!(in instanceof BufferedInputStream)) {
            in = new BufferedInputStream(in);
        }
        return StatsCollectingStreams.wrap(stats, blobId, in);
    } catch (DataStoreException e) {
        throw new IOException(e);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InMemoryDataRecord(org.apache.jackrabbit.oak.plugins.blob.datastore.InMemoryDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord) IOException(java.io.IOException)

Example 44 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class LengthCachingDataStore method getRecordIfStored.

@Override
public DataRecord getRecordIfStored(DataIdentifier dataIdentifier) throws DataStoreException {
    if (existingMappings.containsKey(dataIdentifier.toString())) {
        return new DelegateDataRecord(this, dataIdentifier, existingMappings);
    } else if (newMappings.containsKey(dataIdentifier.toString())) {
        return new DelegateDataRecord(this, dataIdentifier, newMappings);
    }
    DataRecord result = getDelegate().getRecordIfStored(dataIdentifier);
    addNewMapping(result);
    return result;
}
Also used : AbstractDataRecord(org.apache.jackrabbit.core.data.AbstractDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 45 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class TestS3DataStore method testAlternateBucketProp.

@Test
public void testAlternateBucketProp() throws Exception {
    assumeTrue(isS3Configured());
    Random randomGen = new Random();
    props = S3DataStoreUtils.getS3Config();
    //Replace bucket in props with container
    String bucket = props.getProperty(S3Constants.S3_BUCKET);
    props.remove(S3Constants.S3_BUCKET);
    props.put(S3Constants.S3_CONTAINER, bucket);
    ds = getS3DataStore(s3Class, props, dataStoreDir.getAbsolutePath());
    byte[] data = new byte[4096];
    randomGen.nextBytes(data);
    DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
    assertEquals(data.length, rec.getLength());
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Test(org.junit.Test)

Aggregations

DataRecord (org.apache.jackrabbit.core.data.DataRecord)76 Test (org.junit.Test)43 ByteArrayInputStream (java.io.ByteArrayInputStream)34 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)30 File (java.io.File)24 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)19 FileInputStream (java.io.FileInputStream)16 Random (java.util.Random)12 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)6 IOException (java.io.IOException)4 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)4 Function (com.google.common.base.Function)3 SequenceInputStream (java.io.SequenceInputStream)3 RepositoryException (javax.jcr.RepositoryException)3 DataStore (org.apache.jackrabbit.core.data.DataStore)3 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2