use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GMLWriterTest method testEncoding.
// Note: this is only a very lightweight test of writer/reader encoding.
// It is known that there are characters which, when written by GMLWriter,
// cause parse errors for GraphMLReader.
// However, this happens uncommonly enough that is not yet known which characters those are.
public void testEncoding() throws Exception {
Graph g = new TinkerGraph();
Vertex v = g.addVertex(1);
v.setProperty("text", "\u00E9");
GMLWriter w = new GMLWriter(g);
File f = File.createTempFile("test", "txt");
f.deleteOnExit();
OutputStream out = new FileOutputStream(f);
w.outputGraph(out);
out.close();
Graph g2 = new TinkerGraph();
GMLReader r = new GMLReader(g2);
InputStream in = new FileInputStream(f);
r.inputGraph(in);
in.close();
Vertex v2 = g2.getVertex(1);
assertEquals("\u00E9", v2.getProperty("text"));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonNormalLabelOrIdOnEdge.
@Test
public void edgeFromJsonNormalLabelOrIdOnEdge() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);
Edge e = GraphSONUtility.edgeFromJson(new JSONObject(new JSONTokener(edgeJsonLight)), v1, v2, factory, GraphSONMode.NORMAL, null);
Assert.assertSame(v1, g.getVertex(1));
Assert.assertSame(v2, g.getVertex(2));
Assert.assertSame(e, g.getEdge(0));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method vertexFromJsonIgnoreKeyValid.
@Test
public void vertexFromJsonIgnoreKeyValid() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Set<String> ignoreAge = new HashSet<String>();
ignoreAge.add("age");
ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(ignoreAge, null);
GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
Vertex v = utility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
Assert.assertSame(v, g.getVertex(1));
// tinkergraph converts id to string
Assert.assertEquals("1", v.getId());
Assert.assertEquals("marko", v.getProperty("name"));
Assert.assertNull(v.getProperty("age"));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class PartitionGraphTest method testSpecificBehavior.
public void testSpecificBehavior() {
TinkerGraph rawGraph = new TinkerGraph();
PartitionIndexableGraph graph = new PartitionIndexableGraph(rawGraph, "_writeGraph", "a");
assertEquals(graph.getReadPartitions().size(), 1);
assertTrue(graph.getReadPartitions().contains("a"));
assertEquals(graph.getWritePartition(), "a");
Vertex marko = graph.addVertex(null);
Vertex rawMarko = ((PartitionVertex) marko).getBaseVertex();
assertEquals(marko.getPropertyKeys().size(), 0);
assertEquals(rawMarko.getPropertyKeys().size(), 1);
assertNull(marko.getProperty("_writeGraph"));
assertEquals(rawMarko.getProperty("_writeGraph"), "a");
assertEquals(((PartitionVertex) marko).getPartition(), "a");
assertEquals(count(graph.getVertices()), 1);
assertEquals(graph.getVertices().iterator().next(), marko);
assertEquals(count(graph.getEdges()), 0);
graph.setWritePartition("b");
assertEquals(graph.getReadPartitions().size(), 1);
assertTrue(graph.getReadPartitions().contains("a"));
assertEquals(graph.getWritePartition(), "b");
Vertex peter = graph.addVertex(null);
Vertex rawPeter = ((PartitionVertex) peter).getBaseVertex();
assertEquals(peter.getPropertyKeys().size(), 0);
assertEquals(rawPeter.getPropertyKeys().size(), 1);
assertNull(peter.getProperty("_writeGraph"));
assertEquals(rawPeter.getProperty("_writeGraph"), "b");
assertEquals(((PartitionVertex) peter).getPartition(), "b");
assertEquals(count(graph.getVertices()), 1);
assertEquals(graph.getVertices().iterator().next(), marko);
assertEquals(count(graph.getEdges()), 0);
graph.removeReadPartition("a");
assertEquals(graph.getReadPartitions().size(), 0);
assertEquals(graph.getWritePartition(), "b");
assertEquals(count(graph.getVertices()), 0);
assertEquals(count(graph.getEdges()), 0);
graph.addReadPartition("b");
assertEquals(graph.getReadPartitions().size(), 1);
assertTrue(graph.getReadPartitions().contains("b"));
assertEquals(graph.getWritePartition(), "b");
assertEquals(count(graph.getVertices()), 1);
assertEquals(graph.getVertices().iterator().next(), peter);
assertEquals(count(graph.getEdges()), 0);
graph.addReadPartition("a");
assertEquals(graph.getReadPartitions().size(), 2);
assertTrue(graph.getReadPartitions().contains("a"));
assertTrue(graph.getReadPartitions().contains("b"));
assertEquals(graph.getWritePartition(), "b");
assertEquals(count(graph.getVertices()), 2);
assertEquals(count(graph.getEdges()), 0);
graph.setWritePartition("c");
assertEquals(graph.getReadPartitions().size(), 2);
assertTrue(graph.getReadPartitions().contains("a"));
assertTrue(graph.getReadPartitions().contains("b"));
assertEquals(graph.getWritePartition(), "c");
Edge knows = graph.addEdge(null, marko, peter, "knows");
Edge rawKnows = ((PartitionEdge) knows).getBaseEdge();
assertEquals(count(graph.getVertices()), 2);
assertEquals(count(graph.getEdges()), 0);
graph.addReadPartition("c");
assertEquals(count(graph.getVertices()), 2);
assertEquals(count(graph.getEdges()), 1);
assertEquals(knows.getPropertyKeys().size(), 0);
assertEquals(rawKnows.getPropertyKeys().size(), 1);
assertNull(knows.getProperty("_writeGraph"));
assertEquals(rawKnows.getProperty("_writeGraph"), "c");
assertEquals(((PartitionEdge) knows).getPartition(), "c");
assertEquals(graph.getEdges().iterator().next(), knows);
graph.removeReadPartition("a");
graph.removeReadPartition("b");
assertEquals(graph.getReadPartitions().size(), 1);
assertTrue(graph.getReadPartitions().contains("c"));
assertEquals(graph.getWritePartition(), "c");
assertEquals(count(graph.getVertices()), 0);
assertEquals(count(graph.getEdges()), 1);
assertNull(knows.getVertex(Direction.IN));
assertNull(knows.getVertex(Direction.OUT));
// testing indices
/*marko.setProperty("name", "marko");
peter.setProperty("name", "peter");
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 0);
graph.addReadPartition("a");
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 1);
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter")), 0);
assertEquals(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko").next(), marko);
graph.removeReadPartition("a");
graph.addReadPartition("b");
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter")), 1);
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 0);
assertEquals(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter").next(), peter);
graph.addReadPartition("a");
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "peter")), 1);
assertEquals(count(graph.getIndex(Index.VERTICES, Vertex.class).get("name", "marko")), 1);
assertEquals(count(graph.getIndex(Index.EDGES, Edge.class).get("label", "knows")), 1);
assertEquals(graph.getIndex(Index.EDGES, Edge.class).get("label", "knows").next(), knows);
graph.removeReadPartition("c");
assertEquals(count(graph.getIndex(Index.EDGES, Edge.class).get("label", "knows")), 0);
*/
graph.shutdown();
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class PartitionGraphTest method testVerticesSeparatedByEdgeInDifferentPartition.
public void testVerticesSeparatedByEdgeInDifferentPartition() {
TinkerGraph rawGraph = new TinkerGraph();
PartitionIndexableGraph graph = new PartitionIndexableGraph(rawGraph, "_writeGraph", "p1");
Vertex inp1 = graph.addVertex("inp1");
graph.setWritePartition("p2");
Vertex inp2 = graph.addVertex("inp2");
inp2.setProperty("key", "value");
graph.setWritePartition("p3");
graph.addEdge("inp3", inp1, inp2, "links");
assertNull(graph.getVertex("inp2"));
graph.addReadPartition("p2");
graph.addReadPartition("p3");
assertNotNull(graph.getVertex("inp1"));
assertNotNull(graph.getVertex("inp2"));
assertTrue(graph.getVertex("inp1").getEdges(Direction.OUT).iterator().hasNext());
graph.removeReadPartition("p2");
assertTrue(graph.getVertex("inp1").getEdges(Direction.OUT).iterator().hasNext());
// the vertex at the end of this traversal is in the p2 partition which was removed above. it should return
// null, throw exception, something....
assertNull(graph.getVertex("inp1").getEdges(Direction.OUT).iterator().next().getVertex(Direction.IN));
}
Aggregations