Search in sources :

Example 46 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 47 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);
    final AtomicInteger conflicts = new AtomicInteger(0);
    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();
                    break;
                } catch (ONeedRetryException e) {
                    System.out.println(iClient + " - caught conflict, reloading vertex. v=" + vertex1.getRecord().getVersion() + " retry: " + retry + " conflicts so far: " + conflicts.get());
                    graph.rollback();
                    vertex1.reload();
                    conflicts.incrementAndGet();
                }
            }
        }
        // STATISTICALLY HERE AT LEAST ONE CONFLICT HAS BEEN RECEIVED
        vertex1.reload();
        Assert.assertTrue("No conflicts recorded. conflicts=" + conflicts.get(), conflicts.get() > 0);
        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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 48 with OrientBaseGraph

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

the class TestAsyncReplMode2Servers2OpsCommitConcurrent method dbClient1.

protected void dbClient1() {
    OGlobalConfiguration.DISTRIBUTED_CONCURRENT_TX_AUTORETRY_DELAY.setValue(1);
    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 49 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)

Example 50 with OrientBaseGraph

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

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