Search in sources :

Example 1 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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);
}
Also used : 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) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 2 with EditorHook

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

the class ReferenceIndexTest method removeReferencedNode.

@Test
public void removeReferencedNode() throws Exception {
    NodeState root = INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty(createProperty(JCR_UUID, "u1", Type.STRING));
    builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE));
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new ReferenceEditorProvider()));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    builder = indexed.builder();
    builder.getChildNode("a").remove();
    thrown.expect(CommitFailedException.class);
    thrown.expectMessage("OakIntegrity0001: Unable to delete referenced node");
    hook.processCommit(indexed, builder.getNodeState(), CommitInfo.EMPTY);
}
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) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with EditorHook

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

the class NodeStoreTest method addExistingNode.

@Test
public void addExistingNode() throws CommitFailedException {
    // FIXME OAK-1550 Incorrect handling of addExistingNode conflict in NodeStore
    assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_MEM);
    assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_NS);
    assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_RDB);
    CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder b2 = store.getRoot().builder();
    // rather the in memory one from AbstractRebaseDiff
    for (int k = 0; k < 1002; k++) {
        b1.setChildNode("n" + k);
        b2.setChildNode("m" + k);
    }
    b1.setChildNode("conflict");
    b2.setChildNode("conflict");
    store.merge(b1, hook, CommitInfo.EMPTY);
    store.merge(b2, hook, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 4 with EditorHook

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

the class NodeStoreTest method addChangeChangedJCRLastModified.

@Test
public void addChangeChangedJCRLastModified() throws CommitFailedException {
    CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
    NodeBuilder b = store.getRoot().builder();
    Calendar calendar = Calendar.getInstance();
    b.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    store.merge(b, hook, CommitInfo.EMPTY);
    NodeBuilder b1 = store.getRoot().builder();
    NodeBuilder b2 = store.getRoot().builder();
    calendar.add(Calendar.MINUTE, 1);
    b1.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    calendar.add(Calendar.MINUTE, 1);
    b2.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
    b1.setChildNode("conflict");
    b2.setChildNode("conflict");
    store.merge(b1, hook, CommitInfo.EMPTY);
    store.merge(b2, hook, CommitInfo.EMPTY);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Calendar(java.util.Calendar) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 5 with EditorHook

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

the class AtomicCounterEditorTest method singleNodeAsync.

@Test
public void singleNodeAsync() throws CommitFailedException, InterruptedException, ExecutionException {
    NodeStore store = new MemoryNodeStore();
    MyExecutor exec1 = new MyExecutor();
    Whiteboard board = new DefaultWhiteboard();
    EditorHook hook1 = new EditorHook(new TestableACEProvider(CLUSTER_1, exec1, store, board));
    NodeBuilder builder, root;
    PropertyState p;
    board.register(CommitHook.class, EmptyHook.INSTANCE, null);
    root = store.getRoot().builder();
    builder = root.child("c");
    builder = setMixin(builder);
    builder = incrementBy(builder, INCREMENT_BY_1);
    store.merge(root, hook1, CommitInfo.EMPTY);
    // as we're providing all the information we expect the counter not to be consolidated for
    // as long as the scheduled process has run
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue(builder.exists());
    p = builder.getProperty(PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PROP_COUNTER);
    assertNull(p);
    // executing the consolidation
    exec1.execute();
    // fetching the latest store state to see the changes
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue("the counter node should exists", builder.exists());
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId(), PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId()), 1);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) LongPropertyState(org.apache.jackrabbit.oak.plugins.memory.LongPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) 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