Search in sources :

Example 31 with NodeBuilder

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

the class DocumentNodeStoreTest method sameSeenAtRevision.

// OAK-3411
@Test
public void sameSeenAtRevision() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setClusterId(1).getNodeStore();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setClusterId(2).getNodeStore();
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("test");
    merge(ns2, b2);
    ns2.runBackgroundOperations();
    ns1.runBackgroundOperations();
    NodeBuilder b1 = ns1.getRoot().builder();
    assertTrue(b1.hasChildNode("test"));
    b1.child("test").remove();
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    DocumentNodeStore ns3 = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setClusterId(3).getNodeStore();
    ns3.setMaxBackOffMillis(0);
    NodeBuilder b3 = ns3.getRoot().builder();
    assertFalse(b3.hasChildNode("test"));
    b3.child("test");
    merge(ns3, b3);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 32 with NodeBuilder

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

the class OrderedPropertyIndexEditorProviderTest method withIndexMultipleNodes.

@Test
public void withIndexMultipleNodes() throws RepositoryException, CommitFailedException {
    final int threshold = 5;
    final int nodes = 16;
    final int traces = nodes / threshold;
    OrderedPropertyIndexEditorProvider.setThreshold(threshold);
    final List<String> expected = Collections.nCopies(traces, OrderedIndex.DEPRECATION_MESSAGE);
    NodeBuilder root = InitialContent.INITIAL_CONTENT.builder();
    createIndexDef(root);
    custom.starting();
    for (int i = 0; i < nodes; i++) {
        NodeState before = root.getNodeState();
        root.child("n" + i).setProperty(indexedProperty, "dead" + i);
        NodeState after = root.getNodeState();
        root = hook.processCommit(before, after, CommitInfo.EMPTY).builder();
    }
    assertThat(custom.getLogs(), is(expected));
    custom.finished();
    assertFalse(root.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(indexName).getChildNode(INDEX_CONTENT_NODE_NAME).exists());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 33 with NodeBuilder

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

the class OrderedPropertyIndexEditorProviderTest method withIndexDefSingleNode.

@Test
public void withIndexDefSingleNode() throws RepositoryException, CommitFailedException {
    NodeBuilder root = InitialContent.INITIAL_CONTENT.builder();
    createIndexDef(root);
    NodeState before = root.getNodeState();
    root.child("n1").setProperty(indexedProperty, "dead");
    NodeState after = root.getNodeState();
    custom.starting();
    root = hook.processCommit(before, after, CommitInfo.EMPTY).builder();
    assertEquals(1, custom.getLogs().size());
    assertThat(custom.getLogs(), hasItem(OrderedIndex.DEPRECATION_MESSAGE));
    custom.finished();
    NodeBuilder b = root.getChildNode(IndexConstants.INDEX_DEFINITIONS_NODE_TYPE).getChildNode(indexName).getChildNode(IndexConstants.INDEX_CONTENT_NODE_NAME);
    assertFalse("nothing should have been touched under the actual index", b.exists());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 34 with NodeBuilder

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

the class PropertyIndexTest method testUpdateUnique.

@Test
public void testUpdateUnique() throws Exception {
    NodeState root = EMPTY_NODE;
    NodeBuilder builder = root.builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, true, ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    NodeState done = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // remove, and then re-add the same node
    builder = done.builder();
    builder.child("a").setProperty("foo", "abc");
    after = builder.getNodeState();
    // apply the changes to the state before adding the entries
    done = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    // re-apply the changes
    done = HOOK.processCommit(done, 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) Test(org.junit.Test)

Example 35 with NodeBuilder

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

the class PropertyIndexTest method valuePattern.

@Test
public void valuePattern() throws Exception {
    NodeState root = EMPTY_NODE;
    // Add index definitions
    NodeBuilder builder = root.builder();
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder indexDef = createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo"), null);
    indexDef.setProperty(IndexConstants.VALUE_PATTERN, "(a.*|b)");
    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", "a");
    builder.child("a1").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a1");
    builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "b");
    builder.child("c").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "c");
    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);
    PropertyIndex pIndex = new PropertyIndex(Mounts.defaultMountInfoProvider());
    assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "a", f));
    assertEquals(ImmutableSet.of("a1"), find(lookup, "foo", "a1", f));
    assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "b", f));
    // expected: no index for "is not null"
    assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
    ArrayList<PropertyValue> list = new ArrayList<PropertyValue>();
    list.add(PropertyValues.newString("c"));
    f.restrictPropertyAsList("foo", list);
    // expected: no index for value c
    assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
    f = createFilter(after, NT_UNSTRUCTURED);
    list = new ArrayList<PropertyValue>();
    list.add(PropertyValues.newString("a"));
    f.restrictPropertyAsList("foo", list);
    // expected: no index for value a
    assertTrue(pIndex.getCost(f, indexed) < Double.POSITIVE_INFINITY);
}
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) ArrayList(java.util.ArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) 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