use of com.tinkerpop.blueprints.Vertex 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.Vertex 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));
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class ReadOnlyGraphTest method testWrappedElementUniqueness.
public void testWrappedElementUniqueness() {
Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
assertEquals(graph.getVertex(1), graph.getVertex(1));
Set<Vertex> set = new HashSet<Vertex>();
set.add(graph.getVertex(2));
set.add(graph.getVertex(2));
assertEquals(set.size(), 1);
assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
assertEquals(graph.getEdge(8), graph.getEdge(8));
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementVertexListPropertyNoKeysNoTypes.
@Test
public void jsonFromElementVertexListPropertyNoKeysNoTypes() throws JSONException {
Vertex v = this.graph.addVertex(1);
List<Object> list = new ArrayList<Object>();
list.add("this");
list.add("that");
list.add("other");
list.add(true);
v.setProperty("keyList", list);
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL);
Assert.assertNotNull(json);
Assert.assertTrue(json.has(GraphSONTokens._ID));
Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
Assert.assertTrue(json.has("keyList"));
JSONArray listAsJSON = json.optJSONArray("keyList");
Assert.assertNotNull(listAsJSON);
Assert.assertEquals(4, listAsJSON.length());
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementVertexCatArrayPropertyNoKeysNoTypes.
@Test
public void jsonFromElementVertexCatArrayPropertyNoKeysNoTypes() throws JSONException {
Vertex v = this.graph.addVertex(1);
List<Cat> cats = new ArrayList<Cat>();
cats.add(new Cat("smithers"));
cats.add(new Cat("mcallister"));
v.setProperty("cats", cats);
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL);
Assert.assertNotNull(json);
Assert.assertTrue(json.has(GraphSONTokens._ID));
Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
Assert.assertTrue(json.has("cats"));
JSONArray catListAsJson = json.optJSONArray("cats");
Assert.assertNotNull(catListAsJson);
Assert.assertEquals(2, catListAsJson.length());
}
Aggregations