Search in sources :

Example 91 with TinkerGraph

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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 92 with TinkerGraph

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()));
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 93 with TinkerGraph

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", ""));
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 94 with TinkerGraph

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", ""));
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 95 with TinkerGraph

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"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4