Search in sources :

Example 1 with ThreeWayConflictHandler

use of org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler in project jackrabbit-oak by apache.

the class ThreeWayConflictHandlerTest method changeChangedProperty.

@Test
public void changeChangedProperty() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution changeChangedProperty(NodeBuilder parent, PropertyState ours, PropertyState theirs, PropertyState base) {
            called.set(true);
            assertEquals("ours", ours.getValue(STRING));
            assertEquals("theirs", theirs.getValue(STRING));
            assertEquals("base", base.getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").setProperty("p", "theirs");
    ourRoot.getTree("/c").setProperty("p", "ours");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 2 with ThreeWayConflictHandler

use of org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler in project jackrabbit-oak by apache.

the class ThreeWayConflictHandlerTest method deleteDeletedNode.

@Test
public void deleteDeletedNode() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution deleteDeletedNode(NodeBuilder parent, String name, NodeState base) {
            called.set(true);
            assertTrue(base.hasProperty("p"));
            assertEquals("base", base.getProperty("p").getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").remove();
    ourRoot.getTree("/c").remove();
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with ThreeWayConflictHandler

use of org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler in project jackrabbit-oak by apache.

the class ThreeWayConflictHandlerTest method deleteChangedNode.

@Test
public void deleteChangedNode() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution deleteChangedNode(NodeBuilder parent, String name, NodeState theirs, NodeState base) {
            called.set(true);
            assertTrue(theirs.hasProperty("p"));
            assertTrue(base.hasProperty("p"));
            assertEquals("theirs", theirs.getProperty("p").getValue(STRING));
            assertEquals("base", base.getProperty("p").getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").setProperty("p", "theirs");
    ourRoot.getTree("/c").remove();
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 4 with ThreeWayConflictHandler

use of org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler in project jackrabbit-oak by apache.

the class ThreeWayConflictHandlerTest method changeDeletedProperty.

@Test
public void changeDeletedProperty() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution changeDeletedProperty(NodeBuilder parent, PropertyState ours, PropertyState base) {
            called.set(true);
            assertEquals("ours", ours.getValue(STRING));
            assertEquals("base", base.getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").removeProperty("p");
    ourRoot.getTree("/c").setProperty("p", "ours");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 5 with ThreeWayConflictHandler

use of org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler in project jackrabbit-oak by apache.

the class ThreeWayConflictHandlerTest method changeDeletedNode.

@Test
public void changeDeletedNode() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution changeDeletedNode(NodeBuilder parent, String name, NodeState ours, NodeState base) {
            called.set(true);
            assertTrue(ours.hasProperty("p"));
            assertTrue(base.hasProperty("p"));
            assertEquals("ours", ours.getProperty("p").getValue(STRING));
            assertEquals("base", base.getProperty("p").getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").remove();
    ourRoot.getTree("/c").setProperty("p", "ours");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)8 Root (org.apache.jackrabbit.oak.api.Root)8 ThreeWayConflictHandler (org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler)8 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)8 Test (org.junit.Test)8 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)5 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3