Search in sources :

Example 1 with BlobOptions

use of org.apache.jackrabbit.oak.spi.blob.BlobOptions 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 2 with BlobOptions

use of org.apache.jackrabbit.oak.spi.blob.BlobOptions in project jackrabbit-oak by apache.

the class CachingDataStoreTest method syncAddGetDelete.

/**
     * Add, get, delete with synchronous option.
     * @throws Exception
     */
@Test
public void syncAddGetDelete() throws Exception {
    LOG.info("Starting syncAddGetDelete");
    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);
    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 syncAddGetDelete");
}
Also used : BlobOptions(org.apache.jackrabbit.oak.spi.blob.BlobOptions) 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

File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)2 DataRecord (org.apache.jackrabbit.core.data.DataRecord)2 BlobOptions (org.apache.jackrabbit.oak.spi.blob.BlobOptions)2 Test (org.junit.Test)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)1