Search in sources :

Example 16 with NodeState

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

the class PrivilegeValidatorTest method testUnknownAggregate.

@Test
public void testUnknownAggregate() {
    try {
        NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE).setProperty(REP_BITS, 8).setProperty(REP_AGGREGATES, ImmutableList.of("unknown", JCR_READ), Type.NAMES).getNodeState();
        PrivilegeValidator validator = new PrivilegeValidator(root, root);
        validator.childNodeAdded("test", newDef);
        fail("unknown aggregate must be detected.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(51, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 17 with NodeState

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

the class PrivilegeValidatorTest method testCircularAggregate2.

@Test
public void testCircularAggregate2() {
    try {
        createPrivilegeTree("test2", "test");
        NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE).setProperty(REP_BITS, 8).setProperty(REP_AGGREGATES, ImmutableList.of("test2", JCR_READ), Type.NAMES).getNodeState();
        PrivilegeValidator validator = new PrivilegeValidator(root, root);
        validator.childNodeAdded("test", newDef);
        fail("unknown aggregate must be detected.");
    } catch (CommitFailedException e) {
        assertTrue(e.isConstraintViolation());
        assertEquals(52, e.getCode());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 18 with NodeState

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

the class BackgroundObserverTest method contentChanged.

private static void contentChanged(Observer observer, long value) {
    NodeState node = EMPTY_NODE.builder().setProperty("p", value).getNodeState();
    observer.contentChanged(node, COMMIT_INFO);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState)

Example 19 with NodeState

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

the class PrefilteringBackgroundObserverTest method testFlipping.

@Test
public void testFlipping() throws Exception {
    final int queueLength = 2000;
    init(queueLength);
    // initialize observer with an initial contentChanged
    // (see ChangeDispatcher#addObserver)
    {
        compositeObserver.contentChanged(p(-1), CommitInfo.EMPTY_EXTERNAL);
    }
    // Part 1 : first run with filtersEvaluatedMapWithEmptyObservers - empty or null shouldn't matter, it's excluded in both cases
    for (int k = 0; k < 1000; k++) {
        CommitInfo info;
        if (k % 2 == 1) {
            info = includingCommitInfo;
        } else {
            info = excludingCommitInfo;
        }
        final NodeState p = p(k);
        compositeObserver.contentChanged(p, info);
        if (k % 10 == 0) {
            executeRunnables(runnableQ, 10);
        }
    }
    executeRunnables(runnableQ, 10);
    // changed from 501 with OAK-5121
    assertEquals(500, received.size());
    // changed from 500 with OAK-5121
    assertEquals(499, resetCallCnt);
    // Part 2 : run with filtersEvaluatedMapWithNullObservers - empty or null shouldn't matter, it's excluded in both cases
    received.clear();
    resetCallCnt = 0;
    for (int k = 0; k < 1000; k++) {
        CommitInfo info;
        if (k % 2 == 1) {
            info = includingCommitInfo;
        } else {
            info = excludingCommitInfo;
        }
        final NodeState p = p(k);
        compositeObserver.contentChanged(p, info);
        if (k % 10 == 0) {
            executeRunnables(runnableQ, 10);
        }
    }
    executeRunnables(runnableQ, 10);
    assertEquals(500, received.size());
    assertEquals(500, resetCallCnt);
    // Part 3 : unlike the method name suggests, this variant tests with the filter disabled, so should receive all events normally
    received.clear();
    resetCallCnt = 0;
    for (int k = 0; k < 1000; k++) {
        CommitInfo info;
        if (k % 2 == 1) {
            info = includingCommitInfo;
        } else {
            info = includingCommitInfo;
        }
        final NodeState p = p(k);
        compositeObserver.contentChanged(p, info);
        if (k % 10 == 0) {
            executeRunnables(runnableQ, 10);
        }
    }
    executeRunnables(runnableQ, 10);
    assertEquals(1000, received.size());
    assertEquals(0, resetCallCnt);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Test(org.junit.Test)

Example 20 with NodeState

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

the class EffectiveType method getTypeNames.

@Nonnull
Set<String> getTypeNames() {
    Set<String> names = newHashSet();
    for (NodeState type : types) {
        names.add(type.getName(JCR_NODETYPENAME));
        addAll(names, type.getNames(REP_SUPERTYPES));
    }
    return names;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Nonnull(javax.annotation.Nonnull)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)779 Test (org.junit.Test)498 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)335 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)94 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)61 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)60 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)54 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)48 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)46 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)41 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)36 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)33 Nonnull (javax.annotation.Nonnull)32 Tree (org.apache.jackrabbit.oak.api.Tree)29 ArrayList (java.util.ArrayList)25 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.plugins.migration.NodeStateTestUtils.getNodeState)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)22 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)22 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)17