Search in sources :

Example 26 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method branchBaseBeforeClusterJoin.

@Test
public void branchBaseBeforeClusterJoin() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1).setDocumentStore(store).setAsyncDelay(0).getNodeStore();
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("parent");
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2).setDocumentStore(store).setAsyncDelay(0).getNodeStore();
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("parent").child("baz");
    merge(ns2, b2);
    ns2.runBackgroundOperations();
    DocumentNodeState root = ns1.getRoot();
    DocumentNodeStoreBranch b = ns1.createBranch(root);
    // branch state is now Unmodified
    NodeBuilder builder = root.builder();
    builder.child("parent").child("foo");
    b.setRoot(builder.getNodeState());
    // branch state is now InMemory
    builder.child("parent").child("bar");
    b.setRoot(builder.getNodeState());
    // branch state is now Persisted
    b.rebase();
    NodeState parent = b.getHead().getChildNode("parent");
    assertTrue(parent.exists());
    assertTrue(parent.hasChildNode("foo"));
    assertTrue(parent.hasChildNode("bar"));
    assertFalse(parent.hasChildNode("baz"));
    ns1.runBackgroundOperations();
    b.merge(EmptyHook.INSTANCE, CommitInfo.EMPTY);
    parent = ns1.getRoot().getChildNode("parent");
    assertTrue(parent.exists());
    assertTrue(parent.hasChildNode("foo"));
    assertTrue(parent.hasChildNode("bar"));
    assertTrue(parent.hasChildNode("baz"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 27 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method commitRootSameAsModifiedPath.

@Ignore("OAK-5788")
@Test
public void commitRootSameAsModifiedPath() throws Exception {
    WriteCountingStore ws = new WriteCountingStore();
    DocumentNodeStore ns = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(ws).getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    builder.child("a").child("b");
    merge(ns, builder);
    ws.reset();
    builder = ns.getRoot().builder();
    builder.child("a").child("b").setProperty("foo", "bar");
    merge(ns, builder);
    assertEquals(1, ws.count);
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentSplitTest method testSplitPropAndCommitOnly.

@Test
public void testSplitPropAndCommitOnly() throws Exception {
    DocumentStore store = mk.getDocumentStore();
    DocumentNodeStore ns = mk.getNodeStore();
    NodeBuilder b1 = ns.getRoot().builder();
    b1.child("test").child("foo").child("bar");
    ns.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // is parent
    for (int i = 0; i < NodeDocument.NUM_REVS_THRESHOLD; i++) {
        b1 = ns.getRoot().builder();
        b1.child("test").child("foo").setProperty("prop", i);
        b1.child("test").setProperty("prop", i);
        ns.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    ns.runBackgroundOperations();
    NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/test/foo"));
    List<NodeDocument> prevDocs = ImmutableList.copyOf(doc.getAllPreviousDocs());
    assertEquals(1, prevDocs.size());
    assertEquals(SplitDocType.COMMIT_ROOT_ONLY, prevDocs.get(0).getSplitDocType());
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 29 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method childNodeEntries.

@Test
public void childNodeEntries() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    DocumentStore docStore = new MemoryDocumentStore() {

        @Nonnull
        @Override
        public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) {
            counter.incrementAndGet();
            return super.query(collection, fromKey, toKey, limit);
        }
    };
    DocumentNodeStore store = builderProvider.newBuilder().setDocumentStore(docStore).getNodeStore();
    NodeBuilder root = store.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        root.child("node-" + i);
    }
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    counter.set(0);
    // the commit and not use a query on the document store (OAK-1322)
    for (ChildNodeEntry e : store.getRoot().getChildNodeEntries()) {
        e.getNodeState();
    }
    assertEquals(0, counter.get());
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 30 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentSplitTest method noBinarySplitWhenRemoved.

@Test
public void noBinarySplitWhenRemoved() throws Exception {
    DocumentStore store = mk.getDocumentStore();
    DocumentNodeStore ns = mk.getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    // use more than 4k of binary data (OAK-5205)
    PropertyState binary = binaryProperty("p", randomBytes(5 * 1024));
    builder.child("foo").setProperty(binary);
    merge(ns, builder);
    builder = ns.getRoot().builder();
    builder.child("foo").remove();
    merge(ns, builder);
    ns.runBackgroundOperations();
    // must not create split document in this case. See OAK-5010
    NodeDocument foo = store.find(NODES, Utils.getIdFromPath("/foo"));
    assertNotNull(foo);
    assertEquals(0, foo.getPreviousRanges().size());
    // re-create it
    builder = ns.getRoot().builder();
    builder.child("foo");
    merge(ns, builder);
    ns.runBackgroundOperations();
    // now the old binary value must be moved to a previous document
    foo = store.find(NODES, Utils.getIdFromPath("/foo"));
    assertNotNull(foo);
    List<NodeDocument> prevDocs = copyOf(foo.getAllPreviousDocs());
    assertEquals(1, prevDocs.size());
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)948 Test (org.junit.Test)704 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)253 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)84 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)74 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)73 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)70 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)67 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)60 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)52 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)49 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)43 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)31 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)31 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)29 Blob (org.apache.jackrabbit.oak.api.Blob)28 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)24 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)22 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)21 Nonnull (javax.annotation.Nonnull)20