You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/10/26 15:53:56 UTC
[2/2] activemq-artemis git commit:
SessionCloseOnGCTest#testCloseOneSessionOnGC: enforce that Finalizer will be
called after garbage collector
SessionCloseOnGCTest#testCloseOneSessionOnGC: enforce that Finalizer will be called after garbage collector
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7970b6e6
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7970b6e6
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7970b6e6
Branch: refs/heads/master
Commit: 7970b6e6f8f6b41f35e3a3672b4603a0a7ab01b5
Parents: 487d976
Author: Erich Duda <ed...@redhat.com>
Authored: Fri Oct 16 12:15:34 2015 +0200
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Oct 26 10:53:48 2015 -0400
----------------------------------------------------------------------
.../artemis/tests/util/ActiveMQTestBase.java | 23 +++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7970b6e6/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
index 7cbe2f0..7e358a9 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
@@ -525,10 +525,12 @@ public abstract class ActiveMQTestBase extends Assert {
public static void forceGC() {
log.info("#test forceGC");
- WeakReference<Object> dumbReference = new WeakReference<Object>(new Object());
+ AtomicInteger finalized = new AtomicInteger(0);
+ WeakReference<DumbReference> dumbReference = new WeakReference<>(new DumbReference(finalized));
// A loop that will wait GC, using the minimal time as possible
- while (dumbReference.get() != null) {
+ while (!(dumbReference.get() == null && finalized.get() == 1)) {
System.gc();
+ System.runFinalization();
try {
Thread.sleep(100);
}
@@ -2535,4 +2537,19 @@ public abstract class ActiveMQTestBase extends Assert {
public static void waitForLatch(CountDownLatch latch) throws InterruptedException {
assertTrue("Latch has got to return within a minute", latch.await(1, TimeUnit.MINUTES));
}
-}
+
+ protected static class DumbReference {
+
+ private AtomicInteger finalized;
+
+ public DumbReference(AtomicInteger finalized) {
+ this.finalized = finalized;
+ }
+
+ public void finalize() throws Throwable {
+ System.out.println("FINALIZE");
+ finalized.incrementAndGet();
+ super.finalize();
+ }
+ }
+}
\ No newline at end of file