use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class NodeStoreBinaryResourceProviderTest method countBinaries.
@Test
public void countBinaries() throws Exception {
NodeBuilder builder = root.builder();
createFileNode(builder, "a", new IdBlob("hello", null), "text/plain");
createFileNode(builder, "b", new IdBlob("hello", "id1"), "text/plain");
createFileNode(builder.child("a2"), "c", new IdBlob("hello", "id2"), "text/foo").setProperty(JcrConstants.JCR_ENCODING, "bar");
NodeStore store = new MemoryNodeStore(builder.getNodeState());
BlobStore blobStore = new MemoryBlobStore();
NodeStoreBinaryResourceProvider extractor = new NodeStoreBinaryResourceProvider(store, blobStore);
assertEquals(2, extractor.getBinaries("/").size());
assertEquals(1, extractor.getBinaries("/a2").size());
BinaryResource bs = extractor.getBinaries("/a2").first().get();
assertEquals("text/foo", bs.getMimeType());
assertEquals("bar", bs.getEncoding());
assertEquals("id2", bs.getBlobId());
}
use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class NodeStoreBinaryResourceProviderTest method csvGenerator.
@Test
public void csvGenerator() throws Exception {
File csv = new File(temporaryFolder.getRoot(), "test.csv");
BlobStore blobStore = new MemoryBlobStore();
NodeBuilder builder = root.builder();
createFileNode(builder, "a", blobOf("foo", blobStore), "text/plain");
createFileNode(builder, "b", blobOf("hello", blobStore), "text/plain");
NodeStore store = new MemoryNodeStore(builder.getNodeState());
NodeStoreBinaryResourceProvider extractor = new NodeStoreBinaryResourceProvider(store, blobStore);
CSVFileGenerator generator = new CSVFileGenerator(csv);
generator.generate(extractor.getBinaries("/"));
CSVFileBinaryResourceProvider csvbrp = new CSVFileBinaryResourceProvider(csv, blobStore);
assertEquals(2, csvbrp.getBinaries("/").size());
csvbrp.close();
}
use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class DefaultStandbyBlobReaderTest method shouldReturnNullIfBlobDoesNotExist.
@Test
public void shouldReturnNullIfBlobDoesNotExist() throws Exception {
BlobStore s = mock(BlobStore.class);
when(s.getInputStream("id")).thenThrow(new IOException("blob not found"));
DefaultStandbyBlobReader r = new DefaultStandbyBlobReader(s);
assertNull(r.readBlob("id"));
}
use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class DefaultStandbyBlobReaderTest method shouldReturnNullIfBlobIsUnreadable.
@Test
public void shouldReturnNullIfBlobIsUnreadable() throws Exception {
BlobStore s = mock(BlobStore.class);
when(s.getInputStream("id")).thenReturn(newFailingInputStream());
DefaultStandbyBlobReader r = new DefaultStandbyBlobReader(s);
assertNull(r.readBlob("id"));
}
use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class BlobStoreFixture method getDataStore.
public static BlobStoreFixture getDataStore(final File basedir, final int fdsCacheInMB, final StatisticsProvider statisticsProvider) {
return new BlobStoreFixture("DS") {
private DataStore dataStore;
private BlobStore blobStore;
private File storeDir;
private Map<String, ?> config;
@Override
public BlobStore setUp() {
String className = System.getProperty("dataStore");
checkNotNull(className, "No system property named 'dataStore' defined");
try {
dataStore = Class.forName(className).asSubclass(DataStore.class).newInstance();
config = getConfig();
configure(dataStore, config);
dataStore = configureIfCloudDataStore(className, dataStore, config, unique.toLowerCase(), statisticsProvider);
storeDir = new File(basedir, unique);
dataStore.init(storeDir.getAbsolutePath());
blobStore = new DataStoreBlobStore(dataStore, true, fdsCacheInMB);
configure(blobStore);
return blobStore;
} catch (Exception e) {
throw new IllegalStateException("Cannot instantiate DataStore " + className, e);
}
}
@Override
public void tearDown() {
if (blobStore instanceof DataStoreBlobStore) {
try {
((DataStoreBlobStore) blobStore).close();
cleanup(storeDir, config, unique.toLowerCase());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@Override
public long size() {
throw new UnsupportedOperationException("Implementation pending");
}
};
}
Aggregations