Search in sources :

Example 26 with DataRecord

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

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

Example 28 with DataRecord

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

the class CachingDataStoreTest method getAllIdentifiers.

/**
     * Get all Identifiers.
     */
@Test
public void getAllIdentifiers() throws Exception {
    LOG.info("Starting getAllIdentifiers");
    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());
    assertTrue(Iterators.contains(dataStore.getAllIdentifiers(), new DataIdentifier(id)));
    //start & finish
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish();
    assertTrue(Iterators.contains(dataStore.getAllIdentifiers(), new DataIdentifier(id)));
    LOG.info("Finished getAllIdentifiers");
}
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 29 with DataRecord

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

the class CachingDataStoreTest method syncAddGetLoadCache.

/**
     * Add, get forcing load in cache.
     * @throws Exception
     */
@Test
public void syncAddGetLoadCache() throws Exception {
    LOG.info("Starting syncAddGetForceFromCache");
    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, new BlobOptions().setUpload(SYNCHRONOUS));
    assertEquals(id, rec.getIdentifier().toString());
    assertFile(rec.getStream(), f, folder);
    // Invalidate from the local cache
    dataStore.getCache().invalidate(id);
    // Trigger load from backend
    File cacheDownloaded = dataStore.getCache().get(id);
    assertTrue(Files.equal(f, cacheDownloaded));
    assertEquals(1, Iterators.size(dataStore.getAllIdentifiers()));
    LOG.info("Finished syncAddGetLoadCache");
}
Also used : BlobOptions(org.apache.jackrabbit.oak.spi.blob.BlobOptions) 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 30 with DataRecord

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

the class CachingDataStoreTest method lazyLoadStream.

/**
     * Add in datastore, invalidate from cache and lazy load record stream.
     */
@Test
public void lazyLoadStream() throws Exception {
    LOG.info("Starting lazyLoadStream");
    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());
    //start & finish
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish();
    // Invalidate from the local cache
    dataStore.getCache().invalidate(id);
    // retrieve record from the datastore
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNotNull(rec);
    assertEquals(id, rec.getIdentifier().toString());
    // the file should not be in cache
    File cached = dataStore.getCache().getIfPresent(id);
    assertNull(cached);
    // assert stream
    assertFile(rec.getStream(), f, folder);
    // Now should be available in the cache
    cached = dataStore.getCache().getIfPresent(id);
    assertNotNull(cached);
    assertTrue(Files.equal(f, cached));
    dataStore.deleteRecord(new DataIdentifier(id));
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    LOG.info("Finished lazyLoadStream");
}
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