Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java (revision 1562394) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Revision.java (working copy) @@ -161,14 +161,15 @@ } /** - * Get the difference between two timestamps (a - b) in milliseconds. + * Get the timestamp difference between two revisions (r1 - r2) in + * milliseconds. * - * @param a the first timestamp - * @param b the second timestamp + * @param r1 the first revision + * @param r2 the second revision * @return the difference in milliseconds */ - public static long getTimestampDifference(long a, long b) { - return a - b; + public static long getTimestampDifference(Revision r1, Revision r2) { + return r1.getTimestamp() - r2.getTimestamp(); } public static Revision fromString(String rev) { Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java (revision 1562394) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/RevisionTest.java (working copy) @@ -44,15 +44,20 @@ @Test public void difference() throws InterruptedException { + long t0 = Revision.getCurrentTimestamp(); Revision r0 = Revision.newRevision(0); Revision r1 = Revision.newRevision(0); - long timestamp = Revision.getCurrentTimestamp(); - assertTrue(Revision.getTimestampDifference(r1.getTimestamp(), r0.getTimestamp()) < 10); - assertTrue(Revision.getTimestampDifference(timestamp, r0.getTimestamp()) < 10); - Thread.sleep(2); + long t1 = Revision.getCurrentTimestamp(); + // the difference must not be more than t1 - t0 + assertTrue(Revision.getTimestampDifference(r1, r0) <= (t1 - t0)); + // busy wait until we have a timestamp different from t1 + long t2; + do { + t2 = Revision.getCurrentTimestamp(); + } while (t1 == t2); + Revision r2 = Revision.newRevision(0); - assertTrue(Revision.getTimestampDifference(r2.getTimestamp(), r0.getTimestamp()) > 0); - assertTrue(Revision.getTimestampDifference(r2.getTimestamp(), r0.getTimestamp()) < 20); + assertTrue(Revision.getTimestampDifference(r2, r1) > 0); } @Test