adding timeout verification

Some VMs (IBM) can eventually ignore the System.gc call.
Adding some mitigation when that happens here
This commit is contained in:
Clebert Suconic 2016-01-18 12:31:52 -05:00
parent c58209f03c
commit 17a443b1f0
1 changed files with 20 additions and 2 deletions

View File

@ -499,13 +499,22 @@ public abstract class ActiveMQTestBase extends Assert {
} }
} }
private static int failedGCCalls = 0;
public static void forceGC() { public static void forceGC() {
if (failedGCCalls >= 10) {
log.info("ignoring forceGC call since it seems System.gc is not working anyways");
return;
}
log.info("#test forceGC"); log.info("#test forceGC");
CountDownLatch finalized = new CountDownLatch(1); CountDownLatch finalized = new CountDownLatch(1);
WeakReference<DumbReference> dumbReference = new WeakReference<>(new DumbReference(finalized)); WeakReference<DumbReference> dumbReference = new WeakReference<>(new DumbReference(finalized));
long timeout = System.currentTimeMillis() + 1000;
// A loop that will wait GC, using the minimal time as possible // A loop that will wait GC, using the minimal time as possible
while (!(dumbReference.get() == null && finalized.getCount() == 0)) { while (!(dumbReference.get() == null && finalized.getCount() == 0) && System.currentTimeMillis() < timeout) {
System.gc(); System.gc();
System.runFinalization(); System.runFinalization();
try { try {
@ -514,7 +523,16 @@ public abstract class ActiveMQTestBase extends Assert {
catch (InterruptedException e) { catch (InterruptedException e) {
} }
} }
log.info("#test forceGC Done");
if (dumbReference.get() != null) {
failedGCCalls++;
log.info("It seems that GC is disabled at your VM");
}
else {
// a success would reset the count
failedGCCalls = 0;
}
log.info("#test forceGC Done ");
} }
public static void forceGC(final Reference<?> ref, final long timeout) { public static void forceGC(final Reference<?> ref, final long timeout) {