use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class CacheTest method test.
@Test
public void test() throws Exception {
FileUtils.deleteDirectory(new File("target/cacheTest"));
PersistentCache cache = new PersistentCache("target/cacheTest,size=1,-compress");
try {
MemoryBlobStore mem = new MemoryBlobStore();
mem.setBlockSizeMin(100);
BlobStore b = cache.wrapBlobStore(mem);
Random r = new Random();
for (int i = 0; i < 10000; i++) {
byte[] data = new byte[100];
r.nextBytes(data);
String id = b.writeBlob(new ByteArrayInputStream(data));
b.readBlob(id, 0, new byte[1], 0, 1);
}
} finally {
cache.close();
}
}
use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class SplitBlobStoreService method registerSplitBlobStore.
private void registerSplitBlobStore() {
if (oldBlobStore == null && oldBlobStoreType == BlobStoreType.EXTERNAL) {
log.info("No BlobStore with ({}=old)", PROP_SPLIT_BLOBSTORE);
return;
}
if (newBlobStore == null) {
log.info("No BlobStore with ({}=new)", PROP_SPLIT_BLOBSTORE);
return;
}
if (reg != null) {
log.info("SplitBlobStore already registered");
return;
}
if (ctx == null) {
log.info("Component not activated yet");
return;
}
log.info("Registering SplitBlobStore with old={} ({}) and new={}", oldBlobStore, oldBlobStoreType, newBlobStore);
BlobStore blobStore;
if (oldBlobStoreType == EXTERNAL || oldBlobStoreType == SEGMENT) {
blobStore = new DefaultSplitBlobStore(homeDir, oldBlobStore, newBlobStore);
} else if (oldBlobStoreType == DOCUMENT) {
blobStore = new WrappingSplitBlobStore(homeDir, newBlobStore);
} else {
throw new IllegalStateException("Illegal blob store type value: " + oldBlobStoreType);
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("service.pid", "org.apache.jackrabbit.oak.spi.blob.split.SplitBlobStore");
reg = ctx.registerService(new String[] { BlobStore.class.getName() }, blobStore, props);
}
use of org.apache.jackrabbit.oak.spi.blob.BlobStore in project jackrabbit-oak by apache.
the class AbstractBlobTrackerRegistrationTest method reRegisterBlobTrackingStore.
@Test
public void reRegisterBlobTrackingStore() throws Exception {
registerNodeStoreService();
assertServiceNotActivated();
registerTrackingBlobStore();
assertServiceActivated();
BlobStore blobStore = context.getService(BlobStore.class);
assertTrue(blobStore instanceof BlobTrackingStore);
BlobTrackingStore trackingStore = (BlobTrackingStore) blobStore;
assertNotNull(trackingStore.getTracker());
BlobTracker oldTracker = trackingStore.getTracker();
unregisterNodeStoreService();
registerNodeStoreService();
blobStore = context.getService(BlobStore.class);
trackingStore = (BlobTrackingStore) blobStore;
BlobTracker newTracker = trackingStore.getTracker();
assertNotEquals(oldTracker, newTracker);
assertTrackerReinitialized();
}
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();
}
Aggregations