jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1579912 - /jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
Date Fri, 21 Mar 2014 10:09:38 GMT
Author: reschke
Date: Fri Mar 21 10:09:38 2014
New Revision: 1579912

URL: http://svn.apache.org/r1579912
Log:
JCR-3743 - fix for systems on which currentTimeMillis doesn't have 1 ms resolution (patch
by Shashank Gupta)

Modified:
    jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java

Modified: jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java?rev=1579912&r1=1579911&r2=1579912&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
Fri Mar 21 10:09:38 2014
@@ -399,11 +399,14 @@ public abstract class TestCaseBase exten
         DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data));
         LOG.debug("rec2 timestamp=" + rec2.getLastModified());
 
-        Thread.sleep(2000);
+        // sleep for some time to ensure that async upload completes in backend.
+        sleep(6000);
         long updateTime = System.currentTimeMillis();
         LOG.debug("updateTime=" + updateTime);
         ds.updateModifiedDateOnAccess(updateTime);
 
+        // sleep to workaround System.currentTimeMillis granularity.
+        sleep(100);
         data = new byte[dataLength];
         random.nextBytes(data);
         DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data));
@@ -442,10 +445,13 @@ public abstract class TestCaseBase exten
         random.nextBytes(data);
         DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data));
 
-        Thread.sleep(2000);
+        // sleep for some time to ensure that async upload completes in backend.
+        sleep(6000);
         long updateTime = System.currentTimeMillis();
         ds.updateModifiedDateOnAccess(updateTime);
-
+        
+        // sleep to workaround System.currentTimeMillis granularity.
+        sleep(100);
         data = new byte[dataLength];
         random.nextBytes(data);
         DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data));
@@ -662,5 +668,21 @@ public abstract class TestCaseBase exten
             stream.close();
         }
     }
+    
+    /**
+     * Utility method to stop execution for duration time.
+     * 
+     * @param duration
+     *            time in milli seconds
+     */
+    protected void sleep(long duration) {
+        long expected = System.currentTimeMillis() + duration;
+        while (System.currentTimeMillis() < expected) {
+            try {
+                Thread.sleep(1);
+            } catch (InterruptedException ie) {
 
+            }
+        }
+    }
 }



Mime
View raw message