groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject groovy git commit: Fix AbstractConcurrentMapSegmentTest intermittent failures
Date Fri, 08 Jan 2016 01:25:00 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 0cd72fb22 -> 52b539bdf


Fix AbstractConcurrentMapSegmentTest intermittent failures

The use of System.currentTimeMillis() to generate unique key names would cause intermittent
failures because separate calls to whenIAddElements could happen in the same millisecond (as
noted in javadoc many operating systems measure time in units of tens of milliseconds).  Because
the key was not unique it wouldn't be added to the segment table, the existing key would be
updated and rehashing would not occur as expected.


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 52b539bdf45eec7213e3bd34d16bc1d6b630dd51
Parents: 0cd72fb
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Thu Jan 7 17:17:29 2016 -0800
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Thu Jan 7 17:22:57 2016 -0800

----------------------------------------------------------------------
 .../groovy/util/AbstractConcurrentMapSegmentTest.groovy     | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/52b539bd/src/test/org/codehaus/groovy/util/AbstractConcurrentMapSegmentTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/util/AbstractConcurrentMapSegmentTest.groovy b/src/test/org/codehaus/groovy/util/AbstractConcurrentMapSegmentTest.groovy
index 18d239e..9b8c729 100644
--- a/src/test/org/codehaus/groovy/util/AbstractConcurrentMapSegmentTest.groovy
+++ b/src/test/org/codehaus/groovy/util/AbstractConcurrentMapSegmentTest.groovy
@@ -24,6 +24,11 @@ import org.junit.Test
 class AbstractConcurrentMapSegmentTest {
     private static final Integer INITIAL_SEGMENT_SIZE = 100
     private static final Integer SEGMENT_THRESHOLD = 0.75f * INITIAL_SEGMENT_SIZE
+
+    // Incrementing counter used to generate unique key names for TestEntry objects
+    // across all test methods in this class
+    private static int keyId
+
     TestSegment segment
     List<TestEntry> entries = []
     int rehashCount = 0
@@ -100,7 +105,7 @@ class AbstractConcurrentMapSegmentTest {
 
     private void whenIAddElements(int count) {
         count.times {
-            String key = "k:${System.currentTimeMillis()}-${it}"
+            String key = "k:${++keyId}-${it}"
             segment.put(key, key.hashCode(), "v${it}")
         }
     }
@@ -138,7 +143,7 @@ class AbstractConcurrentMapSegmentTest {
         }
 
         @Override
-        def void rehash() {
+        void rehash() {
             rehashCount++
             super.rehash()
         }


Mime
View raw message