Search in sources :

Example 46 with OrientGraph

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

the class TestReplicationVersionIncrementedByOne method dbClient1.

protected void dbClient1() {
    OrientBaseGraph graph = new OrientGraph(getLocalURL());
    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());
        v1.addEdge("edgetype", v2);
        graph.commit();
        assertEquals(2, ((OrientVertex) v1).getRecord().getVersion());
        assertEquals(2, ((OrientVertex) v2).getRecord().getVersion());
    } 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)

Example 47 with OrientGraph

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

the class TestAsyncReplMode method dbClient1.

protected void dbClient1() {
    sleep(1000);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL());
        try {
            // Create 2 parent vertices.
            OrientVertex parentV1 = graph.addVertex("vertextype1", (String) null);
            graph.commit();
            assertEquals(1, parentV1.getRecord().getVersion());
            parentV1Id = parentV1.getId();
            OrientVertex parentV2 = graph.addVertex("vertextype2", (String) null);
            graph.commit();
            assertEquals(1, parentV2.getRecord().getVersion());
            parentV2Id = parentV2.getId();
            // Create vertices.
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                pause();
                if (exceptionInThread != null)
                    break;
                //          sleep(500);
                OrientVertex vertex = graph.addVertex("vertextype3", (String) null);
                graph.commit();
                assertEquals(1, vertex.getRecord().getVersion());
                vertex.setProperty("num", i);
                graph.commit();
                assertEquals(2, vertex.getRecord().getVersion());
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV1.addEdge("edgetype1", vertex);
                        graph.commit();
                        assertNotNull(parentV1.getProperty("cnt"));
                        boolean edge1Exists = false;
                        for (Edge e : parentV1.getEdges(Direction.OUT, "edgetype1")) {
                            if (e.getVertex(Direction.IN).equals(vertex)) {
                                edge1Exists = true;
                                break;
                            }
                        }
                        assertTrue(edge1Exists);
                        boolean edge2Exists = false;
                        for (Edge e : vertex.getEdges(Direction.IN, "edgetype1")) {
                            if (e.getVertex(Direction.OUT).equals(parentV1)) {
                                edge2Exists = true;
                                break;
                            }
                        }
                        assertTrue(edge2Exists);
                        assertNotNull(vertex.getProperty("num"));
                        break;
                    } catch (OConcurrentModificationException c) {
                        System.out.println("***********ROLLBACK***************");
                        graph.rollback();
                        parentV1.reload();
                        vertex.reload();
                    }
                }
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV2.addEdge("edgetype2", vertex);
                        graph.commit();
                        assertNotNull(parentV2.getProperty("cnt"));
                        boolean edge1Exists = false;
                        for (Edge e : parentV2.getEdges(Direction.OUT, "edgetype2")) {
                            if (e.getVertex(Direction.IN).equals(vertex)) {
                                edge1Exists = true;
                                break;
                            }
                        }
                        assertTrue(edge1Exists);
                        boolean edge2Exists = false;
                        for (Edge e : vertex.getEdges(Direction.IN, "edgetype2")) {
                            if (e.getVertex(Direction.OUT).equals(parentV2)) {
                                edge2Exists = true;
                                break;
                            }
                        }
                        assertTrue(edge2Exists);
                        assertNotNull(vertex.getProperty("num"));
                        break;
                    } catch (OConcurrentModificationException c) {
                        System.out.println("***********ROLLBACK***************");
                        graph.rollback();
                        parentV2.reload();
                        vertex.reload();
                    }
                }
            }
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : 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) Edge(com.tinkerpop.blueprints.Edge)

Example 48 with OrientGraph

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

the class TestAsyncReplMode2Servers method dbClient1.

protected void dbClient1() {
    OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getRemoteURL());
        try {
            OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
            graph.commit();
            assertEquals(1, parentV1.getRecord().getVersion());
            parentV1Id = parentV1.getId();
            OrientVertex parentV2 = graph.addVertex("vertextype", (String) null);
            graph.commit();
            assertEquals(1, parentV2.getRecord().getVersion());
            parentV2Id = parentV2.getId();
            int countPropValue = 0;
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                pause();
                if (exceptionInThread != null)
                    break;
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV1.setProperty(CNT_PROP_NAME, ++countPropValue);
                        graph.commit();
                        System.out.println("Committing parentV1" + parentV1.getRecord() + "...");
                        break;
                    } catch (OConcurrentModificationException c) {
                        graph.rollback();
                        parentV1.reload();
                    }
                }
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV2.setProperty(CNT_PROP_NAME, countPropValue);
                        graph.commit();
                        System.out.println("Committing parentV2" + parentV2.getRecord() + "...");
                        break;
                    } catch (OConcurrentModificationException c) {
                        graph.rollback();
                        parentV2.reload();
                    }
                }
            }
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : 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)

Example 49 with OrientGraph

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

the class TestAsyncReplMode2Servers2OpsCommitConcurrent method dbClient1.

protected void dbClient1() {
    // OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
    OrientBaseGraph graph = new OrientGraph(getLocalURL());
    OrientVertex vertex1 = graph.addVertex("vertextype", (String) null);
    graph.commit();
    graph.shutdown();
    vertex1Id = vertex1.getIdentity();
    exec("client1");
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 50 with OrientGraph

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

the class TestAsyncReplMode2Servers2OpsCommitConcurrent method exec.

protected void exec(final String iClient) {
    counter.countDown();
    try {
        counter.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    OrientBaseGraph graph = new OrientGraph(getLocalURL());
    OrientVertex vertex1 = graph.getVertex(vertex1Id);
    try {
        int i = 0;
        for (; i < TOTAL; ++i) {
            for (int retry = 0; retry < 20; ++retry) {
                try {
                    OrientVertex vertex2 = graph.addVertex("vertextype", (String) null);
                    vertex1.addEdge("edgetype", vertex2);
                    graph.commit();
                    System.out.println(iClient + " - successfully committed version: " + vertex1.getRecord().getVersion() + " retry: " + retry);
                    break;
                } catch (ONeedRetryException e) {
                    System.out.println(iClient + " - caught conflict, reloading vertex. v=" + vertex1.getRecord().getVersion() + " retry: " + retry);
                    graph.rollback();
                    vertex1.reload();
                }
            }
        }
        // STATISTICALLY HERE AT LEAST ONE CONFLICT HAS BEEN RECEIVED
        vertex1.reload();
        Assert.assertTrue(vertex1.getRecord().getVersion() > TOTAL + 1);
        Assert.assertEquals(TOTAL, i);
    } catch (Throwable e) {
        if (exceptionInThread == null)
            exceptionInThread = e;
    } finally {
        System.out.println("Shutting down");
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

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