activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/2] activemq-artemis git commit: SessionCloseOnGCTest#testCloseOneSessionOnGC: enforce that Finalizer will be called after garbage collector
Date Mon, 26 Oct 2015 14:53:56 GMT
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 <eduda@redhat.com>
Authored: Fri Oct 16 12:15:34 2015 +0200
Committer: Clebert Suconic <clebertsuconic@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


Mime
View raw message