use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class BatchGraphTest method testLoadingWithExisting1.
public void testLoadingWithExisting1() {
int numEdges = 1000;
String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
TinkerGraph tg = new TinkerGraph();
BatchGraph bg = new BatchGraph(new WritethroughGraph(tg), VertexIDType.STRING, 100);
bg.setLoadingFromScratch(false);
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 GMLWriterTest method testRoundTrip.
public void testRoundTrip() throws Exception {
TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GMLWriter w = new GMLWriter(g1);
w.setUseId(true);
w.outputGraph(bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
Graph g2 = new TinkerGraph();
GMLReader.inputGraph(g2, bis);
assertEquals(getIterableCount(g1.getVertices()), getIterableCount(g2.getVertices()));
assertEquals(getIterableCount(g1.getEdges()), getIterableCount(g2.getEdges()));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GMLWriterTest method testUseIds.
public void testUseIds() throws Exception {
TinkerGraph g = new TinkerGraph();
GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GMLWriter w = new GMLWriter(g);
w.setNormalize(true);
w.setUseId(true);
w.outputGraph(bos);
String actual = bos.toString();
String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer2.gml"));
// ignore carriage return character...not really relevant to the test
assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GMLWriterTest method testNormal.
public void testNormal() throws Exception {
TinkerGraph g = new TinkerGraph();
GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GMLWriter w = new GMLWriter(g);
w.setNormalize(true);
w.outputGraph(bos);
String actual = bos.toString();
String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer.gml"));
// ignore carriage return character...not really relevant to the test
assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GMLWriterTest method testRoundTripIgnoreBadProperties.
public void testRoundTripIgnoreBadProperties() throws Exception {
TinkerGraph g1 = TinkerGraphFactory.createTinkerGraph();
Vertex v = g1.getVertex(1);
v.setProperty("bad_property", "underscore");
v.setProperty("bad property", "space");
v.setProperty("bad-property", "dash");
v.setProperty("bad$property", "other stuff");
v.setProperty("badproperty_", "but don't get too fancy");
v.setProperty("_badproperty", "or it won't work");
v.setProperty("55", "numbers alone are bad");
v.setProperty("5badproperty", "must start with alpha");
v.setProperty("badpropertyajflalfjsajfdfjdkfjsdiahfshfksajdhfkjdhfkjhaskdfhaksdhfsalkjdfhkjdhkahsdfkjasdhfkajfdhkajfhkadhfkjsdafhkajfdhasdkfhakfdhakjsdfhkadhfakjfhaksdjhfkajfhakhfaksfdhkahdfkahfkajsdhfkjahdfkahsdfkjahfkhakfsdjhakjksfhakfhaksdhfkadhfakhfdkasfdhiuerfaeafdkjhakfdhfdadfasdfsdafadf", "super long keys won't work");
v.setProperty("good5property", "numbers are cool");
v.setProperty("goodproperty5", "numbers are cool");
v.setProperty("a", "one letter is ok");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GMLWriter w = new GMLWriter(g1);
w.setStrict(true);
w.setUseId(true);
w.outputGraph(bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
Graph g2 = new TinkerGraph();
GMLReader.inputGraph(g2, bis);
assertEquals(getIterableCount(g1.getVertices()), getIterableCount(g2.getVertices()));
assertEquals(getIterableCount(g1.getEdges()), getIterableCount(g2.getEdges()));
Vertex v1 = g2.getVertex(1);
Assert.assertNull(v1.getProperty("bad_property"));
Assert.assertNull(v1.getProperty("bad property"));
Assert.assertNull(v1.getProperty("bad-property"));
Assert.assertNull(v1.getProperty("bad$property"));
Assert.assertNull(v1.getProperty("_badproperty"));
Assert.assertNull(v1.getProperty("badproperty_"));
Assert.assertNull(v1.getProperty("5badproperty"));
Assert.assertNull(v1.getProperty("55"));
Assert.assertNull(v1.getProperty("badpropertyajflalfjsajfdfjdkfjsdiahfshfksajdhfkjdhfkjhaskdfhaksdhfsalkjdfhkjdhkahsdfkjasdhfkajfdhkajfhkadhfkjsdafhkajfdhasdkfhakfdhakjsdfhkadhfakjfhaksdjhfkajfhakhfaksfdhkahdfkahfkajsdhfkjahdfkahsdfkjahfkhakfsdjhakjksfhakfhaksdhfkadhfakhfdkasfdhiuerfaeafdkjhakfdhfdadfasdfsdafadf"));
Assert.assertEquals("numbers are cool", v1.getProperty("good5property"));
Assert.assertEquals("numbers are cool", v1.getProperty("goodproperty5"));
Assert.assertEquals("one letter is ok", v1.getProperty("a"));
}
Aggregations