|
14 | 14 |
|
15 | 15 | package org.janusgraph.hadoop; |
16 | 16 |
|
| 17 | +import org.apache.commons.configuration.ConfigurationException; |
| 18 | +import org.apache.commons.configuration.PropertiesConfiguration; |
17 | 19 | import org.janusgraph.CassandraStorageSetup; |
18 | | -import org.janusgraph.core.Cardinality; |
19 | | -import org.janusgraph.core.JanusGraphVertex; |
20 | 20 | import org.janusgraph.diskstorage.configuration.ModifiableConfiguration; |
21 | 21 | import org.janusgraph.diskstorage.configuration.WriteConfiguration; |
22 | | -import org.janusgraph.example.GraphOfTheGodsFactory; |
23 | | -import org.janusgraph.graphdb.JanusGraphBaseTest; |
24 | | -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; |
25 | | -import org.apache.tinkerpop.gremlin.spark.process.computer.SparkGraphComputer; |
26 | | -import org.apache.tinkerpop.gremlin.structure.Direction; |
27 | | -import org.apache.tinkerpop.gremlin.structure.Edge; |
28 | 22 | import org.apache.tinkerpop.gremlin.structure.Graph; |
29 | | -import org.apache.tinkerpop.gremlin.structure.Vertex; |
30 | 23 | import org.apache.tinkerpop.gremlin.structure.util.GraphFactory; |
31 | | -import org.junit.Test; |
32 | 24 |
|
33 | | -import java.util.Iterator; |
34 | | -import java.util.List; |
35 | | -import java.util.Map; |
36 | | -import java.util.Set; |
| 25 | +import java.io.IOException; |
| 26 | +import java.nio.file.Files; |
| 27 | +import java.nio.file.Path; |
| 28 | +import java.nio.file.Paths; |
37 | 29 |
|
38 | | -import com.google.common.collect.Iterators; |
39 | | -import com.google.common.collect.Lists; |
40 | | -import com.google.common.collect.Sets; |
| 30 | +public class CassandraInputFormatIT extends AbstractInputFormatIT { |
41 | 31 |
|
42 | | -import static org.junit.Assert.assertEquals; |
43 | | -import static org.junit.Assert.assertNotNull; |
44 | | -import static org.junit.Assert.assertTrue; |
45 | | - |
46 | | -public class CassandraInputFormatIT extends JanusGraphBaseTest { |
47 | | - |
48 | | - |
49 | | - @Test |
50 | | - public void testReadGraphOfTheGods() { |
51 | | - GraphOfTheGodsFactory.load(graph, null, true); |
52 | | - assertEquals(12L, (long) graph.traversal().V().count().next()); |
53 | | - Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); |
54 | | - GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); |
55 | | - assertEquals(12L, (long) t.V().count().next()); |
56 | | - } |
57 | | - |
58 | | - @Test |
59 | | - public void testReadWideVertexWithManyProperties() { |
60 | | - int numProps = 1 << 16; |
61 | | - |
62 | | - long numV = 1; |
63 | | - mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make(); |
64 | | - mgmt.commit(); |
65 | | - finishSchema(); |
66 | | - |
67 | | - for (int j = 0; j < numV; j++) { |
68 | | - Vertex v = graph.addVertex(); |
69 | | - for (int i = 0; i < numProps; i++) { |
70 | | - v.property("p", i); |
71 | | - } |
72 | | - } |
73 | | - graph.tx().commit(); |
74 | | - |
75 | | - assertEquals(numV, (long) graph.traversal().V().count().next()); |
76 | | - Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next(); |
77 | | - List<?> valuesOnP = (List)propertiesOnVertex.values().iterator().next(); |
78 | | - assertEquals(numProps, valuesOnP.size()); |
79 | | - Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); |
80 | | - GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); |
81 | | - assertEquals(numV, (long) t.V().count().next()); |
82 | | - propertiesOnVertex = t.V().valueMap().next(); |
83 | | - valuesOnP = (List)propertiesOnVertex.values().iterator().next(); |
84 | | - assertEquals(numProps, valuesOnP.size()); |
85 | | - } |
86 | | - |
87 | | - @Test |
88 | | - public void testReadSelfEdge() { |
89 | | - GraphOfTheGodsFactory.load(graph, null, true); |
90 | | - assertEquals(12L, (long) graph.traversal().V().count().next()); |
91 | | - |
92 | | - // Add a self-loop on sky with edge label "lives"; it's nonsense, but at least it needs no schema changes |
93 | | - JanusGraphVertex sky = (JanusGraphVertex)graph.query().has("name", "sky").vertices().iterator().next(); |
94 | | - assertNotNull(sky); |
95 | | - assertEquals("sky", sky.value("name")); |
96 | | - assertEquals(1L, sky.query().direction(Direction.IN).edgeCount()); |
97 | | - assertEquals(0L, sky.query().direction(Direction.OUT).edgeCount()); |
98 | | - assertEquals(1L, sky.query().direction(Direction.BOTH).edgeCount()); |
99 | | - sky.addEdge("lives", sky, "reason", "testReadSelfEdge"); |
100 | | - assertEquals(2L, sky.query().direction(Direction.IN).edgeCount()); |
101 | | - assertEquals(1L, sky.query().direction(Direction.OUT).edgeCount()); |
102 | | - assertEquals(3L, sky.query().direction(Direction.BOTH).edgeCount()); |
103 | | - graph.tx().commit(); |
104 | | - |
105 | | - // Read the new edge using the inputformat |
106 | | - Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); |
107 | | - GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); |
108 | | - Iterator<Object> edgeIdIter = t.V().has("name", "sky").bothE().id(); |
109 | | - assertNotNull(edgeIdIter); |
110 | | - assertTrue(edgeIdIter.hasNext()); |
111 | | - Set<Object> edges = Sets.newHashSet(edgeIdIter); |
112 | | - assertEquals(2, edges.size()); |
| 32 | + protected Graph getGraph() throws ConfigurationException, IOException { |
| 33 | + final PropertiesConfiguration config = new PropertiesConfiguration("target/test-classes/cassandra-read.properties"); |
| 34 | + Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation")); |
| 35 | + baseOutDir.toFile().mkdirs(); |
| 36 | + String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString(); |
| 37 | + config.setProperty("gremlin.hadoop.outputLocation", outDir); |
| 38 | + return GraphFactory.open(config); |
113 | 39 | } |
114 | 40 |
|
115 | 41 | @Override |
|
0 commit comments