commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r433162 - in /jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io: FileUtilsTestCase.java filefilter/FileFilterTestCase.java
Date Mon, 21 Aug 2006 06:04:37 GMT
Author: bayard
Date: Sun Aug 20 23:04:36 2006
New Revision: 433162

URL: http://svn.apache.org/viewvc?rev=433162&view=rev
Log:
Fixing the failed tests on the vmbuild machine. Rather than trying to pause for a second and
hoping that means the file's will have different timestamps - the new code just sits and creates
the new file repeatedly until it has a different timestamp. A pause of a second means that
repeatedly should usually be a very small number of times - such as one. Also changed the
code so the long millisecond variable is the date's getTime method and not a different time
all together. The previous one irritated my sense of aesthetics :)

Modified:
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java?rev=433162&r1=433161&r2=433162&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
Sun Aug 20 23:04:36 2006
@@ -363,12 +363,27 @@
 
         // Create Files
         createFile(oldFile, 0);
-        spin(oldFile.lastModified());
-        long now = System.currentTimeMillis();
+
+        do {
+            try {
+                Thread.sleep(1000);
+            } catch(InterruptedException ie) {
+                // ignore
+            }
+            createFile(reference, 0);
+        } while( oldFile.lastModified() == reference.lastModified() );
+
         Date date = new Date();
-        createFile(reference, 0);
-        spin(reference.lastModified());
-        createFile(newFile, 0);
+        long now = date.getTime();
+
+        do {
+            try {
+                Thread.sleep(1000);
+            } catch(InterruptedException ie) {
+                // ignore
+            }
+            createFile(newFile, 0);
+        } while( reference.lastModified() == newFile.lastModified() );
 
         // Test isFileNewer()
         assertFalse("Old File - Newer - File", FileUtils.isFileNewer(oldFile, reference));
@@ -928,13 +943,6 @@
             IOUtils.LINE_SEPARATOR + "some text" + IOUtils.LINE_SEPARATOR;
         String actual = FileUtils.readFileToString(file, "US-ASCII");
         assertEquals(expected, actual);
-    }
-
-    private void spin(long now) throws InterruptedException {
-        final long end = now + 1000;
-        while (System.currentTimeMillis() <= end) {
-            Thread.sleep(Math.max(1, end - System.currentTimeMillis()));
-        }
     }
 
 }

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java?rev=433162&r1=433161&r2=433162&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Sun Aug 20 23:04:36 2006
@@ -581,24 +581,41 @@
 
     public void testAgeFilter() throws Exception {
         File oldFile = new File(getTestDirectory(), "old.txt");
+        File reference = new File(getTestDirectory(), "reference.txt");
+        File newFile = new File(getTestDirectory(), "new.txt");
+
         createFile(oldFile, 0);
-        spin(oldFile.lastModified());
-        long now = System.currentTimeMillis();
+
+        do {
+            try { 
+                Thread.sleep(1000);
+            } catch(InterruptedException ie) {
+                // ignore
+            }
+            createFile(reference, 0);
+        } while( oldFile.lastModified() == reference.lastModified() );
+
+        Date date = new Date();
+        long now = date.getTime();
+
+        do {
+            try { 
+                Thread.sleep(1000);
+            } catch(InterruptedException ie) {
+                // ignore
+            }
+            createFile(newFile, 0);
+        } while( reference.lastModified() == newFile.lastModified() );
+
         IOFileFilter filter1 = FileFilterUtils.ageFileFilter(now);
         IOFileFilter filter2 = FileFilterUtils.ageFileFilter(now, true);
         IOFileFilter filter3 = FileFilterUtils.ageFileFilter(now, false);
-        Date date = new Date();
         IOFileFilter filter4 = FileFilterUtils.ageFileFilter(date);
         IOFileFilter filter5 = FileFilterUtils.ageFileFilter(date, true);
         IOFileFilter filter6 = FileFilterUtils.ageFileFilter(date, false);
-        File reference = new File(getTestDirectory(), "reference.txt");
-        createFile(reference, 0);
         IOFileFilter filter7 = FileFilterUtils.ageFileFilter(reference);
         IOFileFilter filter8 = FileFilterUtils.ageFileFilter(reference, true);
         IOFileFilter filter9 = FileFilterUtils.ageFileFilter(reference, false);
-        spin(reference.lastModified());
-        File newFile = new File(getTestDirectory(), "new.txt");
-        createFile(newFile, 0);
 
         assertFiltering(filter1, oldFile, true);
         assertFiltering(filter2, oldFile, true);
@@ -716,13 +733,6 @@
         assertFiltering(EmptyFileFilter.EMPTY, notEmptyFile, false);
         assertFiltering(EmptyFileFilter.NOT_EMPTY, notEmptyFile, true);
         FileUtils.forceDelete(emptyDir);
-    }
-
-    private void spin(long now) throws InterruptedException {
-        final long end = now + 1000;
-        while (System.currentTimeMillis() <= end) {
-            Thread.sleep(Math.max(1, end - System.currentTimeMillis()));
-        }
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message