Search in sources :

Example 41 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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 42 with NodeBuilder

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

the class PropertyIndexTest method testCustomConfigNodeTypeFallback.

/**
     * @see <a href="https://issues.apache.org/jira/browse/OAK-666">OAK-666:
     *      Property2Index: node type is used when indexing, but ignored when
     *      querying</a>
     */
@Test
public void testCustomConfigNodeTypeFallback() throws Exception {
    NodeState root = EMPTY_NODE;
    // Add index definitions
    NodeBuilder builder = root.builder();
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo", "extrafoo"), null);
    createIndexDefinition(index, "fooIndexFile", true, false, ImmutableSet.of("foo"), ImmutableSet.of(NT_FILE));
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("a").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "abc");
    builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
    NodeState after = builder.getNodeState();
    // Add an index
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(after, NT_UNSTRUCTURED);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
    assertEquals(ImmutableSet.of("a", "b"), find(lookup, "foo", "abc", f));
    assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "def", f));
    assertEquals(ImmutableSet.of(), find(lookup, "foo", "ghi", f));
    try {
        assertEquals(ImmutableSet.of(), find(lookup, "pqr", "foo", f));
        fail();
    } catch (IllegalArgumentException e) {
    // expected: no index for "pqr"
    }
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 43 with NodeBuilder

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

the class PropertyIndexTest method singleMount.

@Test
public void singleMount() throws Exception {
    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);
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").child("x").setProperty("foo", "abc");
    builder.child("a").child("x").setProperty("foo", "abc");
    builder.child("m").child("n").setProperty("foo", "abc");
    builder.child("m").child("n").child("o").setProperty("foo", "abc");
    builder.child("m").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a", "/m/n").build();
    Mount fooMount = mip.getMountByName("foo");
    Mount defMount = mip.getDefaultMount();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip)));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(indexed, NT_BASE);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed, mip);
    assertEquals(ImmutableSet.of("a", "b/x", "a/x", "m", "m/n", "m/n/o"), find(lookup, "foo", "abc", f));
    assertEquals(ImmutableSet.of(), find(lookup, "foo", "ghi", f));
    assertTrue(getNode(indexed, "/oak:index/foo/:index").exists());
    //Separate node for mount
    assertTrue(getNode(indexed, "/oak:index/foo/" + getNodeForMount(fooMount)).exists());
    //Index entries for paths in foo mount should go to :oak:foo-index
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/a", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/a/x", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/m/n", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/m/n/o", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/a", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/a/x", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/m/n", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/m/n/o", "abc")).exists());
    //All other index entries should go to :index
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/b", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/b/x", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/m", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/b", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/b/x", "abc")).exists());
//System.out.println(NodeStateUtils.toString(getNode(indexed, "/oak:index/foo")));
}
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) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Mount(org.apache.jackrabbit.oak.spi.mount.Mount) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 44 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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)

Example 45 with NodeBuilder

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

the class PropertyIndexInfoProviderTest method emptyIndexEstimate.

@Test
public void emptyIndexEstimate() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    store.merge(builder, HOOK, CommitInfo.EMPTY);
    IndexInfo info = infoProvider.getInfo("/oak:index/foo");
    assertNotNull(info);
    assertEquals("/oak:index/foo", info.getIndexPath());
    assertEquals("property", info.getType());
    assertEquals(-2, info.getLastUpdatedTime());
    assertEquals(0, info.getEstimatedEntryCount());
}
Also used : IndexInfo(org.apache.jackrabbit.oak.plugins.index.IndexInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)948 Test (org.junit.Test)704 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)253 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)84 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)74 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)73 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)70 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)67 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)60 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)52 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)49 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)43 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)31 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)31 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)29 Blob (org.apache.jackrabbit.oak.api.Blob)28 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)24 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)22 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)21 Nonnull (javax.annotation.Nonnull)20