Search in sources :

Example 16 with MemoryBlobStore

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

the class Cluster2Test method twoNodes.

@Test
public void twoNodes() throws Exception {
    MemoryDocumentStore ds = new MemoryDocumentStore();
    MemoryBlobStore bs = new MemoryBlobStore();
    DocumentMK.Builder builder;
    builder = new DocumentMK.Builder();
    builder.setDocumentStore(ds).setBlobStore(bs);
    DocumentMK mk1 = builder.setClusterId(1).open();
    builder = new DocumentMK.Builder();
    builder.setDocumentStore(ds).setBlobStore(bs);
    DocumentMK mk2 = builder.setClusterId(2).open();
    mk1.commit("/", "+\"test\":{\"x\": 1}", null, null);
    mk1.backgroundWrite();
    mk2.backgroundRead();
    String b1 = mk2.branch(mk2.getHeadRevision());
    mk2.commit("/", "-\"test\"", b1, null);
    String b2 = mk2.branch(mk2.getHeadRevision());
    String b2b = mk2.commit("/", "-\"test\"", b2, null);
    mk2.merge(b2b, null);
    mk2.backgroundWrite();
    mk1.backgroundRead();
    mk1.commit("/", "+\"test\":{\"x\": 1}", null, null);
    mk1.backgroundWrite();
    mk2.backgroundRead();
    String n1 = mk1.getNodes("/test", mk1.getHeadRevision(), 0, 0, 10, null);
    String n2 = mk2.getNodes("/test", mk2.getHeadRevision(), 0, 0, 10, null);
    // mk1 now sees both changes
    assertEquals("{\"x\":1,\":childNodeCount\":0}", n1);
    assertEquals("{\"x\":1,\":childNodeCount\":0}", n2);
    mk1.dispose();
    mk2.dispose();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 17 with MemoryBlobStore

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

the class ClusterTest method openCloseOpen.

@Test
public void openCloseOpen() {
    MemoryDocumentStore ds = new MemoryDocumentStore();
    MemoryBlobStore bs = new MemoryBlobStore();
    DocumentMK mk1 = createMK(1, 0, ds, bs);
    mk1.commit("/", "+\"a\": {}", null, null);
    mk1.commit("/", "-\"a\"", null, null);
    mk1.runBackgroundOperations();
    DocumentMK mk2 = createMK(2, 0, ds, bs);
    mk2.commit("/", "+\"a\": {}", null, null);
    mk2.commit("/", "-\"a\"", null, null);
    mk2.runBackgroundOperations();
    DocumentMK mk3 = createMK(3, 0, ds, bs);
    mk3.commit("/", "+\"a\": {}", null, null);
    mk3.commit("/", "-\"a\"", null, null);
    mk3.runBackgroundOperations();
    DocumentMK mk4 = createMK(4, 0, ds, bs);
    mk4.commit("/", "+\"a\": {}", null, null);
    mk4.runBackgroundOperations();
    DocumentMK mk5 = createMK(5, 0, ds, bs);
    mk5.commit("/", "-\"a\"", null, null);
    mk5.commit("/", "+\"a\": {}", null, null);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 18 with MemoryBlobStore

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

the class OakDirectoryTestBase method markAllBlobsFromBlobStoreAsDeleted.

// OAK-7066
@Test
public void markAllBlobsFromBlobStoreAsDeleted() throws Exception {
    IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
    final Set<String> deletedFiles = newHashSet();
    MemoryBlobStore bs = new MemoryBlobStore();
    bs.setBlockSizeMin(48);
    BlobFactory factory = in -> new BlobStoreBlob(bs, bs.writeBlob(in));
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {

        @Override
        public void deleted(String blobId, Iterable<String> ids) {
            deletedFiles.add(Iterables.getLast(ids));
        }

        @Override
        public void commitProgress(IndexProgress indexProgress) {
        }

        @Override
        public boolean isMarkingForActiveDeletionUnsafe() {
            return false;
        }
    }).build();
    writeFile(dir, "file1", 25);
    writeFile(dir, "file2", 50);
    dir.deleteFile("file1");
    dir.deleteFile("file2");
    dir.close();
    assertTrue("file1 must be reported as deleted", deletedFiles.contains("file1"));
    assertTrue("file2 must be reported as deleted", deletedFiles.contains("file2"));
}
Also used : JCR_DATA(org.apache.jackrabbit.JcrConstants.JCR_DATA) Arrays(java.util.Arrays) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Random(java.util.Random) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Directory(org.apache.lucene.store.Directory) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) UNIQUE_KEY_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.UNIQUE_KEY_SIZE) Assert.fail(org.junit.Assert.fail) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) IOContext(org.apache.lucene.store.IOContext) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) PROP_BLOB_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_BLOB_SIZE) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Type(org.apache.jackrabbit.oak.api.Type) Set(java.util.Set) ONE_MB(org.apache.commons.io.FileUtils.ONE_MB) FileNotFoundException(java.io.FileNotFoundException) Sets(com.google.common.collect.Sets) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NullInputStream(org.apache.commons.io.input.NullInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) LuceneIndexConstants(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants) SegmentNodeStoreBuilders(org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) SegmentTestConstants(org.apache.jackrabbit.oak.segment.SegmentTestConstants) PropertyStates(org.apache.jackrabbit.oak.plugins.memory.PropertyStates) IndexOutput(org.apache.lucene.store.IndexOutput) PROP_UNSAFE_FOR_ACTIVE_DELETION(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNSAFE_FOR_ACTIVE_DELETION) INDEX_DATA_CHILD_NAME(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME) ONE_GB(org.apache.commons.io.FileUtils.ONE_GB) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IndexInput(org.apache.lucene.store.IndexInput) Assert.assertTrue(org.junit.Assert.assertTrue) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) IOException(java.io.IOException) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) File(java.io.File) InputStreamDataInput(org.apache.lucene.store.InputStreamDataInput) PROP_UNIQUE_KEY(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNIQUE_KEY) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Blob(org.apache.jackrabbit.oak.api.Blob) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) INITIAL_CONTENT(org.apache.jackrabbit.oak.InitialContent.INITIAL_CONTENT) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 19 with MemoryBlobStore

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

