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:22:09 GMT
Repository: groovy
Updated Branches:
  refs/heads/master f40309942 -> 2046dd76b


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/2046dd76
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2046dd76
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2046dd76

Branch: refs/heads/master
Commit: 2046dd76bdbb7398d425e83a7d9b39a0a8707c9a
Parents: f403099
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:17:29 2016 -0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/2046dd76/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