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