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