use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.
the class PropertyIndexTest method testPathAwarePropertyLookup.
@Test
public void testPathAwarePropertyLookup() throws Exception {
NodeState root = INITIAL_CONTENT;
// Add index definition
NodeBuilder builder = root.builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("a").setProperty("foo", "abc");
builder.child("b").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
f.restrictPath("/a", Filter.PathRestriction.ALL_CHILDREN);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "abc", f));
}
use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.
the class PropertyIndexTest method testPathInclude.
@Test
public void testPathInclude() 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(createProperty(PROP_INCLUDED_PATHS, of("/test/a"), Type.STRINGS));
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("test").child("a").setProperty("foo", "abc");
builder.child("test").child("b").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("test/a"), find(lookup, "foo", "abc", f));
}
use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.
the class PropertyIndexTest method testUniqueByTypeKO.
@Test(expected = CommitFailedException.class)
public void testUniqueByTypeKO() throws Exception {
NodeState root = EMPTY_NODE;
// Add index definition
NodeBuilder builder = root.builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, true, ImmutableSet.of("foo"), ImmutableSet.of("typeFoo"));
NodeState before = builder.getNodeState();
builder.child("a").setProperty(JCR_PRIMARYTYPE, "typeFoo", Type.NAME).setProperty("foo", "abc");
builder.child("b").setProperty(JCR_PRIMARYTYPE, "typeFoo", Type.NAME).setProperty("foo", "abc");
NodeState after = builder.getNodeState();
// should throw
HOOK.processCommit(before, after, CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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);
}
use of org.apache.jackrabbit.oak.spi.state.NodeBuilder 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);
}
Aggregations