Search in sources :

Example 36 with DataRecord

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

the class CachingDataStoreTest method zeroCacheAddGetDelete.

/**
     * Add, get, delete when zero cache size.
     * @throws Exception
     */
@Test
public void zeroCacheAddGetDelete() throws Exception {
    LOG.info("Starting zeroCacheAddGetDelete");
    dataStore.close();
    init(1, 0, 0);
    File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
    String id = getIdForInputStream(f);
    FileInputStream fin = new FileInputStream(f);
    closer.register(fin);
    DataRecord rec = dataStore.addRecord(fin);
    assertEquals(id, rec.getIdentifier().toString());
    assertFile(rec.getStream(), f, folder);
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertEquals(id, rec.getIdentifier().toString());
    assertFile(rec.getStream(), f, folder);
    assertEquals(1, Iterators.size(dataStore.getAllIdentifiers()));
    dataStore.deleteRecord(new DataIdentifier(id));
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    LOG.info("Finished zeroCacheAddGetDelete");
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 37 with DataRecord

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

the class AbstractDataStoreTest method doDeleteRecordTest.

/**
     * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
     */
protected void doDeleteRecordTest() throws Exception {
    Random random = randomGen;
    byte[] data1 = new byte[dataLength];
    random.nextBytes(data1);
    DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));
    byte[] data2 = new byte[dataLength];
    random.nextBytes(data2);
    DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));
    byte[] data3 = new byte[dataLength];
    random.nextBytes(data3);
    DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));
    ((MultiDataStoreAware) ds).deleteRecord(rec1.getIdentifier());
    assertNull("rec1 should be null", ds.getRecordIfStored(rec1.getIdentifier()));
    assertEquals(new ByteArrayInputStream(data2), ds.getRecord(rec2.getIdentifier()).getStream());
    assertEquals(new ByteArrayInputStream(data3), ds.getRecord(rec3.getIdentifier()).getStream());
}
Also used : MultiDataStoreAware(org.apache.jackrabbit.core.data.MultiDataStoreAware) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 38 with DataRecord

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

the class LengthCachingDataStore method addRecord.

@Override
public DataRecord addRecord(InputStream inputStream) throws DataStoreException {
    checkIfReadOnly();
    DataRecord result = getDelegate().addRecord(inputStream);
    addNewMapping(result);
    return result;
}
Also used : AbstractDataRecord(org.apache.jackrabbit.core.data.AbstractDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 39 with DataRecord

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

the class SafeDataStoreBlobStore method getReference.

@Override
public String getReference(@Nonnull String encodedBlobId) {
    checkNotNull(encodedBlobId);
    String blobId = extractBlobId(encodedBlobId);
    //Reference are not created for in memory record
    if (InMemoryDataRecord.isInstance(blobId)) {
        return null;
    }
    DataRecord record;
    try {
        record = delegate.getRecordIfStored(new DataIdentifier(blobId));
        if (record != null) {
            return record.getReference();
        } else {
            log.debug("No blob found for id [{}]", blobId);
        }
    } catch (DataStoreException e) {
        log.warn("Unable to access the blobId for  [{}]", blobId, e);
    }
    return null;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) InMemoryDataRecord(org.apache.jackrabbit.oak.plugins.blob.datastore.InMemoryDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 40 with DataRecord

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

the class TestS3DSWithSSES3 method testDataMigration.

/**
     * Test data migration enabling SSE_S3 encryption.
     */
public void testDataMigration() {
    try {
        String bucket = props.getProperty(S3Constants.S3_BUCKET);
        S3DataStore s3ds = new S3DataStore();
        s3ds.setProperties(props);
        s3ds.setCacheSize(0);
        s3ds.init(dataStoreDir);
        byte[] data = new byte[dataLength];
        randomGen.nextBytes(data);
        DataRecord rec = s3ds.addRecord(new ByteArrayInputStream(data));
        assertEquals(data.length, rec.getLength());
        assertRecord(data, rec);
        s3ds.close();
        // turn encryption now.
        props.setProperty(S3Constants.S3_BUCKET, bucket);
        props.setProperty(S3Constants.S3_ENCRYPTION, S3Constants.S3_ENCRYPTION_SSE_S3);
        props.setProperty(S3Constants.S3_RENAME_KEYS, "true");
        s3ds = new S3DataStore();
        s3ds.setProperties(props);
        s3ds.setCacheSize(0);
        s3ds.init(dataStoreDir);
        rec = s3ds.getRecord(rec.getIdentifier());
        assertEquals(data.length, rec.getLength());
        assertRecord(data, rec);
        randomGen.nextBytes(data);
        rec = s3ds.addRecord(new ByteArrayInputStream(data));
        s3ds.close();
    } catch (Exception e) {
        LOG.error("error:", e);
        fail(e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

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