Search in sources :

Example 16 with OrientBaseGraph

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

the class DatabaseConflictStrategyAutoMergeTest method dbClient1.

private void dbClient1() {
    sleep(500);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(CLIENT_ORIENT_URL_MAIN);
        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;
                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());
                parentV1.addEdge("edgetype1", vertex);
                graph.commit();
                assertNotNull(parentV1.getProperty("cnt"), "record " + parentV1.getIdentity() + " has no 'cnt' property");
                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"));
                parentV2.addEdge("edgetype2", vertex);
                graph.commit();
                assertNotNull(parentV2.getProperty("cnt"));
                edge1Exists = false;
                for (Edge e : parentV2.getEdges(Direction.OUT, "edgetype2")) {
                    if (e.getVertex(Direction.IN).equals(vertex)) {
                        edge1Exists = true;
                        break;
                    }
                }
                assertTrue(edge1Exists);
                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"));
            }
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            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) Edge(com.tinkerpop.blueprints.Edge)

Example 17 with OrientBaseGraph

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

the class DatabaseConflictStrategyAutoMergeTest method testAutoMerge.

@Test
public void testAutoMerge() throws Throwable {
    OrientGraphFactory factory = new OrientGraphFactory(CLIENT_ORIENT_URL_MAIN);
    OrientBaseGraph graph = factory.getNoTx();
    graph.setConflictStrategy(OAutoMergeRecordConflictStrategy.NAME);
    graph.createVertexType("vertextype");
    graph.createEdgeType("edgetype");
    graph.shutdown();
    factory.close();
    Thread dbClient1 = new Thread() {

        @Override
        public void run() {
            dbClient1();
        }
    };
    dbClient1.start();
    // Start the second DB client.
    Thread dbClient2 = new Thread() {

        @Override
        public void run() {
            dbClient2();
        }
    };
    dbClient2.start();
    dbClient1.join();
    dbClient2.join();
    if (exceptionInThread != null) {
        throw exceptionInThread;
    }
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.testng.annotations.Test)

Example 18 with OrientBaseGraph

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

the class ConcurrentDistributedUpdateTest method executeTest.

@Override
public void executeTest() throws Exception {
    OrientBaseGraph orientGraph = new OrientGraphNoTx(getPlocalDatabaseURL(serverInstance.get(0)));
    OClass clazz = orientGraph.getVertexType("Test");
    if (clazz == null) {
        log("Creating vertex type - " + "Test");
        orientGraph.createVertexType("Test");
    }
    orientGraph.shutdown();
    OrientBaseGraph graph = new OrientGraphNoTx(getPlocalDatabaseURL(serverInstance.get(0)));
    for (int i = 0; i < 2; i++) {
        Vertex vertex = graph.addVertex("class:Test");
        vertex.setProperty("prop1", "v1-" + i);
        vertex.setProperty("prop2", "v2-1");
        vertex.setProperty("prop3", "v3-1");
        graph.commit();
        if ((i % 100) == 0) {
            log("Created " + i + " nodes");
        }
    }
    graph.shutdown();
    executeMultipleTest();
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 19 with OrientBaseGraph

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

the class TestAsyncReplMode method dbClient2.

protected void dbClient2() {
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getRemoteURL());
        OrientVertex parentV1 = null;
        OrientVertex parentV2 = null;
        int countPropValue = 0;
        try {
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                pause();
                if (exceptionInThread != null)
                    break;
                // Let's give it some time for asynchronous replication.
                //          sleep(500);
                countPropValue++;
                if (parentV1 == null) {
                    parentV1 = graph.getVertex(parentV1Id);
                }
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV1.setProperty("cnt", countPropValue);
                        graph.commit();
                    } catch (OConcurrentModificationException c) {
                        graph.rollback();
                        parentV1.reload();
                    }
                }
                if (parentV2 == null) {
                    parentV2 = graph.getVertex(parentV2Id);
                }
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV2.setProperty("cnt", countPropValue);
                        graph.commit();
                    } 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 20 with OrientBaseGraph

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

the class TestAsyncReplMode2Servers method dbClient2.

protected void dbClient2() {
    sleep(1000);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL2());
        try {
            OrientVertex parentV1 = graph.getVertex(parentV1Id);
            assertEquals(1, parentV1.getRecord().getVersion());
            OrientVertex parentV2 = graph.getVertex(parentV2Id);
            assertEquals(1, parentV2.getRecord().getVersion());
            int countPropValue = 0;
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                pause();
                if (exceptionInThread != null)
                    break;
                sleep(500);
                parentV1.reload();
                parentV2.reload();
                assertEquals("parentV1 (" + parentV1.getRecord() + ")", ++countPropValue, parentV1.getProperty(CNT_PROP_NAME));
                assertEquals("parentV2 (" + parentV2.getRecord() + ")", countPropValue, parentV2.getProperty(CNT_PROP_NAME));
            }
        } 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)

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