use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method commitRootSameAsModifiedPathWithConflicts.
@Test
public void commitRootSameAsModifiedPathWithConflicts() throws Exception {
MemoryDocumentStore store = new MemoryDocumentStore(true);
final DocumentNodeStore ns = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(store).getNodeStore();
NodeBuilder builder = ns.getRoot().builder();
builder.child("a").child("b").setProperty("p", 0L);
merge(ns, builder);
final List<Throwable> exceptions = synchronizedList(Lists.newArrayList());
Runnable task = new Runnable() {
CommitHook hook = new CompositeHook(new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
@Override
public void run() {
try {
for (int i = 0; i < 100; i++) {
NodeBuilder builder = ns.getRoot().builder();
NodeBuilder b = builder.child("a").child("b");
PropertyState p = b.getProperty("p");
assertNotNull(p);
long value = p.getValue(Type.LONG) + 1;
b.setProperty(p.getName(), value);
try {
ns.merge(builder, hook, CommitInfo.EMPTY);
} catch (CommitFailedException e) {
if (e.asRepositoryException() instanceof InvalidItemStateException) {
// this is fine and may happen from time to
// time because the test updates the same
// property concurrently
} else {
// anything else is unexpected
exceptions.add(e);
}
}
}
} catch (AssertionError e) {
exceptions.add(e);
}
}
};
List<Thread> threads = Lists.newArrayList();
for (int i = 0; i < 4; i++) {
threads.add(new Thread(task));
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
// check updates are consecutive
NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/a/b"));
assertNotNull(doc);
long previousValue = -1;
List<String> values = Lists.newArrayList(doc.getLocalMap("p").values());
for (String v : Lists.reverse(values)) {
long currentValue = Long.parseLong(v);
assertEquals(previousValue + 1, currentValue);
previousValue = currentValue;
}
for (Throwable e : exceptions) {
fail(e.toString());
}
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class DocumentBundlingTest method recreatedBundledNode2.
@Test
public void recreatedBundledNode2() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder fileNode = newNode("nt:file");
fileNode.child("jcr:content").setProperty("jcr:data", "foo");
builder.child("test").setChildNode("book.jpg", fileNode.getNodeState());
merge(builder);
builder = store.getRoot().builder();
builder.child("a");
// In this case we recreate the node in CommitHook
store.merge(builder, new EditorHook(new EditorProvider() {
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
return new BookRecreatingEditor(builder);
}
}), CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class NodeStoreUtils method mergeWithConcurrentCheck.
static void mergeWithConcurrentCheck(NodeStore nodeStore, NodeBuilder builder, IndexEditorProvider indexEditorProvider) throws CommitFailedException {
CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, new EditorHook(new IndexUpdateProvider(indexEditorProvider, null, true)), new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(singletonList(new ConflictValidatorProvider()))));
nodeStore.merge(builder, hooks, createCommitInfo());
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class LuceneIndexEditor2Test method simplePropertyUpdateCallback.
@Test
public void simplePropertyUpdateCallback() throws Exception {
IndexDefinitionBuilder defnb = new IndexDefinitionBuilder();
defnb.indexRule("nt:base").property("foo").propertyIndex();
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").setProperty("foo", "bar");
builder.child("a").setProperty("foo2", "bar");
builder.child("a").child("b");
before = hook.processCommit(root, builder.getNodeState(), CommitInfo.EMPTY);
propCallback.state.assertState("/a", "foo", UpdateState.ADDED);
assertEquals(1, propCallback.invocationCount);
assertEquals(1, propCallback.doneInvocationCount);
propCallback.reset();
// Property updated
builder = before.builder();
builder.child("a").setProperty("foo", "bar2");
builder.child("a").setProperty("foo2", "bar2");
before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
propCallback.state.assertState("/a", "foo", UpdateState.UPDATED);
assertEquals(1, propCallback.invocationCount);
propCallback.reset();
// Property deleted
builder = before.builder();
builder.child("a").removeProperty("foo");
builder.child("a").removeProperty("foo2");
before = hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
propCallback.state.assertState("/a", "foo", UpdateState.DELETED);
assertEquals(1, propCallback.invocationCount);
propCallback.reset();
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class LuceneIndexEditor2Test method basics.
@Test
public void basics() throws Exception {
IndexDefinitionBuilder defnb = new IndexDefinitionBuilder();
defnb.indexRule("nt:base").property("foo").propertyIndex();
NodeState defnState = defnb.build();
IndexDefinition defn = new IndexDefinition(root, defnState, indexPath);
LuceneIndexEditorContext ctx = newContext(defnState.builder(), defn, true);
EditorHook hook = createHook(ctx);
updateBefore(defnb);
NodeBuilder builder = before.builder();
builder.child("a").setProperty("foo", "bar");
hook.processCommit(root, builder.getNodeState(), CommitInfo.EMPTY);
assertThat(writer.docs.keySet(), containsInAnyOrder("/a"));
}
Aggregations