use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method exceptionHandlingInCommit.
@Test
public void exceptionHandlingInCommit() throws Exception {
DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore();
final TestException testException = new TestException();
final AtomicBoolean failCommit = new AtomicBoolean();
ns.addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
if (failCommit.get()) {
throw testException;
}
}
});
NodeBuilder b1 = ns.getRoot().builder();
b1.child("parent");
failCommit.set(true);
try {
merge(ns, b1);
fail();
} catch (Exception e) {
assertSame(testException, Throwables.getRootCause(e));
}
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class NodeStoreTest method beforeCommitHook.
@Test
public void beforeCommitHook() throws CommitFailedException {
NodeState root = store.getRoot();
NodeBuilder rootBuilder = root.builder();
NodeBuilder testBuilder = rootBuilder.child("test");
NodeBuilder newNodeBuilder = testBuilder.child("newNode");
newNodeBuilder.setProperty("n", 42);
testBuilder.getChildNode("a").remove();
store.merge(rootBuilder, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) {
NodeBuilder rootBuilder = after.builder();
NodeBuilder testBuilder = rootBuilder.child("test");
testBuilder.child("fromHook");
return rootBuilder.getNodeState();
}
}, CommitInfo.EMPTY);
NodeState test = store.getRoot().getChildNode("test");
assertTrue(test.getChildNode("newNode").exists());
assertTrue(test.getChildNode("fromHook").exists());
assertFalse(test.getChildNode("a").exists());
assertEquals(42, (long) test.getChildNode("newNode").getProperty("n").getValue(LONG));
assertEquals(test, store.getRoot().getChildNode("test"));
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class NodeStoreTest method rebaseWithFailedMerge.
// OAK-1320
@Test
public void rebaseWithFailedMerge() throws CommitFailedException {
NodeBuilder rootBuilder = store.getRoot().builder();
rootBuilder.child("foo");
// commit something in between to force rebase
NodeBuilder b = store.getRoot().builder();
b.child("bar");
store.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY);
try {
store.merge(rootBuilder, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
throw new CommitFailedException("", 0, "commit rejected");
}
}, CommitInfo.EMPTY);
fail("must throw CommitFailedException");
} catch (CommitFailedException e) {
// expected
}
// merge again
NodeState root = store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
assertTrue(root.hasChildNode("bar"));
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class CheckpointTest method noContentChangeForCheckpoints.
@Test
public void noContentChangeForCheckpoints() throws Exception {
final AtomicInteger invocationCount = new AtomicInteger();
((Observable) store).addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
invocationCount.incrementAndGet();
}
});
invocationCount.set(0);
String cp = store.checkpoint(Long.MAX_VALUE);
assertEquals(0, invocationCount.get());
store.release(cp);
assertEquals(0, invocationCount.get());
}
use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.
the class ExternalIndexObserverTest method assertIndexing.
private void assertIndexing(Observer observer) {
Multimap<String, String> indexedPaths = HashMultimap.create();
indexedPaths.put("/a", "/oak:index/foo");
commitContext.set(LuceneDocumentHolder.NAME, new IndexedPaths(indexedPaths));
CommitInfo ci = newCommitInfo();
when(queue.add(any(LuceneDoc.class))).thenReturn(true);
when(tracker.getIndexDefinition("/oak:index/foo")).thenReturn(createNRTIndex("nt:base"));
NodeBuilder nb = INITIAL_CONTENT.builder();
nb.child("a").setProperty("foo", "bar");
observer.contentChanged(nb.getNodeState(), ci);
ArgumentCaptor<LuceneDoc> doc = ArgumentCaptor.forClass(LuceneDoc.class);
verify(queue).add(doc.capture());
assertEquals("/oak:index/foo", doc.getValue().getIndexPath());
}
Aggregations