Search in sources :

Example 41 with OrientGraph

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

the class TransactionConsistencyTest method deletesWithinTransactionArentWorking.

@Test
public void deletesWithinTransactionArentWorking() throws IOException {
    OrientGraph graph = new OrientGraph(url);
    graph.setUseLightweightEdges(false);
    try {
        if (graph.getVertexType("Foo") == null)
            graph.createVertexType("Foo");
        if (graph.getVertexType("Bar") == null)
            graph.createVertexType("Bar");
        if (graph.getVertexType("Sees") == null)
            graph.createEdgeType("Sees");
        // Commenting out the transaction will result in the test succeeding.
        ODocument foo = graph.addVertex("class:Foo", "prop", "test1").getRecord();
        // Comment out these two lines and the test will succeed. The issue appears to be related to an edge
        // connecting a deleted vertex during a transaction
        ODocument bar = graph.addVertex("class:Bar", "prop", "test1").getRecord();
        ODocument sees = graph.addEdge(null, graph.getVertex(foo), graph.getVertex(bar), "Sees").getRecord();
        graph.commit();
        List<ODocument> foos = graph.getRawGraph().query(new OSQLSynchQuery("select * from Foo"));
        Assert.assertEquals(foos.size(), 1);
        graph.removeVertex(graph.getVertex(foos.get(0)));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 42 with OrientGraph

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

the class TraverseTest method init.

@BeforeClass
public void init() {
    OrientGraph graph = new OrientGraph(database);
    graph.setUseLightweightEdges(false);
    graph.createVertexType("Movie");
    graph.createVertexType("Actor");
    tomCruise = graph.addVertex("class:Actor", "name", "Tom Cruise").getRecord();
    totalElements++;
    megRyan = graph.addVertex("class:Actor", "name", "Meg Ryan").getRecord();
    totalElements++;
    nicoleKidman = graph.addVertex("class:Actor", "name", "Nicole Kidman", "attributeWithDotValue", "a.b").getRecord();
    totalElements++;
    ODocument topGun = graph.addVertex("class:Movie", "name", "Top Gun", "year", 1986).getRecord();
    totalElements++;
    ODocument missionImpossible = graph.addVertex("class:Movie", "name", "Mission: Impossible", "year", 1996).getRecord();
    totalElements++;
    ODocument youHaveGotMail = graph.addVertex("class:Movie", "name", "You've Got Mail", "year", 1998).getRecord();
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(topGun), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(megRyan), graph.getVertex(topGun), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(missionImpossible), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(megRyan), graph.getVertex(youHaveGotMail), "actorIn");
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(megRyan), "friend");
    totalElements++;
    graph.addEdge(null, graph.getVertex(tomCruise), graph.getVertex(nicoleKidman), "married").setProperty("year", 1990);
    totalElements++;
    graph.commit();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) BeforeClass(org.testng.annotations.BeforeClass)

Example 43 with OrientGraph

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

the class DistributedSuperNodeTest method onAfterExecution.

@Override
protected void onAfterExecution() {
    OrientGraph graph = factory.getTx();
    try {
        OrientVertex root = graph.getVertex(rootVertexId);
        Assert.assertEquals(((OMultiCollectionIterator) root.getEdges(Direction.OUT)).size(), count * serverInstance.size() * writerCount);
    } finally {
        graph.shutdown();
    }
    super.onAfterExecution();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 44 with OrientGraph

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

the class ConcurrentDistributedUpdateTest method createWriter.

protected Callable<Void> createWriter(final int serverId, final int threadId, final String databaseURL) {
    return new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            final String id = serverId + "." + threadId;
            boolean isRunning = true;
            final OrientBaseGraph graph = new OrientGraph(databaseURL);
            try {
                String query = "select from Test where prop2='v2-1'";
                for (int i = 0; i < 100 && isRunning; i++) {
                    if ((i % 25) == 0) {
                        log("[" + id + "] Records Processed: [" + i + "]");
                    }
                    Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
                    boolean update = true;
                    for (Vertex vtx : vtxs) {
                        if (update) {
                            update = true;
                            for (int k = 0; k < 10 && update; k++) {
                                OrientVertex vtx1 = (OrientVertex) vtx;
                                try {
                                    vtx1.setProperty("prop5", "prop55");
                                    graph.commit();
                                    // log("[" + id + "/" + i + "/" + k + "] OK!\n");
                                    break;
                                } catch (OConcurrentModificationException ex) {
                                    vtx1.reload();
                                } catch (ODistributedRecordLockedException ex) {
                                    log("[" + id + "/" + i + "/" + k + "] Distributed lock Exception " + ex + " for vertex " + vtx1 + " \n");
                                    //                    ex.printStackTrace();
                                    update = false;
                                    //                    isRunning = false;
                                    break;
                                } catch (Exception ex) {
                                    log("[" + id + "/" + i + "/" + k + "] Exception " + ex + " for vertex " + vtx1 + "\n\n");
                                    ex.printStackTrace();
                                    isRunning = false;
                                    break;
                                }
                            }
                            if (!isRunning)
                                break;
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
                ex.printStackTrace();
            } finally {
                log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
                graph.shutdown();
                runningWriters.countDown();
            }
            Assert.assertTrue(isRunning);
            return null;
        }
    };
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) ODistributedRecordLockedException(com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Callable(java.util.concurrent.Callable) ODistributedRecordLockedException(com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL)

Example 45 with OrientGraph

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

the class TestRemoteDelete method dbClient1.

@Override
protected void dbClient1() {
    OrientBaseGraph graph = new OrientGraph(getRemoteURL());
    try {
        Vertex v1 = graph.addVertex("vertextype", (String) null);
        graph.commit();
        assertEquals(1, ((OrientVertex) v1).getRecord().getVersion());
        Vertex v2 = graph.addVertex("vertextype", (String) null);
        graph.commit();
        assertEquals(1, ((OrientVertex) v2).getRecord().getVersion());
        Edge e = v1.addEdge("edgetype", v2);
        graph.commit();
        assertEquals(2, ((OrientVertex) v1).getRecord().getVersion());
        assertEquals(2, ((OrientVertex) v2).getRecord().getVersion());
        e.remove();
        graph.commit();
        assertFalse(((OrientVertex) v1).getVertices(Direction.OUT, "edgetype").iterator().hasNext());
        assertFalse(((OrientVertex) v2).getVertices(Direction.IN, "edgetype").iterator().hasNext());
    } catch (Throwable e) {
        if (exceptionInThread == null) {
            exceptionInThread = e;
        }
    } finally {
        OLogManager.instance().info(this, "Shutting down");
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)94 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)43 Test (org.junit.Test)33 Vertex (com.tinkerpop.blueprints.Vertex)22 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)18 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)12 Edge (com.tinkerpop.blueprints.Edge)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)7 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)7 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)6 Test (org.testng.annotations.Test)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4