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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations