commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [04/46] incubator-commonsrdf git commit: COMMONSRDF-8 use ConcurrentHashMap in test
Date Thu, 02 Jun 2016 16:31:41 GMT
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 <stain@apache.org>
Authored: Fri Apr 10 10:10:26 2015 +0100
Committer: Stian Soiland-Reyes <stain@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));
     }
 


Mime
View raw message