Search in sources :

Example 1 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class SecondaryStoreCacheTest method binarySearch.

@Test
public void binarySearch() throws Exception {
    SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
    List<AbstractDocumentNodeState> roots = Lists.newArrayList();
    List<RevisionVector> revs = Lists.newArrayList();
    for (int i = 0; i < 50; i++) {
        NodeBuilder nb = primary.getRoot().builder();
        create(nb, "/a/b" + i);
        AbstractDocumentNodeState r = merge(nb);
        roots.add(r);
        revs.add(r.getRootRevision());
    }
    AbstractDocumentNodeState[] rootsArr = Iterables.toArray(roots, AbstractDocumentNodeState.class);
    Collections.shuffle(revs);
    for (RevisionVector rev : revs) {
        AbstractDocumentNodeState result = SecondaryStoreCache.findMatchingRoot(rootsArr, rev);
        assertNotNull(result);
        assertEquals(rev, result.getRootRevision());
    }
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/m");
    AbstractDocumentNodeState r = merge(nb);
    AbstractDocumentNodeState result = SecondaryStoreCache.findMatchingRoot(rootsArr, r.getRootRevision());
    assertNull(result);
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class SecondaryStoreCacheTest method basicTest.

@Test
public void basicTest() throws Exception {
    SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty));
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/b", "/a/c", "/x/y/z");
    merge(nb);
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    assertNull(cache.getDocumentNodeState("/a/b", rv1, rv2));
    assertNull(cache.getDocumentNodeState("/x", rv1, rv2));
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method basicWorking.

@Test
public void basicWorking() throws Exception {
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    builder.setProperty(asPropertyState(PROP_REVISION, rv1));
    builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
    AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
    assertEquals(rv1, state.getRootRevision());
    assertEquals(rv2, state.getLastRevision());
    assertTrue(state.hasNoChildren());
    assertTrue(state.exists());
    assertFalse(state.isFromExternalChange());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Test(org.junit.Test)

Example 4 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method withRootRevision.

@Test
public void withRootRevision() throws Exception {
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    builder.setProperty(asPropertyState(PROP_REVISION, rv1));
    builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
    AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
    AbstractDocumentNodeState state2 = state.withRootRevision(rv1, false);
    assertSame(state, state2);
    RevisionVector rv4 = new RevisionVector(new Revision(1, 0, 4));
    AbstractDocumentNodeState state3 = state.withRootRevision(rv4, true);
    assertEquals(rv4, state3.getRootRevision());
    assertTrue(state3.isFromExternalChange());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Test(org.junit.Test)

Example 5 with RevisionVector

use of org.apache.jackrabbit.oak.plugins.document.RevisionVector in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method setMetaProps.

private static void setMetaProps(NodeBuilder nb) {
    nb.setProperty(asPropertyState(PROP_REVISION, new RevisionVector(new Revision(1, 0, 1))));
    nb.setProperty(asPropertyState(PROP_LAST_REV, new RevisionVector(new Revision(1, 0, 1))));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector)

Aggregations

RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)16 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)13 Test (org.junit.Test)8 File (java.io.File)3 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)3 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)3 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 ArrayList (java.util.ArrayList)2 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCollection (com.mongodb.DBCollection)1 DBObject (com.mongodb.DBObject)1 ReadPreference (com.mongodb.ReadPreference)1 FileOutputStream (java.io.FileOutputStream)1 HashSet (java.util.HashSet)1 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)1 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)1 DocumentReadPreference (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference)1 LocalChanges (org.apache.jackrabbit.oak.plugins.document.mongo.replica.LocalChanges)1