Search in sources :

Example 11 with DataRecord

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

the class DataStoreBlobStore method getDataRecord.

protected DataRecord getDataRecord(String blobId) throws DataStoreException {
    DataRecord id;
    if (InMemoryDataRecord.isInstance(blobId)) {
        id = InMemoryDataRecord.getInstance(blobId);
    } else {
        id = delegate.getRecord(new DataIdentifier(blobId));
    }
    checkNotNull(id, "No DataRecord found for blobId [%s]", blobId);
    return id;
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 12 with DataRecord

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

the class S3DataStoreStatsTest method testGetMultilpleActiveS3FileSyncMetric.

@Test
public void testGetMultilpleActiveS3FileSyncMetric() throws Exception {
    stats = new S3DataStoreStats();
    stats.nodeStore = nodeStore;
    stats.s3ds = manualSyncMockS3ds;
    final Set<DataRecord> records = Sets.newHashSet();
    try {
        records.add(manualSyncMockS3ds.addRecord(getStream("test1")));
        records.add(manualSyncMockS3ds.addRecord(getStream("test2")));
        records.add(manualSyncMockS3ds.addRecord(getStream("test3")));
        assertTrue(3 == stats.getActiveSyncs());
    } finally {
        for (final DataRecord record : records) {
            manualSyncMockS3ds.deleteRecord(record.getIdentifier());
        }
    }
    ((ManuallySyncingInMemoryBackend) manualSyncMockS3ds.getBackend()).clearInProgressWrites();
    assertTrue(0 == stats.getActiveSyncs());
}
Also used : DataRecord(org.apache.jackrabbit.core.data.DataRecord) Test(org.junit.Test)

Example 13 with DataRecord

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

the class AbstractDataStoreTest method doAddRecordTest.

/**
     * Test {@link DataStore#addRecord(InputStream)} and assert length of added
     * record.
     */
protected void doAddRecordTest() throws Exception {
    byte[] data = new byte[dataLength];
    randomGen.nextBytes(data);
    DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
    Assert.assertEquals(data.length, rec.getLength());
    assertRecord(data, rec);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 14 with DataRecord

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

the class AbstractDataStoreTest method doTest.

/**
     * Assert randomly read stream from record.
     */
void doTest(DataStore ds, int offset) throws Exception {
    ArrayList<DataRecord> list = new ArrayList<DataRecord>();
    HashMap<DataRecord, Integer> map = new HashMap<DataRecord, Integer>();
    for (int i = 0; i < 10; i++) {
        int size = 100000 - (i * 100);
        RandomInputStream in = new RandomInputStream(size + offset, size);
        DataRecord rec = ds.addRecord(in);
        list.add(rec);
        map.put(rec, size);
    }
    Random random = new Random(1);
    for (int i = 0; i < list.size(); i++) {
        int pos = random.nextInt(list.size());
        DataRecord rec = list.get(pos);
        int size = map.get(rec);
        rec = ds.getRecord(rec.getIdentifier());
        Assert.assertEquals(size, rec.getLength());
        RandomInputStream expected = new RandomInputStream(size + offset, size);
        InputStream in = rec.getStream();
        // Workaround for race condition that can happen with low cache size relative to the test
        // read immediately
        byte[] buffer = new byte[1];
        in.read(buffer);
        in = new SequenceInputStream(new ByteArrayInputStream(buffer), in);
        if (random.nextBoolean()) {
            in = readInputStreamRandomly(in, random);
        }
        assertEquals(expected, in);
    }
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) RandomInputStream(org.apache.jackrabbit.core.data.RandomInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Random(java.util.Random) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) RandomInputStream(org.apache.jackrabbit.core.data.RandomInputStream)

Example 15 with DataRecord

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

the class AbstractDataStoreTest method doReferenceTest.

/**
     * Test if record can be accessed via
     * {@link DataStore#getRecordFromReference(String)}
     */
protected void doReferenceTest() throws Exception {
    byte[] data = new byte[dataLength];
    randomGen.nextBytes(data);
    String reference;
    DataRecord record = ds.addRecord(new ByteArrayInputStream(data));
    reference = record.getReference();
    assertReference(data, reference, ds);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

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