You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2017/02/19 01:49:31 UTC

[14/51] [abbrv] geronimo-yoko git commit: Fix gc bug in test.

Fix gc bug in test.


Project: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/repo
Commit: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/commit/aef2d869
Tree: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/tree/aef2d869
Diff: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/diff/aef2d869

Branch: refs/heads/master
Commit: aef2d869807ff994219041d010a868ce6e83dfed
Parents: e4ca6e1
Author: Joe Chacko <ch...@uk.ibm.com>
Authored: Wed Nov 11 18:47:55 2015 +0000
Committer: Joe Chacko <ch...@uk.ibm.com>
Committed: Wed Nov 11 18:47:55 2015 +0000

----------------------------------------------------------------------
 .../yoko/util/concurrent/WeakConcurrentFifoTest.java  | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/aef2d869/yoko-util/src/test/java/org/apache/yoko/util/concurrent/WeakConcurrentFifoTest.java
----------------------------------------------------------------------
diff --git a/yoko-util/src/test/java/org/apache/yoko/util/concurrent/WeakConcurrentFifoTest.java b/yoko-util/src/test/java/org/apache/yoko/util/concurrent/WeakConcurrentFifoTest.java
index 5cce0f5..e7435e9 100644
--- a/yoko-util/src/test/java/org/apache/yoko/util/concurrent/WeakConcurrentFifoTest.java
+++ b/yoko-util/src/test/java/org/apache/yoko/util/concurrent/WeakConcurrentFifoTest.java
@@ -23,6 +23,7 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
     // must not use the @Mock annotation and Mockito's injection
     // because it intermittently fails to count invocations correctly
     private Runnable cleanup;
+    private ReferenceQueue<?> referenceQueue = new ReferenceQueue<>();
 
     @Before
     @Override
@@ -88,23 +89,17 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
         WeakReference[] refs = new WeakReference[strings.length];
         for (int i = 0 ; i < strings.length; i++) {
             String s = new String(strings[i]);
-            refs[i] = new WeakReference(s);
+            refs[i] = new WeakReference(s, referenceQueue);
             fifo.put(s);
         }
         return refs;
     }
 
-    public static void gcUntilCleared(WeakReference<?>... refs) throws Exception {
+    public void gcUntilCleared(WeakReference<?>... refs) throws Exception {
         for (WeakReference<?> ref : refs) {
             gcUntilCollected(ref);
-            System.out.println();
+            referenceQueue.remove();
         }
-        // now use a dummy object and a new ref queue to wait for enqueuing to happen
-        // (hopefully once the dummy ref is enqueued on the new ref q, the enqueueing inside the fifo has happened)
-        ReferenceQueue<String> q = new ReferenceQueue<String>();
-        WeakReference<String> r = new WeakReference<String>(new String("Hello"), q);
-        gcUntilCollected(r);
-        q.remove();
     }
 
     private static void gcUntilCollected(WeakReference<?> ref) {
@@ -112,5 +107,6 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
             System.out.print("gc ");
             System.gc();
         }
+        System.out.println();
     }
 }