Repository: groovy
Updated Branches:
  refs/heads/master 7ed686f2f -> 0eb785509


Refine `ConcurrentLinkedHashMapTest`


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/0eb78550
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0eb78550
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0eb78550

Branch: refs/heads/master
Commit: 0eb78550969677add05ee98a03be3b40537007ca
Parents: 7ed686f
Author: sunlan <[email protected]>
Authored: Wed Jan 24 07:52:22 2018 +0800
Committer: sunlan <[email protected]>
Committed: Wed Jan 24 07:52:34 2018 +0800

----------------------------------------------------------------------
 .../ConcurrentLinkedHashMapTest.java            | 23 ++++++++------------
 1 file changed, 9 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/0eb78550/src/test/java/org/apache/groovy/util/concurrentlinkedhashmap/ConcurrentLinkedHashMapTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/groovy/util/concurrentlinkedhashmap/ConcurrentLinkedHashMapTest.java
 
b/src/test/java/org/apache/groovy/util/concurrentlinkedhashmap/ConcurrentLinkedHashMapTest.java
index f20372d..a961df4 100644
--- 
a/src/test/java/org/apache/groovy/util/concurrentlinkedhashmap/ConcurrentLinkedHashMapTest.java
+++ 
b/src/test/java/org/apache/groovy/util/concurrentlinkedhashmap/ConcurrentLinkedHashMapTest.java
@@ -25,6 +25,7 @@ import java.util.concurrent.CountDownLatch;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 public class ConcurrentLinkedHashMapTest {
     @Test
@@ -53,7 +54,7 @@ public class ConcurrentLinkedHashMapTest {
                 .maximumWeightedCapacity(3)
                 .build();
 
-        final int threadNum = 5;
+        final int threadNum = 20;
         final CountDownLatch countDownLatch = new CountDownLatch(1);
         final CountDownLatch countDownLatch2 = new CountDownLatch(threadNum);
 
@@ -63,18 +64,6 @@ public class ConcurrentLinkedHashMapTest {
                 try {
                     countDownLatch.await();
 
-                    if (num != 0 && num != 1 && num != 2) {
-                        Thread.sleep(300);
-                    }
-
-                    if (num == 1) {
-                        Thread.sleep(50);
-                    }
-
-                    if (num == 2) {
-                        Thread.sleep(150);
-                    }
-
                     m.computeIfAbsent(num % 3, k -> num);
                 } catch (InterruptedException e) {
                     e.printStackTrace();
@@ -87,7 +76,13 @@ public class ConcurrentLinkedHashMapTest {
         countDownLatch.countDown();
         countDownLatch2.await();
 
+        m.computeIfAbsent(0, k -> 16);
+
         assertArrayEquals(new Integer[] {0, 1, 2}, m.keySet().toArray(new 
Integer[0]));
-        assertArrayEquals(new Integer[] {0, 1, 2}, m.values().toArray(new 
Integer[0]));
+
+        assertNotEquals(16, m.get(0));
+        assertEquals(0, (Integer) m.get(0) % 3);
+        assertEquals(1, (Integer) m.get(1) % 3);
+        assertEquals(2, (Integer) m.get(2) % 3);
     }
 }
\ No newline at end of file

Reply via email to