COMMONSRDF-8 use ConcurrentHashMap in test

..and .parallel().forEach()
not for speed, but because it triggered a bug


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/d4a9c95b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/d4a9c95b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/d4a9c95b

Branch: refs/heads/quad
Commit: d4a9c95bf0752ffe2de09132c5ae3c39c3809f83
Parents: e1203fd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Apr 10 10:10:26 2015 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sat Mar 12 18:28:17 2016 +0000

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/AbstractGraphTest.java   | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d4a9c95b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git 
a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java 
b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index d6a5f9d..a301654 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -29,6 +29,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.junit.Assume;
 import org.junit.Before;
@@ -294,10 +295,11 @@ public abstract class AbstractGraphTest {
 
             IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name";);
 
-            final Map<String, BlankNodeOrIRI> whoIsWho = new HashMap<>();
-            System.out.println(g3.getTriples(null, name, null).count());
-            // NOTE: sequential as our HashMap is not thread-safe
-            g3.getTriples(null, name, null).sequential().forEach( t ->
+            final Map<String, BlankNodeOrIRI> whoIsWho = new 
ConcurrentHashMap<>();
+            // ConcurrentHashMap as we will try parallel forEach below,
+            // which should not give inconsistent results (it does with a 
+            // HashMap!)
+            g3.getTriples(null, name, null).parallel().forEach( t ->
                 whoIsWho.put( t.getObject().ntriplesString(), t.getSubject()));
             assertEquals(4, whoIsWho.size());
             // and contains 4 unique values
@@ -357,7 +359,7 @@ public abstract class AbstractGraphTest {
     protected static void copyTriples(Graph source, Graph target) {
 
         // unordered() as we don't need to preserve triple order
-        // sequential() as we don't require target Graph to be thread-safe
+        // sequential() as we don't (currently) require target Graph to be 
thread-safe
         source.getTriples().unordered().sequential().forEach(t -> 
target.add(t));
     }
 

Reply via email to