Search in sources :

Example 21 with DataRecord

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

the class SharedDataStoreUtilsTest method test.

@Test
public void test() throws Exception {
    File rootFolder = folder.newFolder();
    dataStore = getBlobStore(rootFolder);
    String repoId1 = UUID.randomUUID().toString();
    String repoId2 = UUID.randomUUID().toString();
    // Add repository records
    dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REPOSITORY.getNameFromId(repoId1));
    DataRecord repo1 = dataStore.getMetadataRecord(SharedStoreRecordType.REPOSITORY.getNameFromId(repoId1));
    dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REPOSITORY.getNameFromId(repoId2));
    DataRecord repo2 = dataStore.getMetadataRecord(SharedStoreRecordType.REPOSITORY.getNameFromId(repoId2));
    // Add reference marker record for repo1
    dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.MARKED_START_MARKER.getNameFromId(repoId1));
    DataRecord markerRec1 = dataStore.getMetadataRecord(SharedStoreRecordType.MARKED_START_MARKER.getNameFromId(repoId1));
    assertEquals(SharedStoreRecordType.MARKED_START_MARKER.getIdFromName(markerRec1.getIdentifier().toString()), repoId1);
    long lastModifiedMarkerRec1 = markerRec1.getLastModified();
    TimeUnit.MILLISECONDS.sleep(100);
    // Add reference records
    dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REFERENCES.getNameFromId(repoId1));
    DataRecord rec1 = dataStore.getMetadataRecord(SharedStoreRecordType.REFERENCES.getNameFromId(repoId1));
    long lastModifiedRec1 = rec1.getLastModified();
    TimeUnit.MILLISECONDS.sleep(25);
    dataStore.addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedStoreRecordType.REFERENCES.getNameFromId(repoId2));
    DataRecord rec2 = dataStore.getMetadataRecord(SharedStoreRecordType.REFERENCES.getNameFromId(repoId2));
    long lastModifiedRec2 = rec2.getLastModified();
    assertEquals(SharedStoreRecordType.REPOSITORY.getIdFromName(repo1.getIdentifier().toString()), repoId1);
    assertEquals(SharedStoreRecordType.REPOSITORY.getIdFromName(repo2.getIdentifier().toString()), repoId2);
    assertEquals(SharedStoreRecordType.REFERENCES.getIdFromName(rec1.getIdentifier().toString()), repoId1);
    assertEquals(SharedStoreRecordType.REFERENCES.getIdFromName(rec2.getIdentifier().toString()), repoId2);
    // All the references from registered repositories are available
    Assert.assertTrue(SharedDataStoreUtils.refsNotAvailableFromRepos(dataStore.getAllMetadataRecords(SharedStoreRecordType.REPOSITORY.getType()), dataStore.getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType())).isEmpty());
    // Since, we don't care about which file specifically but only the earliest timestamped record
    // Earliest time should be the min timestamp from the 2 reference files
    long minRefTime = (lastModifiedRec1 <= lastModifiedRec2 ? lastModifiedRec1 : lastModifiedRec2);
    assertEquals(SharedDataStoreUtils.getEarliestRecord(dataStore.getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType())).getLastModified(), minRefTime);
    // the marker timestamp should be the minimum
    long minMarkerTime = SharedDataStoreUtils.getEarliestRecord(dataStore.getAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType())).getLastModified();
    Assert.assertTrue(minRefTime >= minMarkerTime);
    // Delete references and check back if deleted
    dataStore.deleteAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType());
    Assert.assertTrue(dataStore.getAllMetadataRecords(SharedStoreRecordType.REFERENCES.getType()).isEmpty());
    // Delete markers and check back if deleted
    dataStore.deleteAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType());
    Assert.assertTrue(dataStore.getAllMetadataRecords(SharedStoreRecordType.MARKED_START_MARKER.getType()).isEmpty());
    // Repository ids should still be available
    assertEquals(2, dataStore.getAllMetadataRecords(SharedStoreRecordType.REPOSITORY.getType()).size());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) Test(org.junit.Test)

Example 22 with DataRecord

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

the class SharedDataStoreUtilsTest method testGetAllRecords.

@Test
public void testGetAllRecords() throws Exception {
    File rootFolder = folder.newFolder();
    dataStore = getBlobStore(rootFolder);
    int number = 10;
    Set<String> added = newHashSet();
    for (int i = 0; i < number; i++) {
        String rec = dataStore.addRecord(randomStream(i, 16516)).getIdentifier().toString();
        added.add(rec);
    }
    Set<String> retrieved = newHashSet(Iterables.transform(newHashSet(dataStore.getAllRecords()), new Function<DataRecord, String>() {

        @Nullable
        @Override
        public String apply(@Nullable DataRecord input) {
            return input.getIdentifier().toString();
        }
    }));
    assertEquals(added, retrieved);
}
Also used : Function(com.google.common.base.Function) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 23 with DataRecord

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

the class SharedDataStoreUtilsTest method testGetRecordForId.

@Test
public void testGetRecordForId() throws Exception {
    File rootFolder = folder.newFolder();
    dataStore = getBlobStore(rootFolder);
    int number = 10;
    Set<DataRecord> added = newHashSet();
    for (int i = 0; i < number; i++) {
        added.add(dataStore.addRecord(randomStream(i, 16516)));
    }
    Set<DataRecord> retrieved = newHashSet();
    for (DataRecord rec : added) {
        retrieved.add(dataStore.getRecordForId(rec.getIdentifier()));
    }
    assertRecords(added, retrieved);
}
Also used : DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) Test(org.junit.Test)

Example 24 with DataRecord

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

the class SharedDataStoreUtilsTest method assertRecords.

private static void assertRecords(Set<DataRecord> expected, Set<DataRecord> retrieved) throws DataStoreException, IOException {
    //assert streams
    Map<DataIdentifier, DataRecord> retMap = Maps.newHashMap();
    for (DataRecord ret : retrieved) {
        retMap.put(ret.getIdentifier(), ret);
    }
    for (DataRecord rec : expected) {
        assertEquals("Record id different for " + rec.getIdentifier(), rec.getIdentifier(), retMap.get(rec.getIdentifier()).getIdentifier());
        assertEquals("Record length different for " + rec.getIdentifier(), rec.getLength(), retMap.get(rec.getIdentifier()).getLength());
        assertEquals("Record lastModified different for " + rec.getIdentifier(), rec.getLastModified(), retMap.get(rec.getIdentifier()).getLastModified());
        assertTrue("Record steam different for " + rec.getIdentifier(), IOUtils.contentEquals(rec.getStream(), retMap.get(rec.getIdentifier()).getStream()));
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 25 with DataRecord

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

the class CachingDataStoreTest method zeroStagingCacheAddGetDelete.

/**
     * Add, get, delete when staging cache is 0.
     * @throws Exception
     */
@Test
public void zeroStagingCacheAddGetDelete() throws Exception {
    LOG.info("Starting zeroStagingCacheAddGetDelete");
    dataStore.close();
    init(1, 64 * 1024 * 1024, 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 zeroStagingCacheAddGetDelete");
}
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)

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