use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class JournalDiffLoaderTest method useJournal.
// OAK-5228
@Test
public void useJournal() throws Exception {
final AtomicInteger journalQueryCounter = new AtomicInteger();
DocumentStore ds = new MemoryDocumentStore() {
@Nonnull
@Override
public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) {
if (collection == Collection.JOURNAL) {
journalQueryCounter.incrementAndGet();
}
return super.query(collection, fromKey, toKey, limit);
}
};
DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1).clock(clock).setLeaseCheck(false).setDocumentStore(ds).setAsyncDelay(0).getNodeStore();
DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2).clock(clock).setLeaseCheck(false).setDocumentStore(ds).setAsyncDelay(0).getNodeStore();
NodeBuilder b1 = ns1.getRoot().builder();
NodeBuilder foo = b1.child("foo");
for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD + 1; i++) {
foo.child("n" + i);
}
merge(ns1, b1);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
clock.waitUntil(clock.getTime() + TimeUnit.MINUTES.toMillis(10));
NodeBuilder b2 = ns2.getRoot().builder();
b2.child("foo").child("bar");
merge(ns2, b2);
ns2.runBackgroundOperations();
ns1.runBackgroundOperations();
// collect journal entry created for /foo/nX
ns1.getJournalGarbageCollector().gc(5, TimeUnit.MINUTES);
// the next modification updates the root revision
// for clusterId 1 past the removed journal entry
b1 = ns1.getRoot().builder();
b1.child("qux");
merge(ns1, b1);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
// remember before state
DocumentNodeState fooBefore = (DocumentNodeState) ns1.getRoot().getChildNode("foo");
b2 = ns2.getRoot().builder();
b2.child("foo").child("baz");
merge(ns2, b2);
ns2.runBackgroundOperations();
ns1.runBackgroundOperations();
b1 = ns1.getRoot().builder();
b1.child("foo").child("bar").remove();
merge(ns1, b1);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
DocumentNodeState fooAfter = (DocumentNodeState) ns1.getRoot().getChildNode("foo");
journalQueryCounter.set(0);
final Set<String> changes = Sets.newHashSet();
fooAfter.compareAgainstBaseState(fooBefore, new DefaultNodeStateDiff() {
@Override
public boolean childNodeChanged(String name, NodeState before, NodeState after) {
changes.add(name);
return true;
}
@Override
public boolean childNodeAdded(String name, NodeState after) {
changes.add(name);
return true;
}
@Override
public boolean childNodeDeleted(String name, NodeState before) {
changes.add(name);
return true;
}
});
assertThat(changes, containsInAnyOrder("bar", "baz"));
assertTrue("must use JournalDiffLoader", journalQueryCounter.get() > 0);
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class JournalDiffLoaderTest method fromExternalChange.
@Test
public void fromExternalChange() throws Exception {
DocumentStore store = new MemoryDocumentStore();
DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1).clock(clock).setDocumentStore(store).setAsyncDelay(0).getNodeStore();
DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2).clock(clock).setDocumentStore(store).setAsyncDelay(0).getNodeStore();
DocumentNodeState s1 = ns1.getRoot();
NodeBuilder builder = ns1.getRoot().builder();
builder.child("foo");
merge(ns1, builder);
builder = ns2.getRoot().builder();
builder.child("bar");
merge(ns2, builder);
ns2.runBackgroundOperations();
// create journal entry for ns1 and pick up changes from ns2
ns1.runBackgroundOperations();
builder = ns1.getRoot().builder();
builder.child("baz");
merge(ns1, builder);
DocumentNodeState s2 = ns1.getRoot();
assertEquals(newHashSet("foo", "bar", "baz"), changeChildNodes(ns1, s1, s2));
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class JournalEntryTest method invalidateOnly.
@Test
public void invalidateOnly() throws Exception {
DocumentStore store = new MemoryDocumentStore();
JournalEntry invalidateEntry = JOURNAL.newDocument(store);
Set<String> paths = Sets.newHashSet();
addRandomPaths(paths);
invalidateEntry.modified(paths);
Revision r1 = new Revision(1, 0, 1);
Revision r2 = new Revision(2, 0, 1);
Revision r3 = new Revision(3, 0, 1);
UpdateOp op = invalidateEntry.asUpdateOp(r1.asBranchRevision());
assertTrue(store.create(JOURNAL, singletonList(op)));
JournalEntry entry = JOURNAL.newDocument(store);
entry.invalidate(singleton(r1));
op = entry.asUpdateOp(r2);
assertTrue(store.create(JOURNAL, singletonList(op)));
StringSort sort = JournalEntry.newSorter();
StringSort inv = JournalEntry.newSorter();
JournalEntry.fillExternalChanges(sort, inv, r2, r3, store);
assertEquals(0, sort.getSize());
assertEquals(0, inv.getSize());
JournalEntry.fillExternalChanges(sort, inv, r1, r2, store);
assertEquals(1, sort.getSize());
assertEquals(paths.size(), inv.getSize());
inv.close();
sort.close();
sort = JournalEntry.newSorter();
inv = JournalEntry.newSorter();
JournalEntry.fillExternalChanges(sort, inv, r1, r3, store);
assertEquals(1, sort.getSize());
assertEquals(paths.size(), inv.getSize());
sort.close();
inv.close();
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method readWriteOldVersion.
@Test
public void readWriteOldVersion() throws Exception {
DocumentStore store = new MemoryDocumentStore();
FormatVersion.V1_0.writeTo(store);
try {
new DocumentMK.Builder().setDocumentStore(store).getNodeStore();
fail("must fail with " + DocumentStoreException.class.getSimpleName());
} catch (Exception e) {
// expected
}
}
use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.
the class DocumentNodeStoreTest method lastRevWithRevisionVector.
@Test
public void lastRevWithRevisionVector() throws Exception {
MemoryDocumentStore store = new MemoryDocumentStore();
DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1).setDocumentStore(store).setAsyncDelay(0).getNodeStore();
DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2).setDocumentStore(store).setAsyncDelay(0).getNodeStore();
NodeBuilder b1 = ns1.getRoot().builder();
b1.child("parent");
merge(ns1, b1);
b1 = ns1.getRoot().builder();
NodeBuilder parent = b1.child("parent");
parent.setProperty("p", 1);
parent.child("child");
merge(ns1, b1);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
NodeBuilder b2 = ns2.getRoot().builder();
b2.child("parent").setProperty("p", 2);
merge(ns2, b2);
ns2.runBackgroundOperations();
ns1.runBackgroundOperations();
assertTrue(ns1.getRoot().getChildNode("parent").hasChildNode("child"));
}
Aggregations