Search in sources :

Example 66 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestGraphRecovering method testRecoverBrokenGraphAllEdges.

@Test
public void testRecoverBrokenGraphAllEdges() {
    final OrientBaseGraph g = new OrientGraphNoTx("memory:testRecoverBrokenGraphAllEdges");
    try {
        init(g, false);
        for (Edge e : g.getEdges()) {
            ((OrientEdge) e).getRecord().removeField("out");
            ((OrientEdge) e).getRecord().save();
        }
        final TestListener eventListener = new TestListener();
        new OGraphRepair().setEventListener(eventListener).repair(g, null, null);
        Assert.assertEquals(eventListener.scannedEdges, 3);
        Assert.assertEquals(eventListener.removedEdges, 3);
        Assert.assertEquals(eventListener.scannedVertices, 3);
        Assert.assertEquals(eventListener.scannedLinks, 6);
        Assert.assertEquals(eventListener.removedLinks, 6);
        Assert.assertEquals(eventListener.repairedVertices, 3);
    } finally {
        g.shutdown();
    }
}
Also used : OGraphRepair(com.tinkerpop.blueprints.impls.orient.OGraphRepair) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Edge(com.tinkerpop.blueprints.Edge) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 67 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestGraphRecovering method testRecoverBrokenGraphLinksInVerticesNonLW.

