use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method disableSupersededIndex.
// OAK-6864
@Test
public void disableSupersededIndex() throws Exception {
IndexEditorProvider propIdxEditorProvider = new PropertyIndexEditorProvider();
EditorHook propIdxHook = new EditorHook(new IndexUpdateProvider(propIdxEditorProvider));
MemoryNodeStore store = new MemoryNodeStore();
String supersededIndexName = "supersededIndex";
String supersedingIndexName = "supersedingIndex";
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, propIdxEditorProvider);
// Create superseded index def and merge it
NodeBuilder builder = store.getRoot().builder();
NodeBuilder oakIndex = builder.child(INDEX_DEFINITIONS_NAME);
createIndexDefinition(oakIndex, supersededIndexName, true, false, ImmutableSet.of("foo"), null);
store.merge(builder, propIdxHook, CommitInfo.EMPTY);
// Create superseding index def and merge it
builder = store.getRoot().builder();
oakIndex = builder.child(INDEX_DEFINITIONS_NAME);
createIndexDefinition(oakIndex, supersedingIndexName, true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, ImmutableSet.of("async", "nrt"), Type.STRINGS).setProperty(SUPERSEDED_INDEX_PATHS, INDEX_DEFINITIONS_NAME + "/" + supersededIndexName);
store.merge(builder, propIdxHook, CommitInfo.EMPTY);
// add a change and index it thought superseded index
builder = store.getRoot().builder();
builder.child("testNode1").setProperty("foo", "bar");
store.merge(builder, propIdxHook, CommitInfo.EMPTY);
// verify state
NodeState supersededIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersededIndexName);
assertEquals("Index disabled too early", "property", supersededIndex.getString("type"));
assertFalse("Don't set :disableIndexesOnNextCycle on superseded index", supersededIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
NodeState supersedingIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersedingIndexName);
assertFalse("Don't set :disableIndexesOnNextCycle on superseding index just yet", supersedingIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
// do an async run - this should reindex the superseding index
async.run();
// verify state
supersededIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersededIndexName);
assertEquals("Index disabled too early", "property", supersededIndex.getString("type"));
assertFalse("Don't set :disableIndexesOnNextCycle on superseded index", supersededIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
supersedingIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersedingIndexName);
assertTrue(":disableIndexesOnNextCycle not set on superseding index after reindexing run", supersedingIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
// add another change and index it thought superseded index
builder = store.getRoot().builder();
store.getRoot().builder().child("testNode2").setProperty("foo", "bar");
store.merge(builder, propIdxHook, CommitInfo.EMPTY);
// verify state
supersededIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersededIndexName);
assertEquals("Index disabled too early", "property", supersededIndex.getString("type"));
assertFalse("Don't set :disableIndexesOnNextCycle on superseded index", supersededIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
supersedingIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersedingIndexName);
assertTrue(":disableIndexesOnNextCycle not set on superseding index after reindexing run", supersedingIndex.getBoolean(DISABLE_INDEXES_ON_NEXT_CYCLE));
// do another async run - indexes should get disabled now
async.run();
// verify state
supersededIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersededIndexName);
assertEquals("Index yet not disabled", "disabled", supersededIndex.getString("type"));
assertFalse("Don't set :disableIndexesOnNextCycle on superseded index", supersededIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
supersedingIndex = store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(supersedingIndexName);
assertFalse("Don't keep :disableIndexesOnNextCycle on superseding index after disabling", supersedingIndex.hasProperty(DISABLE_INDEXES_ON_NEXT_CYCLE));
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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")));
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class TestUtil method registerNodeType.
public static void registerNodeType(NodeBuilder builder, String nodeTypeDefn) {
// Taken from org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent
NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
NodeStore store = new MemoryNodeStore(base);
Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null);
NodeTypeRegistry.register(root, IOUtils.toInputStream(nodeTypeDefn), "test node types");
NodeState target = store.getRoot();
target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class LuceneIndexAggregation2Test method createRepository.
@Override
protected ContentRepository createRepository() {
LuceneIndexProvider provider = new LuceneIndexProvider();
return new Oak().with(new InitialContent() {
@Override
public void initialize(@Nonnull NodeBuilder builder) {
super.initialize(builder);
// registering additional node types for wider testing
InputStream stream = null;
try {
stream = LuceneIndexAggregation2Test.class.getResourceAsStream("test_nodetypes.cnd");
NodeState base = builder.getNodeState();
NodeStore store = new MemoryNodeStore(base);
Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null);
NodeTypeRegistry.register(root, stream, "testing node types");
NodeState target = store.getRoot();
target.compareAgainstBaseState(base, new ApplyDiff(builder));
} catch (Exception e) {
LOG.error("Error while registering required node types. Failing here", e);
fail("Error while registering required node types");
} finally {
printNodeTypes(builder);
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
LOG.debug("Ignoring exception on stream closing.", e);
}
}
}
}
}).with(new OpenSecurityProvider()).with(((QueryIndexProvider) provider.with(getNodeAggregator()))).with((Observer) provider).with(new LuceneIndexEditorProvider()).createContentRepository();
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class LuceneIndexEditor2Test method relativeProperties.
@Test
public void relativeProperties() throws Exception {
IndexDefinitionBuilder defnb = new IndexDefinitionBuilder();
defnb.indexRule("nt:base").property("jcr:content/metadata/foo").propertyIndex();
defnb.aggregateRule("nt:base").include("*");
NodeState defnState = defnb.build();
IndexDefinition defn = new IndexDefinition(root, defnState, indexPath);
LuceneIndexEditorContext ctx = newContext(defnState.builder(), defn, true);
ctx.setPropertyUpdateCallback(propCallback);
EditorHook hook = createHook(ctx);
updateBefore(defnb);
// Property added
NodeBuilder builder = before.builder();
builder.child("a").child("jcr:content").child("metadata").setProperty("foo", "bar");
builder.child("a").setProperty("foo2", "bar");
before = hook.processCommit(root, builder.getNodeState(), CommitInfo.EMPTY);
propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.ADDED);
assertEquals(1, propCallback.invocationCount);
propCallback.reset();
// Property updated
builder = before.builder();
builder.child("a").child("jcr:content").child("metadata").setProperty("foo", "bar2");
builder.child("a").setProperty("foo2", "bar2");
before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.UPDATED);
assertEquals(1, propCallback.invocationCount);
propCallback.reset();
// Property deleted
builder = before.builder();
builder.child("a").child("jcr:content").child("metadata").removeProperty("foo");
builder.child("a").removeProperty("foo2");
before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
propCallback.state.assertState("/a", "jcr:content/metadata/foo", UpdateState.DELETED);
assertEquals(1, propCallback.invocationCount);
propCallback.reset();
}
Aggregations