Search in sources :

Example 41 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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 42 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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 43 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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 44 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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)

Example 45 with OrientBaseGraph

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

the class TestAsyncReplMode2ServersAddEdge method dbClient1.

protected void dbClient1() {
    OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL());
        try {
            OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
            graph.commit();
            assertEquals(1, parentV1.getRecord().getVersion());
            parentV1Id = parentV1.getId();
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                Vertex childV = graph.addVertex("vertextype", (String) null);
                graph.commit();
                assertEquals(1, ((OrientVertex) childV).getRecord().getVersion());
                parentV1.addEdge("edgetype", childV);
                graph.commit();
                OLogManager.instance().error(this, "parentV1 %s v%d should be v%d", parentV1.getIdentity(), parentV1.getRecord().getVersion(), i + 2);
                assertEquals(i + 2, ((OrientVertex) parentV1).getRecord().getVersion());
                assertEquals(2, ((OrientVertex) childV).getRecord().getVersion());
            }
            pause();
        } catch (Throwable e) {
            OLogManager.instance().error(this, "Exception", e);
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
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)

Aggregations

OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)70 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)40 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)19 Vertex (com.tinkerpop.blueprints.Vertex)13 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)13 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)11 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)8 Test (org.junit.Test)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 Edge (com.tinkerpop.blueprints.Edge)7 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)5 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