the class FlatFileStoreTest method basicTest.

@Test
public void basicTest() throws Exception {
    List<String> paths = createTestPaths();
    FlatFileNodeStoreBuilder builder = new FlatFileNodeStoreBuilder(TestUtils.createEntries(paths), folder.getRoot());
    FlatFileStore flatStore = builder.withBlobStore(new MemoryBlobStore()).withPreferredPathElements(preferred).build();
    List<String> entryPaths = StreamSupport.stream(flatStore.spliterator(), false).map(NodeStateEntry::getPath).collect(Collectors.toList());
    List<String> sortedPaths = TestUtils.sortPaths(paths, preferred);
    assertEquals(sortedPaths, entryPaths);
}
Also used : MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Test(org.junit.Test)

Example 20 with MemoryBlobStore

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

the class MergeRetryTest method retryPersisted.

/**
 * Test for OAK-1202
 */
@Test
public void retryPersisted() throws Exception {
    MemoryDocumentStore ds = new MemoryDocumentStore();
    MemoryBlobStore bs = new MemoryBlobStore();
    DocumentNodeStore ns1 = createMK(1, 1000, ds, bs);
    DocumentNodeStore ns2 = createMK(2, 1000, ds, bs);
    try {
        NodeBuilder builder1 = ns1.getRoot().builder();
        createTree(builder1.child("bar"), 2);
        NodeBuilder builder2 = ns2.getRoot().builder();
        createTree(builder2.child("qux"), 2);
        ns1.merge(builder1, HOOK, CommitInfo.EMPTY);
        ns2.merge(builder2, HOOK, CommitInfo.EMPTY);
    } finally {
        ns1.dispose();
        ns2.dispose();
    }
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

MemoryBlobStore (org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)23 Test (org.junit.Test)16 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)12 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)8 File (java.io.File)5 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)4 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)4 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)4 Random (java.util.Random)3 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)3 AsyncIndexInfoService (org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService)3 IndexPathService (org.apache.jackrabbit.oak.plugins.index.IndexPathService)3 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 InitialContent (org.apache.jackrabbit.oak.InitialContent)2 Oak (org.apache.jackrabbit.oak.Oak)2 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)2 Before (org.junit.Before)2