Search in sources :

Example 16 with CommitInfo

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));
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 17 with CommitInfo

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"));
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 18 with CommitInfo

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"));
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 19 with CommitInfo

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Observable(org.apache.jackrabbit.oak.spi.commit.Observable) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 20 with CommitInfo

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());
}
Also used : CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Aggregations

CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)39 Test (org.junit.Test)29 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)23 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)16 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)11 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)9 Nonnull (javax.annotation.Nonnull)7 Observer (org.apache.jackrabbit.oak.spi.commit.Observer)7 SimpleCommitContext (org.apache.jackrabbit.oak.core.SimpleCommitContext)6 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)6 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)3 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)3 ChangeSet (org.apache.jackrabbit.oak.plugins.observation.ChangeSet)3 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)3 Observable (org.apache.jackrabbit.oak.spi.commit.Observable)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3