use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class BatchGraphTest method testQuadLoading.
public void testQuadLoading() {
int numEdges = 10000;
String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
TinkerGraph graph = new TinkerGraph();
BatchGraph bgraph = new BatchGraph(new WritethroughGraph(graph), VertexIDType.STRING, 1000);
for (String[] quad : quads) {
Vertex[] vertices = new Vertex[2];
for (int i = 0; i < 2; i++) {
vertices[i] = bgraph.getVertex(quad[i]);
if (vertices[i] == null)
vertices[i] = bgraph.addVertex(quad[i]);
}
Edge edge = bgraph.addEdge(null, vertices[0], vertices[1], quad[2]);
edge.setProperty("annotation", quad[3]);
}
assertEquals(numEdges, BaseTest.count(graph.getEdges()));
bgraph.shutdown();
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class BatchGraphTest method testLoadingWithExisting2.
public void testLoadingWithExisting2() {
int numEdges = 1000;
String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
TinkerGraph tg = new IgnoreIdTinkerGraph();
BatchGraph bg = new BatchGraph(new WritethroughGraph(tg), VertexIDType.STRING, 100);
try {
bg.setLoadingFromScratch(false);
fail();
} catch (IllegalStateException e) {
}
bg.setVertexIdKey("uid");
bg.setLoadingFromScratch(false);
try {
bg.setVertexIdKey(null);
fail();
} catch (IllegalStateException e) {
}
Graph graph = null;
int counter = 0;
for (String[] quad : quads) {
if (counter < numEdges / 2)
graph = tg;
else
graph = bg;
Vertex[] vertices = new Vertex[2];
for (int i = 0; i < 2; i++) {
vertices[i] = graph.getVertex(quad[i]);
if (vertices[i] == null)
vertices[i] = graph.addVertex(quad[i]);
}
Edge edge = graph.addEdge(null, vertices[0], vertices[1], quad[2]);
edge.setProperty("annotation", quad[3]);
counter++;
}
assertEquals(numEdges, BaseTest.count(tg.getEdges()));
bg.shutdown();
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactNoIdOnEdge.
@Test
public void edgeFromJsonInputStreamCompactNoIdOnEdge() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Set<String> vertexKeys = new HashSet<String>() {
{
add(GraphSONTokens._ID);
}
};
Set<String> edgeKeys = new HashSet<String>() {
{
add(GraphSONTokens._IN_V);
}
};
GraphSONUtility graphson = new GraphSONUtility(GraphSONMode.COMPACT, factory, vertexKeys, edgeKeys);
Vertex v1 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
Vertex v2 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)));
Edge e = graphson.edgeFromJson(inputStreamEdgeJsonLight, v1, v2);
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 edgeFromJsonValid.
@Test
public void edgeFromJsonValid() 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(edgeJson)), v1, v2, factory, GraphSONMode.NORMAL, null);
Assert.assertSame(v1, g.getVertex(1));
Assert.assertSame(v2, g.getVertex(2));
Assert.assertSame(e, g.getEdge(7));
// tinkergraph converts id to string
Assert.assertEquals("7", e.getId());
Assert.assertEquals(0.5d, e.getProperty("weight"));
Assert.assertEquals("knows", e.getLabel());
Assert.assertEquals(v1, e.getVertex(Direction.OUT));
Assert.assertEquals(v2, e.getVertex(Direction.IN));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementNullsNoKeysWithTypes.
@Test
public void jsonFromElementNullsNoKeysWithTypes() throws JSONException {
Graph g = new TinkerGraph();
Vertex v = g.addVertex(1);
Map<String, Object> map = new HashMap<String, Object>();
map.put("innerkey", null);
List<String> innerList = new ArrayList<String>();
innerList.add(null);
innerList.add("innerstring");
map.put("list", innerList);
v.setProperty("keyMap", map);
List<String> list = new ArrayList<String>();
list.add(null);
list.add("string");
v.setProperty("keyList", list);
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.EXTENDED);
Assert.assertNotNull(json);
JSONObject jsonMap = json.optJSONObject("keyMap").optJSONObject(GraphSONTokens.VALUE);
Assert.assertNotNull(jsonMap);
JSONObject jsonObjectMap = jsonMap.optJSONObject("innerkey");
Assert.assertTrue(jsonObjectMap.isNull(GraphSONTokens.VALUE));
Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectMap.optString(GraphSONTokens.TYPE));
JSONArray jsonInnerArray = jsonMap.getJSONObject("list").getJSONArray(GraphSONTokens.VALUE);
Assert.assertNotNull(jsonInnerArray);
JSONObject jsonObjectInnerListFirst = jsonInnerArray.getJSONObject(0);
Assert.assertTrue(jsonObjectInnerListFirst.isNull(GraphSONTokens.VALUE));
Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectInnerListFirst.optString(GraphSONTokens.TYPE));
JSONArray jsonArray = json.getJSONObject("keyList").getJSONArray(GraphSONTokens.VALUE);
Assert.assertNotNull(jsonArray);
JSONObject jsonObjectListFirst = jsonArray.getJSONObject(0);
Assert.assertTrue(jsonObjectListFirst.isNull(GraphSONTokens.VALUE));
Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectListFirst.optString(GraphSONTokens.TYPE));
}
Aggregations