You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by wi...@apache.org on 2015/03/27 19:15:01 UTC

[03/50] [abbrv] incubator-commonsrdf git commit: Added countQuery()

Added countQuery()


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

Branch: refs/heads/master
Commit: 62a256320de93da6ce182be14c00b3504b805340
Parents: eedbd81
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Jan 26 03:10:57 2015 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Jan 26 03:10:57 2015 +0000

----------------------------------------------------------------------
 .../commonsrdf/simple/TestWritingGraph.java     | 35 +++++++++++++++-----
 1 file changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/62a25632/commons-rdf-simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/commons-rdf-simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java b/commons-rdf-simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
index 3e5a19f..34b8b40 100644
--- a/commons-rdf-simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
+++ b/commons-rdf-simple/src/test/java/com/github/commonsrdf/simple/TestWritingGraph.java
@@ -19,7 +19,7 @@ import java.nio.file.Path;
 import java.util.Optional;
 import java.util.stream.Stream;
 
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.github.commonsrdf.api.BlankNode;
@@ -27,23 +27,42 @@ import com.github.commonsrdf.api.IRI;
 
 public class TestWritingGraph {
 
+	/*
+	 * 200k triples should do - about 7 MB on disk. Override with
+	 * -Dtriples=20000000 to exercise your memory banks.
+	 */
+	private static final int TRIPLES = Integer.getInteger("triples", 200000);
+
 	/** Run tests with -Dkeepfiles=true to inspect /tmp files **/
 	private static boolean KEEP_FILES = Boolean.getBoolean("keepfiles");
 
-	private GraphImpl graph;
+	private static GraphImpl graph;
 
-	@Before
-	public void createGraph() throws Exception {
+	@BeforeClass
+	public static void createGraph() throws Exception {
 		graph = new GraphImpl();
 		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
 		IRI predicate = new IRIImpl("pred");
-		// 200k triples should do
-		for (int i = 0; i < 200000; i++) {
+		for (int i = 0; i < TRIPLES; i++) {
 			graph.add(subject, predicate, new LiteralImpl("Example " + i, "en"));
 		}
 	}
 
 	@Test
+	public void createGraphTiming() throws Exception {
+		createGraph();
+	}
+	
+	@Test
+	public void countQuery() {
+		BlankNode subject = new BlankNodeImpl(Optional.of(graph), "subj");
+		IRI predicate = new IRIImpl("pred");
+		long count = graph.getTriples(subject, predicate, null).unordered()
+				.parallel().count();
+		System.out.println("Counted - " + count);
+	}
+
+	@Test
 	public void writeGraphFromStream() throws Exception {
 		Path graphFile = Files.createTempFile("graph", ".nt");
 		if (KEEP_FILES) {
@@ -51,8 +70,8 @@ public class TestWritingGraph {
 		} else {
 			graphFile.toFile().deleteOnExit();
 		}
-
-		Stream<CharSequence> stream = graph.getTriples().unordered().parallel()
+		
+		Stream<CharSequence> stream = graph.getTriples().unordered()
 				.map(Object::toString);
 		Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
 	}