Author: bayard Date: Thu Oct 12 09:34:06 2006 New Revision: 463310 URL: http://svn.apache.org/viewvc?view=rev&rev=463310 Log: Fixing #IO-82, in JDK 1.6 the gc call does not seem to be giving us the garbage collection, so Stephen came up with this to force that to happen. Speed seems good in JDK 1.4->1.6 and happily this isn't an issue with the underlying source, just the test.
Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java?view=diff&rev=463310&r1=463309&r2=463310 ============================================================================== --- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java (original) +++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java Thu Oct 12 09:34:06 2006 @@ -79,9 +79,8 @@ r.close(); testFile = null; r = null; - while (FileCleaner.getTrackCount() != 0) { - System.gc(); - } + + waitUntilTrackCount(); assertEquals(0, FileCleaner.getTrackCount()); assertEquals(false, new File(path).exists()); @@ -98,10 +97,9 @@ assertEquals(1, FileCleaner.getTrackCount()); obj = null; - while (FileCleaner.getTrackCount() != 0) { - System.gc(); - } - + + waitUntilTrackCount(); + assertEquals(0, FileCleaner.getTrackCount()); assertEquals(true, testFile.exists()); // not deleted, as dir not empty assertEquals(true, testFile.getParentFile().exists()); // not deleted, as dir not empty @@ -118,9 +116,8 @@ assertEquals(1, FileCleaner.getTrackCount()); obj = null; - while (FileCleaner.getTrackCount() != 0) { - System.gc(); - } + + waitUntilTrackCount(); assertEquals(0, FileCleaner.getTrackCount()); assertEquals(true, testFile.exists()); // not deleted, as dir not empty @@ -138,9 +135,8 @@ assertEquals(1, FileCleaner.getTrackCount()); obj = null; - while (FileCleaner.getTrackCount() != 0) { - System.gc(); - } + + waitUntilTrackCount(); assertEquals(0, FileCleaner.getTrackCount()); assertEquals(false, testFile.exists()); @@ -174,4 +170,15 @@ } } + private void waitUntilTrackCount() { + while (FileCleaner.getTrackCount() != 0) { + int total = 0; + while (FileCleaner.getTrackCount() != 0) { + byte[] b = new byte[1024 * 1024]; + b[0] = (byte) System.currentTimeMillis(); + total = total + b[0]; + System.gc(); + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]