You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/12/04 17:09:17 UTC

[groovy] branch master updated: Run `testRemovingEntriesFromMapAfterGC` with `assertScript`

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d0822781f Run `testRemovingEntriesFromMapAfterGC` with `assertScript`
2d0822781f is described below

commit 2d0822781f90e81f14e071d321d1691ff4bcc966
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Dec 5 01:08:59 2022 +0800

    Run `testRemovingEntriesFromMapAfterGC` with `assertScript`
---
 .../ManagedIdentityConcurrentMapTest.groovy        | 65 ++++++++++++----------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/src/test/org/apache/groovy/util/concurrent/ManagedIdentityConcurrentMapTest.groovy b/src/test/org/apache/groovy/util/concurrent/ManagedIdentityConcurrentMapTest.groovy
index ed486536f7..c0a6638b87 100644
--- a/src/test/org/apache/groovy/util/concurrent/ManagedIdentityConcurrentMapTest.groovy
+++ b/src/test/org/apache/groovy/util/concurrent/ManagedIdentityConcurrentMapTest.groovy
@@ -18,42 +18,47 @@
  */
 package org.apache.groovy.util.concurrent
 
-import org.apache.groovy.util.concurrent.ManagedIdentityConcurrentMap
 import org.junit.Test
 
+import static groovy.test.GroovyAssert.assertScript
+
 class ManagedIdentityConcurrentMapTest {
     @Test
     void testRemovingEntriesFromMapAfterGC() {
-        def m = new ManagedIdentityConcurrentMap<Object, String>()
-        def k1 = new Object()
-        m.put(k1, "a")
-        def k2 = new Object()
-        m.put(k2, "b")
-        def k3 = new Object()
-        m.put(k3, "c")
-
-        assert 3 == m.size()
-
-        // the related entries should be removed after GC happens
-        k1 = null
-        k2 = null
-        k3 = null
-
-        // finalize via GC, which is hard to predicate though it will happen at last
-        for (int i = 0; i < 20; i++) {
-            System.gc()
-
-            if (m.values().size() == 0) {
-                break
-            }
+        assertScript '''
+            import org.apache.groovy.util.concurrent.ManagedIdentityConcurrentMap
+
+            def m = new ManagedIdentityConcurrentMap<Object, String>()
+            def k1 = new Object()
+            m.put(k1, "a")
+            def k2 = new Object()
+            m.put(k2, "b")
+            def k3 = new Object()
+            m.put(k3, "c")
+
+            assert 3 == m.size()
 
-            Thread.sleep(100)
-        }
+            // the related entries should be removed after GC happens
+            k1 = null
+            k2 = null
+            k3 = null
+
+            // finalize via GC, which is hard to predicate though it will happen at last
+            for (int i = 0; i < 20; i++) {
+                System.gc()
+
+                if (m.values().size() == 0) {
+                    break
+                }
+
+                Thread.sleep(100)
+            }
 
-        def k4 = new Object()
-        assert "d" == m.getOrPut(k4, "d")
-        assert "d" == m.getOrPut(k4, "e")
-        assert [k4] == (m.keySet() as List)
-        assert ["d"] == (m.values() as List)
+            def k4 = new Object()
+            assert "d" == m.getOrPut(k4, "d")
+            assert "d" == m.getOrPut(k4, "e")
+            assert [k4] == (m.keySet() as List)
+            assert ["d"] == (m.values() as List)
+        '''
     }
 }