@Test
public void testRecoverBrokenGraphLinksInVerticesNonLW() {
    final OrientBaseGraph g = new OrientGraphNoTx("memory:testRecoverBrokenGraphLinksInVerticesNonLW");
    try {
        init(g, false);
        for (Vertex v : g.getVertices()) {
            for (String f : ((OrientVertex) v).getRecord().fieldNames()) {
                if (f.startsWith("out_"))
                    ((OrientVertex) v).getRecord().removeField(f);
            }
        }
        final TestListener eventListener = new TestListener();
        new OGraphRepair().setEventListener(eventListener).repair(g, null, null);
        Assert.assertEquals(eventListener.scannedEdges, 3);
        Assert.assertEquals(eventListener.removedEdges, 3);
        Assert.assertEquals(eventListener.scannedVertices, 3);
        Assert.assertEquals(eventListener.scannedLinks, 3);
        Assert.assertEquals(eventListener.removedLinks, 3);
        Assert.assertEquals(eventListener.repairedVertices, 3);
    } finally {
        g.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OGraphRepair(com.tinkerpop.blueprints.impls.orient.OGraphRepair) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.junit.Test)

Example 68 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestGraphRecovering method testRecoverBrokenGraphLinksInVerticesLW.

@Test
public void testRecoverBrokenGraphLinksInVerticesLW() {
    final OrientBaseGraph g = new OrientGraphNoTx("memory:testRecoverBrokenGraphLinksInVerticesLW");
    try {
        init(g, true);
        for (Vertex v : g.getVertices()) {
            final ODocument record = ((OrientVertex) v).getRecord();
            int key = v.getProperty("key");
            if (key == 0)
                record.field("out_", record);
            else if (key == 1)
                record.field("in_E1", new ORecordId(100, 200));
            else if (key == 2)
                record.field("out_E2", record);
            record.save();
        }
        final TestListener eventListener = new TestListener();
        new OGraphRepair().setEventListener(eventListener).repair(g, null, null);
        Assert.assertEquals(eventListener.scannedEdges, 0);
        Assert.assertEquals(eventListener.removedEdges, 0);
        Assert.assertEquals(eventListener.scannedVertices, 3);
        Assert.assertEquals(eventListener.scannedLinks, 7);
        Assert.assertEquals(eventListener.removedLinks, 5);
        Assert.assertEquals(eventListener.repairedVertices, 3);
    } finally {
        g.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OGraphRepair(com.tinkerpop.blueprints.impls.orient.OGraphRepair) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 69 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class LuceneGraphTXTest method graphTxTest.

@Test
public void graphTxTest() throws Exception {
    OrientGraph graph = new OrientGraph("memory:graphTx");
    try {
        graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {

            @Override
            public Object call(OrientBaseGraph graph) {
                OrientVertexType city = graph.createVertexType("City");
                city.createProperty("name", OType.STRING);
                graph.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();
                return null;
            }
        });
        OrientVertex v = graph.addVertex("class:City", "name", "London");
        v.save();
        Collection results = graph.getRawGraph().command(new OCommandSQL("select from City where name lucene 'London'")).execute();
        Assert.assertEquals(results.size(), 1);
        v.setProperty("name", "Berlin");
        v.save();
        results = graph.getRawGraph().command(new OCommandSQL("select from City where name lucene 'Berlin'")).execute();
        Assert.assertEquals(results.size(), 1);
        results = graph.getRawGraph().command(new OCommandSQL("select from City where name lucene 'London'")).execute();
        Assert.assertEquals(results.size(), 0);
        graph.commit();
        // Assert After Commit
        results = graph.getRawGraph().command(new OCommandSQL("select from City where name lucene 'Berlin'")).execute();
        Assert.assertEquals(results.size(), 1);
        results = graph.getRawGraph().command(new OCommandSQL("select from City where name lucene 'London'")).execute();
        Assert.assertEquals(results.size(), 0);
    } finally {
        graph.drop();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) Collection(java.util.Collection) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.junit.Test)

Example 70 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class BlueprintsConcurrentGraphChangesTestNoTx method assertCreatedGraph.

private void assertCreatedGraph() {
    OrientBaseGraph graph = getGraph();
    graph.setUseLightweightEdges(false);
    Assert.assertEquals(VERTEXES_COUNT, graph.countVertices("TestVertex"));
    Assert.assertEquals(EDGES_COUNT, graph.countEdges("TestEdge"));
    for (TestVertex vertex : vertexes) {
        Iterable<Vertex> vertexes = graph.command(new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + vertex.uuid + "'")).execute();
        Assert.assertTrue(vertexes.iterator().hasNext());
    }
    for (TestEdge edge : edges) {
        Iterable<Edge> edges = graph.command(new OSQLSynchQuery<Edge>("select from TestEdge where uuid = '" + edge.uuid + "'")).execute();
        Assert.assertTrue(edges.iterator().hasNext());
    }
    for (TestVertex vertex : vertexes) {
        Iterable<Vertex> vertexes = graph.command(new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + vertex.uuid + "'")).execute();
        Assert.assertTrue(vertexes.iterator().hasNext());
        Vertex gVertex = vertexes.iterator().next();
        Iterable<Edge> outEdges = gVertex.getEdges(Direction.OUT);
        Iterator<Edge> outGEdgesIterator = outEdges.iterator();
        int counter = 0;
        while (outGEdgesIterator.hasNext()) {
            counter++;
            Edge gEdge = outGEdgesIterator.next();
            TestEdge testEdge = new TestEdge();
            testEdge.uuid = gEdge.getProperty("uuid");
            Assert.assertTrue(vertex.outEdges.contains(testEdge));
        }
        Assert.assertEquals(vertex.outEdges.size(), counter);
        Iterable<Edge> inEdges = gVertex.getEdges(Direction.IN);
        Iterator<Edge> inGEdgesIterator = inEdges.iterator();
        counter = 0;
        while (inGEdgesIterator.hasNext()) {
            counter++;
            Edge gEdge = inGEdgesIterator.next();
            TestEdge testEdge = new TestEdge();
            testEdge.uuid = gEdge.getProperty("uuid");
            Assert.assertTrue(vertex.inEdges.contains(testEdge));
        }
        Assert.assertEquals(vertex.inEdges.size(), counter);
    }
    assertGraphIsConsistent(graph);
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)75 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)40 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)21 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)15 Vertex (com.tinkerpop.blueprints.Vertex)13 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)11 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 Edge (com.tinkerpop.blueprints.Edge)8 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)8 Test (org.junit.Test)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 OGraphRepair (com.tinkerpop.blueprints.impls.orient.OGraphRepair)5 ArrayList (java.util.ArrayList)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)4 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)4