Search in sources :

Example 6 with NodeState

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

the class PropertyIndexTest method traversalWarning.

@Test
public void traversalWarning() throws Exception {
    ListAppender appender = createAndRegisterAppender();
    int testDataSize = ContentMirrorStoreStrategy.TRAVERSING_WARN;
    NodeState indexed = createTestData(testDataSize);
    assertEquals(testDataSize, getResultSize(indexed, "foo", "bar"));
    assertFalse(appender.list.isEmpty());
    appender.list.clear();
    testDataSize = 100;
    indexed = createTestData(100);
    assertEquals(testDataSize, getResultSize(indexed, "foo", "bar"));
    assertTrue("Warning should not be logged for traversing " + testDataSize, appender.list.isEmpty());
    deregisterAppender(appender);
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ListAppender(ch.qos.logback.core.read.ListAppender) Test(org.junit.Test)

Example 7 with NodeState

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

the class PropertyIndexTest method createTestData.

private NodeState createTestData(int entryCount) throws CommitFailedException {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    // disable the estimation
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    int depth = ContentMirrorStoreStrategy.TRAVERSING_WARN / entryCount + 10;
    for (int i = 0; i < entryCount; i++) {
        NodeBuilder parentNode = builder.child("n" + i);
        for (int j = 0; j < depth; j++) {
            parentNode = parentNode.child("c" + j);
        }
        parentNode.setProperty("foo", "bar");
    }
    NodeState after = builder.getNodeState();
    return HOOK.processCommit(before, after, CommitInfo.EMPTY);
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 8 with NodeState

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

the class PropertyIndexTest method mountAndUniqueIndexes.

@Test(expected = CommitFailedException.class)
public void mountAndUniqueIndexes() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, true, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a").build();
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip)));
    // should throw
    hook.processCommit(before, after, CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 9 with NodeState

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

the class PropertyIndexStatsTest method prepareStore.

private void prepareStore() throws CommitFailedException {
    activateMBean();
    NodeState root = store.getRoot();
    NodeBuilder builder = root.builder();
    new InitialContent().initialize(builder);
    store.merge(builder, HOOK, CommitInfo.EMPTY);
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 10 with NodeState

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

the class ReferenceIndexTest method removeReferencedNode.

@Test
public void removeReferencedNode() throws Exception {
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty(createProperty(JCR_UUID, "u1", Type.STRING));
    builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE));
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider()));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    builder = indexed.builder();
    builder.getChildNode("a").remove();
    thrown.expect(CommitFailedException.class);
    thrown.expectMessage("OakIntegrity0001: Unable to delete referenced node");
    hook.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

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