Search in sources :

Example 61 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.

the class LuceneIndexEditorTest method copyOnWriteAndLocks.

@Test
public void copyOnWriteAndLocks() throws Exception {
    assumeFalse(CIHelper.windows());
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    IndexCopier copier = new IndexCopier(executorService, temporaryFolder.getRoot());
    FailOnDemandEditorProvider failingProvider = new FailOnDemandEditorProvider();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new CompositeIndexEditorProvider(failingProvider, new LuceneIndexEditorProvider(copier))));
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder nb = newLuceneIndexDefinitionV2(index, "lucene", of(TYPENAME_STRING));
    IndexUtils.createIndexDefinition(index, "failingIndex", false, false, of("foo"), null);
    // 1. Get initial set indexed. So that next cycle is normal indexing
    NodeState indexed = hook.processCommit(EMPTY_NODE, builder.getNodeState(), CommitInfo.EMPTY);
    builder = indexed.builder();
    NodeState before = indexed;
    builder.child("test").setProperty("a", "fox is jumping");
    NodeState after = builder.getNodeState();
    // 2. Ensure that Lucene gets triggered but close is not called
    failingProvider.setShouldFail(true);
    try {
        hook.processCommit(before, after, CommitInfo.EMPTY);
        fail();
    } catch (CommitFailedException ignore) {
    }
    // 3. Disable the troubling editor
    failingProvider.setShouldFail(false);
    // 4. Now commit should process fine
    hook.processCommit(before, after, CommitInfo.EMPTY);
    executorService.shutdown();
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ExecutorService(java.util.concurrent.ExecutorService) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) Test(org.junit.Test)

Example 62 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.

the class UniqueIndexNodeStoreCheckerTest method populateStore.

private void populateStore(NodeStore ns, Consumer<NodeBuilder> action) throws CommitFailedException {
    NodeBuilder builder = ns.getRoot().builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, true, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    action.accept(builder);
    ns.merge(builder, new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip))), CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 63 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.

the class NodeStoreDiffTest method diffWithConflict.

@Test
public void diffWithConflict() throws Exception {
    // Last rev on /var would be 1-0-1
    createNodes("/var/a", "/var/b/b1");
    // 1. Dummy commits to bump the version no
    createNodes("/fake/b");
    createNodes("/fake/c");
    // Root rev = 3-0-1
    // Root rev = 3-0-1
    // 2. Create a node under /var/a but hold on commit
    NodeBuilder b1 = ns.getRoot().builder();
    createNodes(b1, "/var/a/a1");
    // 3. Remove a node under /var/b and commit it
    NodeBuilder b2 = ns.getRoot().builder();
    b2.child("var").child("b").child("b1").remove();
    merge(b2);
    // 4. Now merge and commit the changes in b1 and include conflict hooks
    // For now exception would be thrown
    ns.merge(b1, new CompositeHook(ConflictHook.of(new AnnotatingConflictHandler()), new EditorHook(new ConflictValidatorProvider())), CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) AnnotatingConflictHandler(org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test)

Example 64 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.

the class IndexImporterTest method getFooIndexNodeState.

private NodeState getFooIndexNodeState() throws CommitFailedException {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null);
    builder.child("a").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider()));
    NodeState indexed = hook.processCommit(EMPTY_NODE, after, CommitInfo.EMPTY);
    return indexed.getChildNode("oak:index").getChildNode("fooIndex");
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 65 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.

the class PropertyIndexTest method mountWithCommitInWritableMount.

@Test
public void mountWithCommitInWritableMount() 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("content").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("foo", "/readOnly").build();
    CompositeHook hook = new CompositeHook(new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip))), new EditorHook(new ValidatorProvider() {

        protected Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
            return new PrivateStoreValidator("/", mip);
        }
    }));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    Mount defMount = mip.getDefaultMount();
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/content", "abc")).exists());
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Mount(org.apache.jackrabbit.oak.spi.mount.Mount) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider) Test(org.junit.Test)

Aggregations

EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)69 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)46 Test (org.junit.Test)44 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)43 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)24 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)14 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)11 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)11 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)11 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)11 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)8 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)7 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)7 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)7 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)6 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)6 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)6 Before (org.junit.Before)6