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"));
}
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);
}
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());
}
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());
}
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());
}
Aggregations