Search in sources :

Example 1 with IgnoreIdTinkerGraph

use of com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph in project blueprints by tinkerpop.

the class BatchGraphTest method loadingTest.

public void loadingTest(int total, int bufferSize, VertexIDType type, LoadingFactory ids) {
    final VertexEdgeCounter counter = new VertexEdgeCounter();
    MockTransactionalGraph tgraph = null;
    if (ignoreIDs) {
        tgraph = new MockTransactionalGraph(new IgnoreIdTinkerGraph());
    } else {
        tgraph = new MockTransactionalGraph(new TinkerGraph());
    }
    BLGraph graph = new BLGraph(tgraph, counter, ids);
    BatchGraph<BLGraph> loader = new BatchGraph<BLGraph>(graph, type, bufferSize);
    if (assignKeys) {
        loader.setVertexIdKey(vertexIDKey);
        loader.setEdgeIdKey(edgeIDKey);
    }
    // Create a chain
    int chainLength = total;
    Vertex previous = null;
    for (int i = 0; i <= chainLength; i++) {
        Vertex next = loader.addVertex(ids.getVertexID(i));
        next.setProperty(UID, i);
        counter.numVertices++;
        counter.totalVertices++;
        if (previous != null) {
            Edge e = loader.addEdge(ids.getEdgeID(i), loader.getVertex(previous.getId()), loader.getVertex(next.getId()), "next");
            e.setProperty(UID, i);
            counter.numEdges++;
        }
        previous = next;
    }
    loader.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
    assertTrue(tgraph.allSuccessful());
    loader.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with IgnoreIdTinkerGraph

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

Aggregations

Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)2 MockTransactionalGraph (com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph)2 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)2 Graph (com.tinkerpop.blueprints.Graph)1 TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)1