Skip to content

Commit 8847edc

Browse files
committed
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 :)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@433162 13f79535-47bb-0310-9956-ffa450edef68
1 parent 69a1e7e commit 8847edc

2 files changed

Lines changed: 45 additions & 27 deletions

File tree

src/test/org/apache/commons/io/FileUtilsTestCase.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,27 @@ public void testIsFileNewerOlder() throws Exception {
363363

364364
// Create Files
365365
createFile(oldFile, 0);
366-
spin(oldFile.lastModified());
367-
long now = System.currentTimeMillis();
366+
367+
do {
368+
try {
369+
Thread.sleep(1000);
370+
} catch(InterruptedException ie) {
371+
// ignore
372+
}
373+
createFile(reference, 0);
374+
} while( oldFile.lastModified() == reference.lastModified() );
375+
368376
Date date = new Date();
369-
createFile(reference, 0);
370-
spin(reference.lastModified());
371-
createFile(newFile, 0);
377+
long now = date.getTime();
378+
379+
do {
380+
try {
381+
Thread.sleep(1000);
382+
} catch(InterruptedException ie) {
383+
// ignore
384+
}
385+
createFile(newFile, 0);
386+
} while( reference.lastModified() == newFile.lastModified() );
372387

373388
// Test isFileNewer()
374389
assertFalse("Old File - Newer - File", FileUtils.isFileNewer(oldFile, reference));
@@ -930,11 +945,4 @@ public void testWriteLines_3arg_nullSeparator() throws Exception {
930945
assertEquals(expected, actual);
931946
}
932947

933-
private void spin(long now) throws InterruptedException {
934-
final long end = now + 1000;
935-
while (System.currentTimeMillis() <= end) {
936-
Thread.sleep(Math.max(1, end - System.currentTimeMillis()));
937-
}
938-
}
939-
940948
}

src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -581,24 +581,41 @@ public void testMakeSVNAware() throws Exception {
581581

582582
public void testAgeFilter() throws Exception {
583583
File oldFile = new File(getTestDirectory(), "old.txt");
584+
File reference = new File(getTestDirectory(), "reference.txt");
585+
File newFile = new File(getTestDirectory(), "new.txt");
586+
584587
createFile(oldFile, 0);
585-
spin(oldFile.lastModified());
586-
long now = System.currentTimeMillis();
588+
589+
do {
590+
try {
591+
Thread.sleep(1000);
592+
} catch(InterruptedException ie) {
593+
// ignore
594+
}
595+
createFile(reference, 0);
596+
} while( oldFile.lastModified() == reference.lastModified() );
597+
598+
Date date = new Date();
599+
long now = date.getTime();
600+
601+
do {
602+
try {
603+
Thread.sleep(1000);
604+
} catch(InterruptedException ie) {
605+
// ignore
606+
}
607+
createFile(newFile, 0);
608+
} while( reference.lastModified() == newFile.lastModified() );
609+
587610
IOFileFilter filter1 = FileFilterUtils.ageFileFilter(now);
588611
IOFileFilter filter2 = FileFilterUtils.ageFileFilter(now, true);
589612
IOFileFilter filter3 = FileFilterUtils.ageFileFilter(now, false);
590-
Date date = new Date();
591613
IOFileFilter filter4 = FileFilterUtils.ageFileFilter(date);
592614
IOFileFilter filter5 = FileFilterUtils.ageFileFilter(date, true);
593615
IOFileFilter filter6 = FileFilterUtils.ageFileFilter(date, false);
594-
File reference = new File(getTestDirectory(), "reference.txt");
595-
createFile(reference, 0);
596616
IOFileFilter filter7 = FileFilterUtils.ageFileFilter(reference);
597617
IOFileFilter filter8 = FileFilterUtils.ageFileFilter(reference, true);
598618
IOFileFilter filter9 = FileFilterUtils.ageFileFilter(reference, false);
599-
spin(reference.lastModified());
600-
File newFile = new File(getTestDirectory(), "new.txt");
601-
createFile(newFile, 0);
602619

603620
assertFiltering(filter1, oldFile, true);
604621
assertFiltering(filter2, oldFile, true);
@@ -718,12 +735,5 @@ public void testEmpty() throws Exception {
718735
FileUtils.forceDelete(emptyDir);
719736
}
720737

721-
private void spin(long now) throws InterruptedException {
722-
final long end = now + 1000;
723-
while (System.currentTimeMillis() <= end) {
724-
Thread.sleep(Math.max(1, end - System.currentTimeMillis()));
725-
}
726-
}
727-
728738
}
729739

0 commit comments

Comments
 (0)