Search in sources :

Example 21 with UpdateOp

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

the class UtilsTest method alignWithExternalRevisions.

@Test
public void alignWithExternalRevisions() throws Exception {
    Clock c = new Clock.Virtual();
    c.waitUntil(System.currentTimeMillis());
    // past
    Revision lastRev1 = new Revision(c.getTime() - 1000, 0, 1);
    // future
    Revision lastRev2 = new Revision(c.getTime() + 1000, 0, 2);
    // create a root document
    NodeDocument doc = new NodeDocument(new MemoryDocumentStore(), c.getTime());
    UpdateOp op = new UpdateOp(Utils.getIdFromPath("/"), true);
    NodeDocument.setLastRev(op, lastRev1);
    NodeDocument.setLastRev(op, lastRev2);
    UpdateUtils.applyChanges(doc, op);
    // must not wait even if revision is in the future
    Utils.alignWithExternalRevisions(doc, c, 2);
    assertThat(c.getTime(), is(lessThan(lastRev2.getTimestamp())));
    // must wait until after lastRev2 timestamp
    Utils.alignWithExternalRevisions(doc, c, 1);
    assertThat(c.getTime(), is(greaterThan(lastRev2.getTimestamp())));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Aggregations

UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)21 ArrayList (java.util.ArrayList)12 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)8 Test (org.junit.Test)8 Stopwatch (com.google.common.base.Stopwatch)5 Connection (java.sql.Connection)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)4 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 HashSet (java.util.HashSet)3 CheckForNull (javax.annotation.CheckForNull)3 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)3 QueryCondition (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition)3 Function (com.google.common.base.Function)2 BasicDBObject (com.mongodb.BasicDBObject)2 BulkWriteOperation (com.mongodb.BulkWriteOperation)2 DBCollection (com.mongodb.DBCollection)2 DBObject (com.mongodb.DBObject)2