Search in sources :

Example 1 with MissingIndexProviderStrategy

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy in project jackrabbit-oak by apache.

the class IndexUpdateTest method testMissingProviderFailsCommit.

/**
 * OAK-3505 Provide an optionally stricter policy for missing synchronous
 * index editor providers
 */
@Test
public void testMissingProviderFailsCommit() throws Exception {
    final IndexUpdateCallback noop = new IndexUpdateCallback() {

        @Override
        public void indexUpdate() {
        }
    };
    final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
    mips.setFailOnMissingIndexProvider(true);
    EditorHook hook = new EditorHook(new EditorProvider() {

        @Override
        public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
            return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
        }
    });
    NodeState before = builder.getNodeState();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
    builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
    builder.child("testRoot").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    try {
        hook.processCommit(before, after, CommitInfo.EMPTY);
        fail("commit should fail on missing index provider");
    } catch (CommitFailedException ex) {
    // expected
    }
}
Also used : MissingIndexProviderStrategy(org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Aggregations

CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 MissingIndexProviderStrategy (org.apache.jackrabbit.oak.plugins.index.IndexUpdate.MissingIndexProviderStrategy)1 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)1 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)1 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)1 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)1 Editor (org.apache.jackrabbit.oak.spi.commit.Editor)1 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)1 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 Test (org.junit.Test)1