Author: niallp
Date: Wed Dec 3 16:02:54 2008
New Revision: 723153
URL: http://svn.apache.org/viewvc?rev=723153&view=rev
Log:
Fix IO-161 FileCleaningTrackerTestCase hangs - reported by Sebastiano Vigna
(copied code to try to force garbage collection from BeanUtils
MemoryLeakTestCase)
Modified:
commons/proper/io/trunk/pom.xml
commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
Modified: commons/proper/io/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/pom.xml?rev=723153&r1=723152&r2=723153&view=diff
==============================================================================
--- commons/proper/io/trunk/pom.xml (original)
+++ commons/proper/io/trunk/pom.xml Wed Dec 3 16:02:54 2008
@@ -224,6 +224,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <forkMode>pertest</forkMode>
+ <!-- limit memory size see IO-161 -->
+ <argLine>-Xmx25M</argLine>
<includes>
<include>**/*Test*</include>
</includes>
Modified:
commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java?rev=723153&r1=723152&r2=723153&view=diff
==============================================================================
---
commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
(original)
+++
commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
Wed Dec 3 16:02:54 2008
@@ -20,6 +20,8 @@
import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -288,15 +290,25 @@
}
//-----------------------------------------------------------------------
- private void waitUntilTrackCount() {
- while (theInstance.getTrackCount() != 0) {
- int total = 0;
- while (theInstance.getTrackCount() != 0) {
- byte[] b = new byte[1024 * 1024];
- b[0] = (byte) System.currentTimeMillis();
- total = total + b[0];
- System.gc();
+ private void waitUntilTrackCount() throws Exception {
+ int count = 0;
+ while(theInstance.getTrackCount() != 0 && count++ < 5) {
+ List<String> list = new ArrayList<String>();
+ try {
+ long i = 0;
+ while (true && theInstance.getTrackCount() != 0) {
+ list.add("A Big String A Big String A Big String A Big
String A Big String A Big String A Big String A Big String A Big String A Big
String " + (i++));
+ }
+ } catch (Throwable ignored) {
}
+ list.clear();
+ list = null;
+ System.gc();
+ Thread.sleep(1000);
}
+ if (theInstance.getTrackCount() != 0) {
+ throw new IllegalStateException("Your JVM is not releasing
SoftReference, try running the testcase with less memory (-Xmx)");
+ }
+
}
}