Search in sources :

Example 1 with Observable

use of org.apache.jackrabbit.oak.spi.commit.Observable 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 2 with Observable

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

the class NodeStoreTest method afterCommitHook.

@Test
public void afterCommitHook() throws CommitFailedException, InterruptedException {
    assumeTrue(store instanceof Observable);
    final AtomicReference<NodeState> observedRoot = new AtomicReference<NodeState>(null);
    final CountDownLatch latch = new CountDownLatch(2);
    ((Observable) store).addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
            if (root.getChildNode("test").hasChildNode("newNode")) {
                observedRoot.set(checkNotNull(root));
                latch.countDown();
            }
        }
    });
    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, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // triggers the observer
    NodeState newRoot = store.getRoot();
    latch.await(2, TimeUnit.SECONDS);
    NodeState after = observedRoot.get();
    assertNotNull(after);
    assertTrue(after.getChildNode("test").getChildNode("newNode").exists());
    assertFalse(after.getChildNode("test").getChildNode("a").exists());
    assertEquals(42, (long) after.getChildNode("test").getChildNode("newNode").getProperty("n").getValue(LONG));
    assertEquals(newRoot, after);
}
Also used : Observer(org.apache.jackrabbit.oak.spi.commit.Observer) AtomicReference(java.util.concurrent.atomic.AtomicReference) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Observable(org.apache.jackrabbit.oak.spi.commit.Observable) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 3 with Observable

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

the class LuceneIndexTest method luceneWithFSDirectory.

@Test
public void luceneWithFSDirectory() throws Exception {
    //Issue is not reproducible with MemoryNodeBuilder and
    //MemoryNodeState as they cannot determine change in childNode without
    //entering
    NodeStore nodeStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    tracker = new IndexTracker();
    ((Observable) nodeStore).addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
            tracker.update(root);
        }
    });
    builder = nodeStore.getRoot().builder();
    //Also initialize the NodeType registry required for Lucene index to work
    builder.setChildNode(JCR_SYSTEM, INITIAL_CONTENT.getChildNode(JCR_SYSTEM));
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder idxb = newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo", "foo2"), null);
    idxb.setProperty(PERSISTENCE_NAME, PERSISTENCE_FILE);
    idxb.setProperty(PERSISTENCE_PATH, getIndexDir());
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    builder = nodeStore.getRoot().builder();
    builder.setProperty("foo", "bar");
    NodeState indexed = nodeStore.merge(builder, HOOK, CommitInfo.EMPTY);
    assertQuery(tracker, indexed, "foo", "bar");
    builder = nodeStore.getRoot().builder();
    builder.setProperty("foo2", "bar2");
    indexed = nodeStore.merge(builder, HOOK, CommitInfo.EMPTY);
    assertQuery(tracker, indexed, "foo2", "bar2");
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) 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) Observable(org.apache.jackrabbit.oak.spi.commit.Observable) Test(org.junit.Test)

Aggregations

CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)3 Observable (org.apache.jackrabbit.oak.spi.commit.Observable)3 Observer (org.apache.jackrabbit.oak.spi.commit.Observer)3 Test (org.junit.Test)3 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)1