Search in sources :

Example 16 with DataRecord

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

the class AbstractDataStoreTest method doGetAllIdentifiersTest.

/**
     * Test {@link DataStore#getAllIdentifiers()} and asserts all identifiers
     * are returned.
     */
protected void doGetAllIdentifiersTest() throws Exception {
    List<DataIdentifier> list = new ArrayList<DataIdentifier>();
    Random random = randomGen;
    byte[] data = new byte[dataLength];
    random.nextBytes(data);
    DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
    list.add(rec.getIdentifier());
    data = new byte[dataLength];
    random.nextBytes(data);
    rec = ds.addRecord(new ByteArrayInputStream(data));
    list.add(rec.getIdentifier());
    data = new byte[dataLength];
    random.nextBytes(data);
    rec = ds.addRecord(new ByteArrayInputStream(data));
    list.add(rec.getIdentifier());
    Iterator<DataIdentifier> itr = Sets.newHashSet(ds.getAllIdentifiers()).iterator();
    while (itr.hasNext()) {
        assertTrue("record found on list", list.remove(itr.next()));
    }
    Assert.assertEquals(0, list.size());
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 17 with DataRecord

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

the class AbstractDataStoreTest method doUpdateLastModifiedOnAccessTest.

/**
     * Asserts that timestamp of all records accessed after
     * {@link DataStore#updateModifiedDateOnAccess(long)} invocation.
     */
protected void doUpdateLastModifiedOnAccessTest() throws Exception {
    Random random = randomGen;
    byte[] data = new byte[dataLength];
    random.nextBytes(data);
    DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data));
    data = new byte[dataLength];
    random.nextBytes(data);
    DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data));
    LOG.debug("rec2 timestamp=" + rec2.getLastModified());
    // sleep for some time to ensure that async upload completes in backend.
    sleep(6000);
    long updateTime = System.currentTimeMillis();
    LOG.debug("updateTime=" + updateTime);
    ds.updateModifiedDateOnAccess(updateTime);
    // sleep to workaround System.currentTimeMillis granularity.
    sleep(3000);
    data = new byte[dataLength];
    random.nextBytes(data);
    DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data));
    data = new byte[dataLength];
    random.nextBytes(data);
    DataRecord rec4 = ds.addRecord(new ByteArrayInputStream(data));
    rec1 = ds.getRecord(rec1.getIdentifier());
    Assert.assertEquals("rec1 touched", true, rec1.getLastModified() > updateTime);
    LOG.debug("rec2 timestamp=" + rec2.getLastModified());
    Assert.assertEquals("rec2 not touched", true, rec2.getLastModified() < updateTime);
    Assert.assertEquals("rec3 touched", true, rec3.getLastModified() > updateTime);
    Assert.assertEquals("rec4 touched", true, rec4.getLastModified() > updateTime);
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 18 with DataRecord

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

the class CachingFileDataStoreTest method assertReferenceKey.

@Test
public void assertReferenceKey() 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);
    DataRecord refRec = ds.getRecordFromReference(rec.getReference());
    assertRecord(data, refRec);
    // Check bytes retrieved from reference.key file
    File refFile = new File(fsBackendPath, "reference.key");
    assertTrue(refFile.exists());
    byte[] keyRet = FileUtils.readFileToByteArray(refFile);
    assertTrue(keyRet.length != 0);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) Test(org.junit.Test)

Example 19 with DataRecord

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

the class DataStoreBlobStoreTest method testReference.

@Test
public void testReference() throws DataStoreException, IOException {
    String reference = "testReference";
    String blobId = "test";
    DataIdentifier testDI = new DataIdentifier(blobId);
    DataRecord testDR = new ByteArrayDataRecord("foo".getBytes(), testDI, reference);
    DataStore mockedDS = mock(DataStore.class);
    when(mockedDS.getRecordFromReference(reference)).thenReturn(testDR);
    when(mockedDS.getRecord(testDI)).thenReturn(testDR);
    when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR);
    DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
    assertEquals(reference, ds.getReference(blobId));
    assertEquals(blobId, BlobId.of(ds.getBlobId(reference)).blobId);
    assertEquals(BlobId.of(testDR).encodedValue(), ds.getBlobId(reference));
    String inMemBlobId = InMemoryDataRecord.getInstance("foo".getBytes()).getIdentifier().toString();
    //For in memory record the reference should be null
    assertNull(ds.getReference(inMemBlobId));
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataStore(org.apache.jackrabbit.core.data.DataStore) DataRecord(org.apache.jackrabbit.core.data.DataRecord) AbstractBlobStoreTest(org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest) Test(org.junit.Test)

Example 20 with DataRecord

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

the class DataStoreBlobStoreTest method testInlineBinary.

@Test
public void testInlineBinary() throws DataStoreException, IOException {
    int maxInlineSize = 300;
    DataStore mockedDS = mock(DataStore.class);
    when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize);
    DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
    byte[] data = new byte[maxInlineSize];
    new Random().nextBytes(data);
    DataRecord dr = ds.addRecord(new ByteArrayInputStream(data));
    assertTrue(InMemoryDataRecord.isInstance(dr.getIdentifier().toString()));
    assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), dr.getStream()));
    assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), new BlobStoreInputStream(ds, dr.getIdentifier().toString(), 0)));
    assertEquals(dr, ds.getRecordIfStored(dr.getIdentifier()));
    assertEquals(dr, ds.getRecord(dr.getIdentifier()));
    //Check for BlobStore methods
    assertEquals(maxInlineSize, ds.getBlobLength(dr.getIdentifier().toString()));
    assertEquals(dr.getIdentifier().toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId);
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) DataStore(org.apache.jackrabbit.core.data.DataStore) BlobStoreInputStream(org.apache.jackrabbit.oak.spi.blob.BlobStoreInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) AbstractBlobStoreTest(org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest) 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