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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations