|
From: <tho...@us...> - 2014-07-19 14:34:15
|
Revision: 8581
http://sourceforge.net/p/bigdata/code/8581
Author: thompsonbry
Date: 2014-07-19 14:34:10 +0000 (Sat, 19 Jul 2014)
Log Message:
-----------
Added a copy of the tests for forward, reverse, and undirected traversal to the bigdata specific GASEngine test suite (they were already present in the openrdf version of the test suite). The tests all pass.
Modified Paths:
--------------
branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestBFS.java
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestBFS.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestBFS.java 2014-07-19 00:10:57 UTC (rev 8580)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestBFS.java 2014-07-19 14:34:10 UTC (rev 8581)
@@ -23,10 +23,13 @@
*/
package com.bigdata.rdf.graph.impl.bd;
+import org.openrdf.sail.SailConnection;
+
import com.bigdata.rdf.graph.IGASContext;
import com.bigdata.rdf.graph.IGASEngine;
import com.bigdata.rdf.graph.IGASState;
import com.bigdata.rdf.graph.IGraphAccessor;
+import com.bigdata.rdf.graph.TraversalDirectionEnum;
import com.bigdata.rdf.graph.analytics.BFS;
/**
@@ -93,4 +96,230 @@
}
+ /**
+ * Variant test in which we choose a vertex (<code>foaf:person</code>) in
+ * the middle of the graph and insist on forward directed edges. Since the
+ * edges point from the person to the <code>foaf:person</code> vertex, this
+ * BSF traversal does not discover any connected vertices.
+ */
+ public void testBFS_directed_forward() throws Exception {
+
+ final SmallGraphProblem p = setupSmallGraphProblem();
+
+ final IGASEngine gasEngine = getGraphFixture()
+ .newGASEngine(1/* nthreads */);
+
+ try {
+
+ final SailConnection cxn = getGraphFixture().getSail()
+ .getConnection();
+
+ try {
+
+ final IGraphAccessor graphAccessor = getGraphFixture()
+ .newGraphAccessor(cxn);
+
+ final IGASContext<BFS.VS, BFS.ES, Void> gasContext = gasEngine
+ .newGASContext(graphAccessor, new BFS());
+
+ final IGASState<BFS.VS, BFS.ES, Void> gasState = gasContext
+ .getGASState();
+
+ // Initialize the froniter.
+ gasState.setFrontier(gasContext, p.getFoafPerson());
+
+ // directed traversal.
+ gasContext
+ .setTraversalDirection(TraversalDirectionEnum.Forward);
+
+ // Converge.
+ gasContext.call();
+
+ // starting vertex at (0,null).
+ assertEquals(0, gasState.getState(p.getFoafPerson()).depth());
+ assertEquals(null, gasState.getState(p.getFoafPerson())
+ .predecessor());
+
+ // no other vertices are visited.
+ assertEquals(-1, gasState.getState(p.getMike()).depth());
+ assertEquals(null, gasState.getState(p.getMike()).predecessor());
+
+ assertEquals(-1, gasState.getState(p.getBryan()).depth());
+ assertEquals(null, gasState.getState(p.getBryan())
+ .predecessor());
+
+ assertEquals(-1, gasState.getState(p.getMartyn()).depth());
+ assertEquals(null, gasState.getState(p.getMartyn())
+ .predecessor());
+
+ } finally {
+
+ try {
+ cxn.rollback();
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ } finally {
+
+ gasEngine.shutdownNow();
+
+ }
+
+ }
+
+ /**
+ * Variant test in which we choose a vertex (<code>foaf:person</code>) in
+ * the middle of the graph and insist on reverse directed edges. Since the
+ * edges point from the person to the <code>foaf:person</code> vertex,
+ * forward BSF traversal does not discover any connected vertices. However,
+ * since the traversal direction is reversed, the vertices are all one hop
+ * away.
+ */
+ public void testBFS_directed_reverse() throws Exception {
+
+ final SmallGraphProblem p = setupSmallGraphProblem();
+
+ final IGASEngine gasEngine = getGraphFixture()
+ .newGASEngine(1/* nthreads */);
+
+ try {
+
+ final SailConnection cxn = getGraphFixture().getSail()
+ .getConnection();
+
+ try {
+
+ final IGraphAccessor graphAccessor = getGraphFixture()
+ .newGraphAccessor(cxn);
+
+ final IGASContext<BFS.VS, BFS.ES, Void> gasContext = gasEngine
+ .newGASContext(graphAccessor, new BFS());
+
+ final IGASState<BFS.VS, BFS.ES, Void> gasState = gasContext
+ .getGASState();
+
+ // Initialize the froniter.
+ gasState.setFrontier(gasContext, p.getFoafPerson());
+
+ // directed traversal.
+ gasContext
+ .setTraversalDirection(TraversalDirectionEnum.Reverse);
+
+ // Converge.
+ gasContext.call();
+
+ // starting vertex at (0,null).
+ assertEquals(0, gasState.getState(p.getFoafPerson()).depth());
+ assertEquals(null, gasState.getState(p.getFoafPerson())
+ .predecessor());
+
+ // All other vertices are 1-hop.
+ assertEquals(1, gasState.getState(p.getMike()).depth());
+ assertEquals(p.getFoafPerson(), gasState.getState(p.getMike())
+ .predecessor());
+
+ assertEquals(1, gasState.getState(p.getBryan()).depth());
+ assertEquals(p.getFoafPerson(), gasState.getState(p.getBryan())
+ .predecessor());
+
+ assertEquals(1, gasState.getState(p.getMartyn()).depth());
+ assertEquals(p.getFoafPerson(), gasState
+ .getState(p.getMartyn()).predecessor());
+
+ } finally {
+
+ try {
+ cxn.rollback();
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ } finally {
+
+ gasEngine.shutdownNow();
+
+ }
+
+ }
+
+ /**
+ * Variant test in which we choose a vertex (<code>foaf:person</code>) in
+ * the middle of the graph and insist on directed edges. Since the edges
+ * point from the person to the <code>foaf:person</code> vertex, this BSF
+ * traversal does not discover any connected vertices.
+ */
+ public void testBFS_undirected() throws Exception {
+
+ final SmallGraphProblem p = setupSmallGraphProblem();
+
+ final IGASEngine gasEngine = getGraphFixture()
+ .newGASEngine(1/* nthreads */);
+
+ try {
+
+ final SailConnection cxn = getGraphFixture().getSail()
+ .getConnection();
+
+ try {
+
+ final IGraphAccessor graphAccessor = getGraphFixture()
+ .newGraphAccessor(cxn);
+
+ final IGASContext<BFS.VS, BFS.ES, Void> gasContext = gasEngine
+ .newGASContext(graphAccessor, new BFS());
+
+ final IGASState<BFS.VS, BFS.ES, Void> gasState = gasContext
+ .getGASState();
+
+ // Initialize the froniter.
+ gasState.setFrontier(gasContext, p.getFoafPerson());
+
+ // undirected traversal.
+ gasContext
+ .setTraversalDirection(TraversalDirectionEnum.Undirected);
+
+ // Converge.
+ gasContext.call();
+
+ // starting vertex at (0,null).
+ assertEquals(0, gasState.getState(p.getFoafPerson()).depth());
+ assertEquals(null, gasState.getState(p.getFoafPerson())
+ .predecessor());
+
+ // All other vertices are 1-hop.
+ assertEquals(1, gasState.getState(p.getMike()).depth());
+ assertEquals(p.getFoafPerson(), gasState.getState(p.getMike())
+ .predecessor());
+
+ assertEquals(1, gasState.getState(p.getBryan()).depth());
+ assertEquals(p.getFoafPerson(), gasState.getState(p.getBryan())
+ .predecessor());
+
+ assertEquals(1, gasState.getState(p.getMartyn()).depth());
+ assertEquals(p.getFoafPerson(), gasState
+ .getState(p.getMartyn()).predecessor());
+
+ } finally {
+
+ try {
+ cxn.rollback();
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ } finally {
+
+ gasEngine.shutdownNow();
+
+ }
+
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|