Search in sources :

Example 11 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier 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 12 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier 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 13 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier 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)

Example 14 with DataIdentifier

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

the class CachingDataStoreTest method addStagingAndDelete.

/**
     * Add in staging and delete.
     * @throws Exception
     */
@Test
public void addStagingAndDelete() throws Exception {
    LOG.info("Starting addStagingAndDelete");
    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));
    assertNotNull(rec);
    assertFile(rec.getStream(), f, folder);
    dataStore.deleteRecord(new DataIdentifier(id));
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    Thread.sleep(1000);
    //start & finish
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish();
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    LOG.info("Finished addStagingAndDelete");
}
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 15 with DataIdentifier

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

the class CachingDataStoreTest method getRecordNotAvailable.

/**
     * {@link CompositeDataStoreCache#getIfPresent(String)} when no record.
     */
@Test
public void getRecordNotAvailable() throws DataStoreException {
    LOG.info("Starting getRecordNotAvailable");
    DataRecord rec = dataStore.getRecordIfStored(new DataIdentifier(ID_PREFIX + 0));
    assertNull(rec);
    LOG.info("Finished getRecordNotAvailable");
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Test(org.junit.Test)

Aggregations

DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)60 Test (org.junit.Test)31 DataRecord (org.apache.jackrabbit.core.data.DataRecord)30 File (java.io.File)22 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)13 FileInputStream (java.io.FileInputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ArrayList (java.util.ArrayList)8 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)5 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 RepositoryException (javax.jcr.RepositoryException)4 Function (com.google.common.base.Function)3 StorageException (com.microsoft.azure.storage.StorageException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3