Search in sources :

Example 11 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method applyTo.

@Test
public void applyTo() throws Exception {
    DiffCache cache = new MemoryDiffCache(new DocumentMK.Builder());
    List<String> paths = Lists.newArrayList();
    addRandomPaths(paths);
    StringSort sort = JournalEntry.newSorter();
    add(sort, paths);
    RevisionVector from = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector to = new RevisionVector(new Revision(2, 0, 1));
    sort.sort();
    JournalEntry.applyTo(sort, cache, "/", from, to);
    for (String p : paths) {
        String changes = cache.getChanges(from, to, p, null);
        assertNotNull("missing changes for " + p, changes);
        for (String c : getChildren(changes)) {
            assertTrue(paths.contains(PathUtils.concat(p, c)));
        }
    }
    sort.close();
}
Also used : StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) Test(org.junit.Test)

Example 12 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method fillExternalChangesWithPath.

@Test
public void fillExternalChangesWithPath() throws Exception {
    Revision r1 = new Revision(1, 0, 1);
    Revision r2 = new Revision(2, 0, 1);
    DocumentStore store = new MemoryDocumentStore();
    JournalEntry entry = JOURNAL.newDocument(store);
    entry.modified("/");
    entry.modified("/foo");
    entry.modified("/foo/a");
    entry.modified("/foo/b");
    entry.modified("/foo/c");
    entry.modified("/bar");
    entry.modified("/bar/a");
    entry.modified("/bar/b");
    entry.modified("/bar/c");
    UpdateOp op = entry.asUpdateOp(r2);
    assertTrue(store.create(JOURNAL, Collections.singletonList(op)));
    StringSort sort = JournalEntry.newSorter();
    StringSort inv = JournalEntry.newSorter();
    JournalEntry.fillExternalChanges(sort, inv, "/foo", r1, r2, store, null, null);
    assertEquals(4, sort.getSize());
    assertEquals(0, inv.getSize());
    sort.close();
    inv.close();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 13 with StringSort

use of org.apache.jackrabbit.oak.commons.sort.StringSort in project jackrabbit-oak by apache.

the class JournalEntryTest method fillExternalChanges2.

@Test
public void fillExternalChanges2() throws Exception {
    Revision r1 = new Revision(1, 0, 1);
    Revision r2 = new Revision(2, 0, 1);
    Revision r3 = new Revision(3, 0, 1);
    Revision r4 = new Revision(4, 0, 1);
    DocumentStore store = new MemoryDocumentStore();
    JournalEntry entry = JOURNAL.newDocument(store);
    entry.modified("/");
    entry.modified("/foo");
    UpdateOp op = entry.asUpdateOp(r2);
    assertTrue(store.create(JOURNAL, Collections.singletonList(op)));
    entry = JOURNAL.newDocument(store);
    entry.modified("/");
    entry.modified("/bar");
    op = entry.asUpdateOp(r4);
    assertTrue(store.create(JOURNAL, Collections.singletonList(op)));
    StringSort sort = externalChanges(r1, r1, store);
    assertEquals(0, sort.getSize());
    sort.close();
    sort = externalChanges(r1, r2, store);
    assertEquals(Sets.newHashSet("/", "/foo"), Sets.newHashSet(sort));
    sort.close();
    sort = externalChanges(r1, r3, store);
    assertEquals(Sets.newHashSet("/", "/foo", "/bar"), Sets.newHashSet(sort));
    sort.close();
    sort = externalChanges(r1, r4, store);
    assertEquals(Sets.newHashSet("/", "/foo", "/bar"), Sets.newHashSet(sort));
    sort.close();
    sort = externalChanges(r2, r2, store);
    assertEquals(0, sort.getSize());
    sort.close();
    sort = externalChanges(r2, r3, store);
    assertEquals(Sets.newHashSet("/", "/bar"), Sets.newHashSet(sort));
    sort.close();
    sort = externalChanges(r2, r4, store);
    assertEquals(Sets.newHashSet("/", "/bar"), Sets.newHashSet(sort));
    sort.close();
    sort = externalChanges(r3, r3, store);
    assertEquals(0, sort.getSize());
    sort.close();
    sort = externalChanges(r3, r4, store);
    assertEquals(Sets.newHashSet("/", "/bar"), Sets.newHashSet(sort));
    sort.close();
    sort = externalChanges(r4, r4, store);
    assertEquals(0, sort.getSize());
    sort.close();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) StringSort(org.apache.jackrabbit.oak.commons.sort.StringSort) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Aggregations

StringSort (org.apache.jackrabbit.oak.commons.sort.StringSort)13 Test (org.junit.Test)9 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)5 IOException (java.io.IOException)2 Map (java.util.Map)1 CacheStats (org.apache.jackrabbit.oak.cache.CacheStats)1 ChangeSetBuilder (org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1