Search in sources :

Example 96 with NodeState

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

the class ClusterTest method clusterBranchRebase.

/**
     * Test for OAK-1254
     */
@Test
public void clusterBranchRebase() throws Exception {
    DocumentMK mk1 = createMK(1, 0);
    mk1.commit("/", "+\"test\":{}", null, null);
    mk1.runBackgroundOperations();
    DocumentMK mk2 = createMK(2, 0);
    DocumentMK mk3 = createMK(3, 0);
    DocumentNodeStore ns3 = mk3.getNodeStore();
    // the next line is required for the test even if it
    // just reads from the node store. do not remove!
    traverse(ns3.getRoot(), "/");
    String b3 = mk3.branch(null);
    b3 = mk3.commit("/", "+\"mk3\":{}", b3, null);
    assertTrue(mk3.nodeExists("/test", b3));
    mk2.commit("/", "+\"test/mk21\":{}", null, null);
    mk2.runBackgroundOperations();
    // pick up changes from mk2
    mk3.runBackgroundOperations();
    String base3 = mk3.getHeadRevision();
    assertFalse(mk3.nodeExists("/test/mk21", b3));
    b3 = mk3.rebase(b3, base3);
    mk2.commit("/", "+\"test/mk22\":{}", null, null);
    mk2.runBackgroundOperations();
    // pick up changes from mk2
    mk3.runBackgroundOperations();
    DocumentNodeState base = ns3.getNode("/", RevisionVector.fromString(base3));
    assertNotNull(base);
    NodeState branchHead = ns3.getNode("/", RevisionVector.fromString(b3));
    assertNotNull(branchHead);
    TrackingDiff diff = new TrackingDiff();
    branchHead.compareAgainstBaseState(base, diff);
    assertEquals(1, diff.added.size());
    assertEquals(Sets.newHashSet("/mk3"), diff.added);
    assertEquals(new HashSet<String>(), diff.deleted);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Test(org.junit.Test)

Example 97 with NodeState

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

the class ConcurrentReadAndAddTest method concurrentReadAdd.

@Test
public void concurrentReadAdd() throws Exception {
    main = Thread.currentThread();
    NodeBuilder builder = ns.getRoot().builder();
    builder.child("test");
    merge(builder);
    final Semaphore sem = new Semaphore(0);
    Thread u = new Thread(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                addNode(i);
                if (i == 20) {
                    sem.release();
                }
            }
        }
    });
    u.setName("writer");
    u.start();
    sem.acquireUninterruptibly();
    readNodes();
    u.join();
    if (!exceptions.isEmpty()) {
        throw exceptions.get(0);
    }
    NodeState test = ns.getRoot().getChildNode("test");
    assertEquals(100, Iterables.size(test.getChildNodeEntries()));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Semaphore(java.util.concurrent.Semaphore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 98 with NodeState

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

the class ClusterTest method fromExternalChange.

@Test
public void fromExternalChange() throws Exception {
    final List<DocumentNodeState> rootStates1 = Lists.newArrayList();
    DocumentNodeStore ns1 = createMK(1, 0).getNodeStore();
    ns1.addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
            rootStates1.add((DocumentNodeState) root);
        }
    });
    final List<DocumentNodeState> rootStates2 = Lists.newArrayList();
    DocumentNodeStore ns2 = createMK(2, 0).getNodeStore();
    ns2.addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
            rootStates2.add((DocumentNodeState) root);
        }
    });
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    rootStates1.clear();
    rootStates2.clear();
    NodeBuilder builder = ns1.getRoot().builder();
    builder.child("foo");
    merge(ns1, builder);
    assertEquals(1, rootStates1.size());
    assertEquals(0, rootStates2.size());
    assertFalse(rootStates1.get(0).isFromExternalChange());
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    assertEquals(1, rootStates1.size());
    assertEquals(1, rootStates2.size());
    assertTrue(rootStates2.get(0).isFromExternalChange());
    NodeState foo = rootStates2.get(0).getChildNode("foo");
    assertTrue(foo instanceof DocumentNodeState);
    assertTrue(((DocumentNodeState) foo).isFromExternalChange());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 99 with NodeState

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

the class CommitContextTest method attributeAddedByCommitHook.

@Test
public void attributeAddedByCommitHook() throws Exception {
    repository = new Oak(store).with(new OpenSecurityProvider()).with(observer).with(new CommitHook() {

        @Nonnull
        @Override
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            CommitContext attrs = (CommitContext) info.getInfo().get(CommitContext.NAME);
            assertNotNull(attrs);
            attrs.set("foo", "bar");
            return after;
        }
    }).createContentRepository();
    session = newSession();
    Root root = session.getLatestRoot();
    Tree tree = root.getTree("/");
    tree.setProperty("a", 1);
    root.commit();
    assertNotNull(observer.info);
    CommitContext attrs = (CommitContext) observer.info.getInfo().get(CommitContext.NAME);
    assertNotNull(attrs.get("foo"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) Oak(org.apache.jackrabbit.oak.Oak) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 100 with NodeState

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

the class AsyncIndexUpdateClusterTestIT method createAsync.

private static AsyncIndexUpdate createAsync(DocumentNodeStore ns, final IndexStatusListener l) {
    IndexEditorProvider p = new TestEditorProvider(new PropertyIndexEditorProvider(), l);
    AsyncIndexUpdate aiu = new AsyncIndexUpdate("async", ns, p) {

        protected boolean updateIndex(NodeState before, String beforeCheckpoint, NodeState after, String afterCheckpoint, String afterTime, AsyncUpdateCallback callback) throws CommitFailedException {
            if (MISSING_NODE == before) {
                l.reindexing();
            }
            return super.updateIndex(before, beforeCheckpoint, after, afterCheckpoint, afterTime, callback);
        }
    };
    aiu.setCloseTimeOut(1);
    return aiu;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)580 Test (org.junit.Test)375 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)254 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)69 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)46 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)45 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)43 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)39 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)36 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)33 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)32 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)29 Nonnull (javax.annotation.Nonnull)28 Tree (org.apache.jackrabbit.oak.api.Tree)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)19 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)18 ArrayList (java.util.ArrayList)17 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)16 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)15