use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.
the class DefaultIndexReaderFactoryTest method indexDirWithBlobStore.
@Test
public void indexDirWithBlobStore() throws Exception {
/* Register a blob store */
CachingFileDataStore ds = DataStoreUtils.createCachingFDS(folder.newFolder().getAbsolutePath(), folder.newFolder().getAbsolutePath());
LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, new DataStoreBlobStore(ds));
LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
writer.updateDocument("/content/en", newDoc("/content/en"));
writer.close(0);
LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
assertEquals(1, readers.size());
LuceneIndexReader reader = readers.get(0);
assertNotNull(reader.getReader());
assertNull(reader.getSuggestDirectory());
assertNull(reader.getLookup());
assertEquals(1, reader.getReader().numDocs());
final AtomicBoolean closed = new AtomicBoolean();
reader.getReader().addReaderClosedListener(new IndexReader.ReaderClosedListener() {
@Override
public void onClose(IndexReader reader) {
closed.set(true);
}
});
reader.close();
assertTrue(closed.get());
}
use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.
the class ExternalBlobIT method testDataStoreBlob.
@Test
public void testDataStoreBlob() throws Exception {
FileDataStore fds = createFileDataStore();
DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
nodeStore = getNodeStore(dbs);
//Test for Blob which get inlined
Blob b1 = testCreateAndRead(createBlob(fds.getMinRecordLength() - 2));
assertTrue(b1 instanceof SegmentBlob);
assertNull(((SegmentBlob) b1).getBlobId());
//Test for Blob which need to be pushed to BlobStore
byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1];
new Random().nextBytes(data2);
Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2)));
assertTrue(b2 instanceof SegmentBlob);
assertNotNull(b2.getReference());
assertEquals(b2.getContentIdentity(), ((SegmentBlob) b2).getBlobId());
InputStream is = dbs.getInputStream(((SegmentBlob) b2).getBlobId());
assertNotNull(IOUtils.contentEquals(new ByteArrayInputStream(data2), is));
is.close();
}
use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.
the class ExternalBlobIT method testSize.
@Test
public void testSize() throws Exception {
FileDataStore fds = createFileDataStore();
DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
nodeStore = getNodeStore(dbs);
int size = Segment.MEDIUM_LIMIT + 1;
byte[] data2 = new byte[size];
new Random().nextBytes(data2);
Blob b = nodeStore.createBlob(new ByteArrayInputStream(data2));
NodeBuilder builder = nodeStore.getRoot().builder();
builder.child("hello").setProperty("world", b);
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
PropertyState ps = nodeStore.getRoot().getChildNode("hello").getProperty("world");
// world = {2318851547697882338 bytes}
assertEquals(size, ps.size());
// assertEquals("{" + size + " bytes}", ps.toString());
}
use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore in project jackrabbit-oak by apache.
the class ExternalBlobIT method testNullBlobId.
@Test
public void testNullBlobId() throws Exception {
FileDataStore fds = createFileDataStore();
DataStoreBlobStore dbs = new DataStoreBlobStore(fds);
nodeStore = getNodeStore(dbs);
NodeBuilder nb = nodeStore.getRoot().builder();
NodeBuilder cb = nb.child("hello");
cb.setProperty("blob1", createBlob(Segment.MEDIUM_LIMIT - 1));
int noOfBlobs = 4000;
for (int i = 0; i < noOfBlobs; i++) {
cb.setProperty("blob" + i, createBlob(Segment.MEDIUM_LIMIT + 1));
}
cb.setProperty("anotherBlob2", createBlob(Segment.MEDIUM_LIMIT + 1));
cb.setProperty("anotherBlob3", createBlob(Segment.MEDIUM_LIMIT + 1));
nodeStore.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
final List<String> refrences = Lists.newArrayList();
store.collectBlobReferences(new ReferenceCollector() {
@Override
public void addReference(String reference, String nodeId) {
assertNotNull(reference);
refrences.add(reference);
}
});
assertEquals(noOfBlobs + 2, refrences.size());
}
use of org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore 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