DocumentNodeStoreBranch implements NodeStoreBranch { @NotNull @Override public NodeState merge(@NotNull CommitHook hook, @NotNull CommitInfo info) throws CommitFailedException { try { return merge0(hook, info, false); } catch (CommitFailedException e) { if (!e.isOfType(MERGE)) { throw e; } } return merge0(hook, info, true); } DocumentNodeStoreBranch(DocumentNodeStore store,
                            DocumentNodeState base,
                            ReadWriteLock mergeLock); @NotNull @Override NodeState getBase(); @NotNull @Override NodeState getHead(); @Override void setRoot(NodeState newRoot); @NotNull @Override NodeState merge(@NotNull CommitHook hook, @NotNull CommitInfo info); @Override void rebase(); @Override String toString();  }
@Test public void branchedBranch() throws Exception { DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore(); NodeBuilder b1 = ns.getRoot().builder(); b1.child("a"); persistToBranch(b1); NodeBuilder b2 = b1.getNodeState().builder(); b1.child("b"); persistToBranch(b1); b2.child("c"); persistToBranch(b2); assertTrue(b2.hasChildNode("a")); assertFalse(b2.hasChildNode("b")); assertTrue(b2.hasChildNode("c")); assertTrue(b1.hasChildNode("a")); assertTrue(b1.hasChildNode("b")); assertFalse(b1.hasChildNode("c")); merge(ns, b1); assertTrue(ns.getRoot().getChildNode("a").exists()); assertTrue(ns.getRoot().getChildNode("b").exists()); assertFalse(ns.getRoot().getChildNode("c").exists()); try { merge(ns, b2); fail("Merge must fail with IllegalStateException"); } catch (IllegalStateException e) { } }
@Test public void builderFromStateFromBuilder() throws Exception { DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore(); NodeBuilder b1 = ns.getRoot().builder(); b1.child("a"); NodeBuilder b2 = b1.getNodeState().builder(); b1.child("b"); b2.child("c"); assertTrue(b2.hasChildNode("a")); assertFalse(b2.hasChildNode("b")); assertTrue(b2.hasChildNode("c")); assertTrue(b1.hasChildNode("a")); assertTrue(b1.hasChildNode("b")); assertFalse(b1.hasChildNode("c")); merge(ns, b1); assertTrue(ns.getRoot().getChildNode("a").exists()); assertTrue(ns.getRoot().getChildNode("b").exists()); assertFalse(ns.getRoot().getChildNode("c").exists()); try { merge(ns, b2); fail("Merge must fail with IllegalStateException"); } catch (IllegalStateException e) { } }
@Test public void noopChanges() throws Exception { DocumentNodeStore ns = builderProvider.newBuilder().setUpdateLimit(10).getNodeStore(); NodeBuilder builder = ns.getRoot().builder(); builder.child("a").setProperty("p", 1); merge(ns, builder); NodeState root = ns.getRoot(); builder = root.builder(); builder.child("b"); for (int i = 0; i < ns.getUpdateLimit() * 2000; i++) { builder.child("a").setProperty("p", 1); } builder.getNodeState().compareAgainstBaseState(root, new JsopDiff()); }