You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/04/28 14:02:57 UTC
[2/2] incubator-tinkerpop git commit: Pull data generation tests out
to their own test class.
Pull data generation tests out to their own test class.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/10cff840
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/10cff840
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/10cff840
Branch: refs/heads/master
Commit: 10cff840c486aa9a096df8b8e407ec5fc3f92fd9
Parents: ae33e8f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Apr 28 08:02:29 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Apr 28 08:02:29 2015 -0400
----------------------------------------------------------------------
tinkergraph-gremlin/pom.xml | 2 +-
.../structure/IoDataGenerationTest.java | 343 +++++++++++++++++++
.../tinkergraph/structure/TinkerGraphTest.java | 312 -----------------
3 files changed, 344 insertions(+), 313 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/10cff840/tinkergraph-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/pom.xml b/tinkergraph-gremlin/pom.xml
index 4a420b7..27030a2 100644
--- a/tinkergraph-gremlin/pom.xml
+++ b/tinkergraph-gremlin/pom.xml
@@ -83,7 +83,7 @@ limitations under the License.
<version>2.17</version>
<configuration>
<includes>
- <include>**/TinkerGraphTest.java</include>
+ <include>**/IoDataGenerationTest.java</include>
</includes>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/10cff840/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
new file mode 100644
index 0000000..5e8f98a
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
@@ -0,0 +1,343 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.tinkergraph.structure;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.algorithm.generator.DistributionGenerator;
+import org.apache.tinkerpop.gremlin.algorithm.generator.PowerLawDistribution;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
+import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLWriter;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.stream.IntStream;
+
+/**
+ * Less of a test of functionality and more of a tool to help generate data files for TinkerPop.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoDataGenerationTest {
+ private static String tempPath;
+
+ static {
+ tempPath = TestHelper.makeTestDataPath(TinkerGraphTest.class, "tinkerpop-io").getPath() + File.separator;
+ }
+
+ @BeforeClass
+ public static void before() throws IOException {
+ final File tempDir = new File(tempPath);
+ FileUtils.deleteDirectory(tempDir);
+ if (!tempDir.mkdirs()) throw new IOException(String.format("Could not create %s", tempDir));
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphAsGryo() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic.kryo");
+ GryoWriter.build().create().writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphAsGryo() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.kryo");
+ GryoWriter.build().create().writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewGraphAsGryo() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew.kryo");
+ GryoWriter.build().create().writeGraph(os, TinkerFactory.createTheCrew());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicVerticesAsGryo() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-vertices.kryo");
+ GryoWriter.build().create().writeVertices(os, TinkerFactory.createClassic().traversal().V(), Direction.BOTH);
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicVerticesAsGraphSON() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-vertices.ldjson");
+ GraphSONWriter.build().create().writeVertices(os, TinkerFactory.createClassic().traversal().V(), Direction.BOTH);
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernVerticesAsGryo() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-vertices.kryo");
+ GryoWriter.build().create().writeVertices(os, TinkerFactory.createModern().traversal().V(), Direction.BOTH);
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernVerticesAsGraphSON() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-vertices.ldjson");
+ GraphSONWriter.build().create().writeVertices(os, TinkerFactory.createModern().traversal().V(), Direction.BOTH);
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewVerticesAsGraphSON() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-vertices.ldjson");
+ GraphSONWriter.build().create().writeVertices(os, TinkerFactory.createTheCrew().traversal().V(), Direction.BOTH);
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewVerticesAsGryo() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-vertices.kryo");
+ GryoWriter.build().create().writeVertices(os, TinkerFactory.createTheCrew().traversal().V(), Direction.BOTH);
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphAsGraphML() throws IOException {
+ try (final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic.xml")) {
+ GraphMLWriter.build().create().writeGraph(os, TinkerFactory.createClassic());
+ }
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphAsGraphML() throws IOException {
+ try (final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.xml")) {
+ GraphMLWriter.build().create().writeGraph(os, TinkerFactory.createModern());
+ }
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphAsGraphSONNoTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic.json");
+ GraphSONWriter.build().create().writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphAsGraphSONNoTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.json");
+ GraphSONWriter.build().create().writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewGraphAsGraphSONNoTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew.json");
+ GraphSONWriter.build().create().writeGraph(os, TinkerFactory.createTheCrew());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphNormalizedAsGraphSON() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-normalized.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).create()).create().writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphNormalizedAsGraphSON() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-normalized.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).create()).create().writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphAsGraphSONWithTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create())
+ .create().writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphAsGraphSONWithTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create())
+ .create().writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewGraphAsGraphSONWithTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create())
+ .create().writeGraph(os, TinkerFactory.createTheCrew());
+ os.close();
+ }
+
+ @Test
+ public void shouldWriteSampleForGremlinServer() throws IOException {
+ final Graph g = TinkerGraph.open();
+ IntStream.range(0, 10000).forEach(i -> g.addVertex("oid", i));
+ DistributionGenerator.build(g)
+ .label("knows")
+ .seedGenerator(() -> 987654321l)
+ .outDistribution(new PowerLawDistribution(2.1))
+ .inDistribution(new PowerLawDistribution(2.1))
+ .expectedNumEdges(100000).create().generate();
+
+ final OutputStream os = new FileOutputStream(tempPath + "sample.kryo");
+ GryoWriter.build().create().writeGraph(os, g);
+ os.close();
+ }
+
+ /**
+ * This test helps with data conversions on Grateful Dead. No Assertions...run as needed. Never read from the
+ * GraphML source as it will always use a String identifier.
+ */
+ @Test
+ public void shouldWriteGratefulDead() throws IOException {
+ final Graph g = TinkerGraph.open();
+
+ final GraphReader reader = GryoReader.build().create();
+ try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/org/apache/tinkerpop/gremlin/structure/io/gryo/grateful-dead.kryo")) {
+ reader.readGraph(stream, g);
+ }
+
+ /* keep this hanging around because changes to gryo format will need grateful dead generated from json so you can generate the gio
+ final GraphSONMapper mapper = GraphSONMapper.build().embedTypes(true).create();
+ final GraphReader reader = org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.build().mapper(mapper).create();
+ try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/org/apache/tinkerpop/gremlin/structure/io/graphson/grateful-dead.json")) {
+ reader.readGraph(stream, g);
+ }
+ */
+
+ final Graph ng = TinkerGraph.open();
+ g.traversal().V().sideEffect(ov -> {
+ final Vertex v = ov.get();
+ if (v.label().equals("song"))
+ ng.addVertex(T.id, Integer.parseInt(v.id().toString()), T.label, "song", "name", v.value("name"), "performances", v.property("performances").orElse(0), "songType", v.property("songType").orElse(""));
+ else if (v.label().equals("artist"))
+ ng.addVertex(T.id, Integer.parseInt(v.id().toString()), T.label, "artist", "name", v.value("name"));
+ else
+ throw new RuntimeException("damn");
+ }).iterate();
+
+ g.traversal().E().sideEffect(oe -> {
+ final Edge e = oe.get();
+ final Vertex v2 = ng.traversal().V(Integer.parseInt(e.inVertex().id().toString())).next();
+ final Vertex v1 = ng.traversal().V(Integer.parseInt(e.outVertex().id().toString())).next();
+
+ if (e.label().equals("followedBy"))
+ v1.addEdge("followedBy", v2, T.id, Integer.parseInt(e.id().toString()), "weight", e.value("weight"));
+ else if (e.label().equals("sungBy"))
+ v1.addEdge("sungBy", v2, T.id, Integer.parseInt(e.id().toString()));
+ else if (e.label().equals("writtenBy"))
+ v1.addEdge("writtenBy", v2, T.id, Integer.parseInt(e.id().toString()));
+ else
+ throw new RuntimeException("bah");
+
+ }).iterate();
+
+ final OutputStream os = new FileOutputStream(tempPath + "grateful-dead.kryo");
+ GryoWriter.build().create().writeGraph(os, ng);
+ os.close();
+
+ final OutputStream os2 = new FileOutputStream(tempPath + "grateful-dead.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create()).create().writeGraph(os2, g);
+ os2.close();
+
+ final OutputStream os3 = new FileOutputStream(tempPath + "grateful-dead.xml");
+ GraphMLWriter.build().create().writeGraph(os3, g);
+ os3.close();
+
+ final OutputStream os4 = new FileOutputStream(tempPath + "grateful-dead-vertices.kryo");
+ GryoWriter.build().create().writeVertices(os4, g.traversal().V(), Direction.BOTH);
+ os.close();
+
+ final OutputStream os5 = new FileOutputStream(tempPath + "grateful-dead-vertices.ldjson");
+ GraphSONWriter.build().create().writeVertices(os5, g.traversal().V(), Direction.BOTH);
+ os.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/10cff840/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 36f108b..3bbd6b3 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -18,45 +18,22 @@
*/
package org.apache.tinkerpop.gremlin.tinkergraph.structure;
-import org.apache.commons.io.FileUtils;
-import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
-import org.apache.tinkerpop.gremlin.TestHelper;
-import org.apache.tinkerpop.gremlin.algorithm.generator.DistributionGenerator;
-import org.apache.tinkerpop.gremlin.algorithm.generator.PowerLawDistribution;
import org.apache.tinkerpop.gremlin.structure.P;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Operator;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLIo;
-import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLWriter;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
-import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
-import java.util.Random;
import java.util.Set;
import java.util.function.Supplier;
-import java.util.stream.IntStream;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
import static org.junit.Assert.assertEquals;
@@ -68,19 +45,6 @@ import static org.junit.Assert.assertTrue;
*/
public class TinkerGraphTest {
- private static String tempPath;
-
- static {
- tempPath = TestHelper.makeTestDataPath(TinkerGraphTest.class, "tinkerpop-io").getPath() + File.separator;
- }
-
- @BeforeClass
- public static void before() throws IOException {
- final File tempDir = new File(tempPath);
- FileUtils.deleteDirectory(tempDir);
- if (!tempDir.mkdirs()) throw new IOException(String.format("Could not create %s", tempDir));
- }
-
@Test
@Ignore
public void testPlay() {
@@ -201,199 +165,6 @@ public class TinkerGraphTest {
g.V().has("age").values("name").forEachRemaining(System.out::println);
}
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicGraphAsGryo() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic.kryo");
- GryoWriter.build().create().writeGraph(os, TinkerFactory.createClassic());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernGraphAsGryo() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.kryo");
- GryoWriter.build().create().writeGraph(os, TinkerFactory.createModern());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteCrewGraphAsGryo() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew.kryo");
- GryoWriter.build().create().writeGraph(os, TinkerFactory.createTheCrew());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicVerticesAsGryo() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-vertices.kryo");
- GryoWriter.build().create().writeVertices(os, TinkerFactory.createClassic().traversal().V(), Direction.BOTH);
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicVerticesAsGraphSON() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-vertices.ldjson");
- GraphSONWriter.build().create().writeVertices(os, TinkerFactory.createClassic().traversal().V(), Direction.BOTH);
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernVerticesAsGryo() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-vertices.kryo");
- GryoWriter.build().create().writeVertices(os, TinkerFactory.createModern().traversal().V(), Direction.BOTH);
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernVerticesAsGraphSON() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-vertices.ldjson");
- GraphSONWriter.build().create().writeVertices(os, TinkerFactory.createModern().traversal().V(), Direction.BOTH);
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteCrewVerticesAsGraphSON() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-vertices.ldjson");
- GraphSONWriter.build().create().writeVertices(os, TinkerFactory.createTheCrew().traversal().V(), Direction.BOTH);
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteCrewVerticesAsGryo() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-vertices.kryo");
- GryoWriter.build().create().writeVertices(os, TinkerFactory.createTheCrew().traversal().V(), Direction.BOTH);
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicGraphAsGraphML() throws IOException {
- try (final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic.xml")) {
- GraphMLWriter.build().create().writeGraph(os, TinkerFactory.createClassic());
- }
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernGraphAsGraphML() throws IOException {
- try (final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.xml")) {
- GraphMLWriter.build().create().writeGraph(os, TinkerFactory.createModern());
- }
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicGraphAsGraphSONNoTypes() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic.json");
- GraphSONWriter.build().create().writeGraph(os, TinkerFactory.createClassic());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernGraphAsGraphSONNoTypes() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.json");
- GraphSONWriter.build().create().writeGraph(os, TinkerFactory.createModern());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteCrewGraphAsGraphSONNoTypes() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew.json");
- GraphSONWriter.build().create().writeGraph(os, TinkerFactory.createTheCrew());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicGraphNormalizedAsGraphSON() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-normalized.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).create()).create().writeGraph(os, TinkerFactory.createClassic());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernGraphNormalizedAsGraphSON() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-normalized.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).create()).create().writeGraph(os, TinkerFactory.createModern());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteClassicGraphAsGraphSONWithTypes() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-typed.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create())
- .create().writeGraph(os, TinkerFactory.createClassic());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteModernGraphAsGraphSONWithTypes() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-typed.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create())
- .create().writeGraph(os, TinkerFactory.createModern());
- os.close();
- }
-
- /**
- * No assertions. Just write out the graph for convenience.
- */
- @Test
- public void shouldWriteCrewGraphAsGraphSONWithTypes() throws IOException {
- final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-typed.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create())
- .create().writeGraph(os, TinkerFactory.createTheCrew());
- os.close();
- }
-
@Test
public void shouldManageIndices() {
final TinkerGraph g = TinkerGraph.open();
@@ -622,88 +393,5 @@ public class TinkerGraphTest {
}, 0.5)).has("oid", "1").count().next());
}
- @Test
- public void shouldWriteSampleForGremlinServer() throws IOException {
- final Graph g = TinkerGraph.open();
- IntStream.range(0, 10000).forEach(i -> g.addVertex("oid", i));
- DistributionGenerator.build(g)
- .label("knows")
- .seedGenerator(() -> 987654321l)
- .outDistribution(new PowerLawDistribution(2.1))
- .inDistribution(new PowerLawDistribution(2.1))
- .expectedNumEdges(100000).create().generate();
-
- final OutputStream os = new FileOutputStream(tempPath + "sample.kryo");
- GryoWriter.build().create().writeGraph(os, g);
- os.close();
- }
-
- /**
- * This test helps with data conversions on Grateful Dead. No Assertions...run as needed. Never read from the
- * GraphML source as it will always use a String identifier.
- */
- @Test
- public void shouldWriteGratefulDead() throws IOException {
- final Graph g = TinkerGraph.open();
- final GraphReader reader = GryoReader.build().create();
- try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/org/apache/tinkerpop/gremlin/structure/io/gryo/grateful-dead.kryo")) {
- reader.readGraph(stream, g);
- }
-
- /* keep this hanging around because changes to gryo format will need grateful dead generated from json so you can generate the gio
- final GraphSONMapper mapper = GraphSONMapper.build().embedTypes(true).create();
- final GraphReader reader = org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.build().mapper(mapper).create();
- try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/org/apache/tinkerpop/gremlin/structure/io/graphson/grateful-dead.json")) {
- reader.readGraph(stream, g);
- }
- */
-
- final Graph ng = TinkerGraph.open();
- g.traversal().V().sideEffect(ov -> {
- final Vertex v = ov.get();
- if (v.label().equals("song"))
- ng.addVertex(T.id, Integer.parseInt(v.id().toString()), T.label, "song", "name", v.value("name"), "performances", v.property("performances").orElse(0), "songType", v.property("songType").orElse(""));
- else if (v.label().equals("artist"))
- ng.addVertex(T.id, Integer.parseInt(v.id().toString()), T.label, "artist", "name", v.value("name"));
- else
- throw new RuntimeException("damn");
- }).iterate();
-
- g.traversal().E().sideEffect(oe -> {
- final Edge e = oe.get();
- final Vertex v2 = ng.traversal().V(Integer.parseInt(e.inVertex().id().toString())).next();
- final Vertex v1 = ng.traversal().V(Integer.parseInt(e.outVertex().id().toString())).next();
-
- if (e.label().equals("followedBy"))
- v1.addEdge("followedBy", v2, T.id, Integer.parseInt(e.id().toString()), "weight", e.value("weight"));
- else if (e.label().equals("sungBy"))
- v1.addEdge("sungBy", v2, T.id, Integer.parseInt(e.id().toString()));
- else if (e.label().equals("writtenBy"))
- v1.addEdge("writtenBy", v2, T.id, Integer.parseInt(e.id().toString()));
- else
- throw new RuntimeException("bah");
-
- }).iterate();
-
- final OutputStream os = new FileOutputStream(tempPath + "grateful-dead.kryo");
- GryoWriter.build().create().writeGraph(os, ng);
- os.close();
-
- final OutputStream os2 = new FileOutputStream(tempPath + "grateful-dead.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create()).create().writeGraph(os2, g);
- os2.close();
-
- final OutputStream os3 = new FileOutputStream(tempPath + "grateful-dead.xml");
- GraphMLWriter.build().create().writeGraph(os3, g);
- os3.close();
-
- final OutputStream os4 = new FileOutputStream(tempPath + "grateful-dead-vertices.kryo");
- GryoWriter.build().create().writeVertices(os4, g.traversal().V(), Direction.BOTH);
- os.close();
-
- final OutputStream os5 = new FileOutputStream(tempPath + "grateful-dead-vertices.ldjson");
- GraphSONWriter.build().create().writeVertices(os5, g.traversal().V(), Direction.BOTH);
- os.close();
- }
}