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:29 UTC

[12/51] [abbrv] geronimo-yoko git commit: Force test to wait for system to enqueue references.

Force test to wait for system to enqueue references.


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

Branch: refs/heads/master
Commit: f8329001babf12af6e0dbc0a924adb3573b0c79b
Parents: 109fa48
Author: Neil Richards <ng...@linux.vnet.ibm.com>
Authored: Wed Nov 11 18:19:19 2015 +0000
Committer: Neil Richards <ng...@linux.vnet.ibm.com>
Committed: Wed Nov 11 18:19:19 2015 +0000

----------------------------------------------------------------------
 .../util/concurrent/WeakConcurrentFifoTest.java | 27 ++++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/f8329001/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 f81f477..5cce0f5 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
@@ -8,6 +8,7 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 
+import java.lang.ref.ReferenceQueue;
 import java.lang.ref.WeakReference;
 
 import static org.junit.Assert.assertEquals;
@@ -31,7 +32,7 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
     }
 
     @Test
-    public void testWeakRefsGetCollectedOnRemove() {
+    public void testWeakRefsGetCollectedOnRemove() throws Exception {
         WeakReference[] refs;
 
         refs = enqueueStringsCollectably("foo", "foo", "bar", "bar", "bar", "bar");
@@ -49,7 +50,7 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
     }
 
     @Test
-    public void testWeakRefsGetCollectedOnPut() {
+    public void testWeakRefsGetCollectedOnPut() throws Exception {
         WeakReference[] refs;
 
         refs = enqueueStringsCollectably("foo", "foo", "bar", "bar", "bar", "bar");
@@ -67,7 +68,7 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
     }
 
     @Test
-    public void testWeakRefsGetCollectedOnSize() {
+    public void testWeakRefsGetCollectedOnSize() throws Exception {
         WeakReference[] refs;
 
         refs = enqueueStringsCollectably("foo", "foo", "bar", "bar", "bar", "bar");
@@ -93,13 +94,23 @@ public class WeakConcurrentFifoTest extends ConcurrentFifoTest {
         return refs;
     }
 
-    public static void gcUntilCleared(WeakReference<?>... refs) {
+    public static void gcUntilCleared(WeakReference<?>... refs) throws Exception {
         for (WeakReference<?> ref : refs) {
-            while (ref.get() != null) {
-                System.out.print("gc ");
-                System.gc();
-            }
+            gcUntilCollected(ref);
             System.out.println();
         }
+        // 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) {
+        while (ref.get() != null) {
+            System.out.print("gc ");
+            System.gc();
+        }
     }
 }