]> source.dussan.org Git - jgit.git/commitdiff
add fsTick() to RepositoryTestCase 31/1231/2
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 3 Aug 2010 20:27:41 +0000 (22:27 +0200)
committerStefan Lay <stefan.lay@sap.com>
Wed, 4 Aug 2010 11:36:27 +0000 (13:36 +0200)
An utility method which was in RacyGitTests has been moved to
RepositoryTestCase. Also the javadoc has been improved.
This method allows to wait long enough until the
filesystem-timer has advanced. This is useful when it has to
be guaranteed that two files modifications have different
modification timestamps.

Change-Id: I2ebd7cd7818feba6acffb3f835101d8fd281bd5a
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

index c29f1a0d72d687e1841ddb3fdcf8fb9d43268c64..e208b27e6bcb2ff53a06194857b6bfc1d81300f1 100644 (file)
@@ -160,38 +160,6 @@ public class RacyGitTests extends RepositoryTestCase {
                                indexState(SMUDGE|MOD_TIME|LENGTH));
        }
 
-       /**
-        * Waits until it is guaranteed that the filesystem timer (used e.g. for
-        * lastModified) has a value greater than the lastmodified time of the given
-        * file. This is done by touch a file, reading the lastmodified and sleeping
-        * attribute sleeping
-        *
-        * @param lastFile
-        * @return return the last measured value of the filesystem timer which is
-        *         greater than then the lastmodification time of lastfile.
-        * @throws InterruptedException
-        * @throws IOException
-        */
-       public static long fsTick(File lastFile) throws InterruptedException,
-                       IOException {
-               long sleepTime = 1;
-               File tmp = File.createTempFile("FileTreeIteratorWithTimeControl", null);
-               try {
-                       long startTime = (lastFile == null) ? tmp.lastModified() : lastFile
-                                       .lastModified();
-                       long actTime = tmp.lastModified();
-                       while (actTime <= startTime) {
-                               Thread.sleep(sleepTime);
-                               sleepTime *= 5;
-                               tmp.setLastModified(System.currentTimeMillis());
-                               actTime = tmp.lastModified();
-                       }
-                       return actTime;
-               } finally {
-                       tmp.delete();
-               }
-       }
-
        private void addToIndex(TreeSet<Long> modTimes)
                        throws FileNotFoundException, IOException {
                DirCacheBuilder builder = db.lockDirCache().builder();
index cb1f385560589483b2ac279b6f965a70eb358d26..36b28ae0779ceb6f305d51076b899a0ea0de8fce 100644 (file)
@@ -232,4 +232,40 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
                }
                return name;
        }
+
+       /**
+        * Waits until it is guaranteed that a subsequent file modification has a
+        * younger modification timestamp than the modification timestamp of the
+        * given file. This is done by touching a temporary file, reading the
+        * lastmodified attribute and, if needed, sleeping. After sleeping this loop
+        * starts again until the filesystem timer has advanced enough.
+        *
+        * @param lastFile
+        *            the file on which we want to wait until the filesystem timer
+        *            has advanced more than the lastmodification timestamp of this
+        *            file
+        * @return return the last measured value of the filesystem timer which is
+        *         greater than then the lastmodification time of lastfile.
+        * @throws InterruptedException
+        * @throws IOException
+        */
+       public static long fsTick(File lastFile) throws InterruptedException,
+                       IOException {
+               long sleepTime = 1;
+               File tmp = File.createTempFile("FileTreeIteratorWithTimeControl", null);
+               try {
+                       long startTime = (lastFile == null) ? tmp.lastModified() : lastFile
+                                       .lastModified();
+                       long actTime = tmp.lastModified();
+                       while (actTime <= startTime) {
+                               Thread.sleep(sleepTime);
+                               sleepTime *= 5;
+                               tmp.setLastModified(System.currentTimeMillis());
+                               actTime = tmp.lastModified();
+                       }
+                       return actTime;
+               } finally {
+                       tmp.delete();
+               }
+       }
 }