You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/10/13 01:04:37 UTC
[2/2] incubator-tinkerpop git commit: extended BLVP test suite
extended BLVP test suite
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/808fc5c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/808fc5c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/808fc5c2
Branch: refs/heads/TINKERPOP3-319
Commit: 808fc5c215fd7c9756f2ef7ad9d6ff918ad42532
Parents: 3c3abec
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Tue Oct 13 00:47:30 2015 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Oct 13 00:47:30 2015 +0200
----------------------------------------------------------------------
.../bulkloading/BulkLoaderVertexProgram.java | 10 +++-
.../BulkLoaderVertexProgramTest.java | 58 ++++++++++++++++----
2 files changed, 56 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/808fc5c2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
index 7e1e677..99bb1f5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgram.java
@@ -381,8 +381,14 @@ public class BulkLoaderVertexProgram implements VertexProgram<Tuple> {
* A configuration for the target graph that can be passed to GraphFactory.open().
*/
public Builder writeGraph(final String configurationFile) throws ConfigurationException {
- final Configuration conf = new PropertiesConfiguration(configurationFile);
- conf.getKeys().forEachRemaining(key -> setGraphConfigurationProperty(key, conf.getProperty(key)));
+ return writeGraph(new PropertiesConfiguration(configurationFile));
+ }
+
+ /**
+ * A configuration for the target graph that can be passed to GraphFactory.open().
+ */
+ public Builder writeGraph(final Configuration configuration) {
+ configuration.getKeys().forEachRemaining(key -> setGraphConfigurationProperty(key, configuration.getProperty(key)));
return this;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/808fc5c2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgramTest.java
index 9905da9..3a85671 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgramTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/bulkloading/BulkLoaderVertexProgramTest.java
@@ -24,11 +24,15 @@ import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.junit.After;
import org.junit.Test;
+import java.io.File;
import java.lang.reflect.Field;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -37,16 +41,30 @@ import static org.junit.Assert.assertTrue;
*/
public class BulkLoaderVertexProgramTest extends AbstractGremlinProcessTest {
+ final static String TINKERGRAPH_LOCATION = "/tmp/tinkertest.kryo";
+
private BulkLoader getBulkLoader(final BulkLoaderVertexProgram blvp) throws Exception {
final Field field = BulkLoaderVertexProgram.class.getDeclaredField("bulkLoader");
field.setAccessible(true);
return (BulkLoader) field.get(blvp);
}
- private Graph getTargetGraph() {
+ private Configuration getWriteGraphConfiguration() {
final Configuration configuration = new BaseConfiguration();
configuration.setProperty(Graph.GRAPH, "org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph");
- return GraphFactory.open(configuration);
+ configuration.setProperty("gremlin.tinkergraph.graphLocation", TINKERGRAPH_LOCATION);
+ configuration.setProperty("gremlin.tinkergraph.graphFormat", "gryo");
+ return configuration;
+ }
+
+ private Graph getWriteGraph() {
+ return GraphFactory.open(getWriteGraphConfiguration());
+ }
+
+ @After
+ public void cleanup() {
+ final File graph = new File(TINKERGRAPH_LOCATION);
+ assertTrue(!graph.exists() || graph.delete());
}
@Test
@@ -60,23 +78,43 @@ public class BulkLoaderVertexProgramTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
public void shouldStoreOriginalIds() throws Exception {
- final BulkLoader loader = getBulkLoader(BulkLoaderVertexProgram.build().userSuppliedIds(false).create(graph));
+ final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
+ .userSuppliedIds(false)
+ .writeGraph(getWriteGraphConfiguration()).create(graph);
+ final BulkLoader loader = getBulkLoader(blvp);
assertFalse(loader.useUserSuppliedIds());
- final Graph target = getTargetGraph();
- graph.vertices().forEachRemaining(v -> loader.getOrCreateVertex(v, target, target.traversal()));
+ graph.compute().program(blvp).submit().get();
+ final Graph target = getWriteGraph();
+ assertEquals(IteratorUtils.count(graph.vertices()), IteratorUtils.count(target.vertices()));
+ assertEquals(IteratorUtils.count(graph.edges()), IteratorUtils.count(target.edges()));
target.vertices().forEachRemaining(v -> assertTrue(v.property(loader.getVertexIdProperty()).isPresent()));
}
@Test
@LoadGraphWith(MODERN)
public void shouldNotStoreOriginalIds() throws Exception {
- final BulkLoader loader = getBulkLoader(BulkLoaderVertexProgram.build().userSuppliedIds(true).create(graph));
+ final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
+ .userSuppliedIds(true)
+ .writeGraph(getWriteGraphConfiguration()).create(graph);
+ final BulkLoader loader = getBulkLoader(blvp);
assertTrue(loader.useUserSuppliedIds());
- final Graph target = getTargetGraph();
- graph.vertices().forEachRemaining(v -> loader.getOrCreateVertex(v, target, target.traversal()));
+ graph.compute().program(blvp).submit().get();
+ final Graph target = getWriteGraph();
+ assertEquals(IteratorUtils.count(graph.vertices()), IteratorUtils.count(target.vertices()));
+ assertEquals(IteratorUtils.count(graph.edges()), IteratorUtils.count(target.edges()));
target.vertices().forEachRemaining(v -> assertFalse(v.property(loader.getVertexIdProperty()).isPresent()));
}
- // TODO: once Neo4j supports concurrent connections, write a real integration test that leverages BLVP
- // TODO: also, once Neo4j can be used, remove the tinkergraph-gremlin dependency from hadoop-gremlin and clean up the existing tests
+ @Test
+ @LoadGraphWith(MODERN)
+ public void shouldOverwriteExistingElements() throws Exception {
+ final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
+ .userSuppliedIds(true)
+ .writeGraph(getWriteGraphConfiguration()).create(graph);
+ graph.compute().program(blvp).submit().get(); // initial
+ graph.compute().program(blvp).submit().get(); // incremental
+ final Graph target = getWriteGraph();
+ assertEquals(IteratorUtils.count(graph.vertices()), IteratorUtils.count(target.vertices()));
+ assertEquals(IteratorUtils.count(graph.edges()), IteratorUtils.count(target.edges()));
+ }
}
\ No newline at end of file