Search in sources :

Example 1 with OrientVertex

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

the class AbstractShardingScenarioTest method loadVertex.

protected OrientVertex loadVertex(OrientBaseGraph graph, String shardName, int serverId, int threadId, int i) {
    List<OrientVertex> result = null;
    try {
        final String uniqueId = shardName + "-s" + serverId + "-t" + threadId + "-v" + i;
        Iterable<Vertex> it = graph.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
        result = new LinkedList<OrientVertex>();
        for (Vertex v : it) {
            result.add((OrientVertex) v);
        }
        if (result.size() == 0)
            fail("No record found with name = '" + uniqueId + "'!");
        else if (result.size() > 1)
            fail(result.size() + " records found with name = '" + uniqueId + "'!");
        if (result.size() > 0)
            return result.get(0);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Error in loadVertex(): " + e.toString());
    }
    return null;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) ODistributedException(com.orientechnologies.orient.server.distributed.ODistributedException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException)

Example 2 with OrientVertex

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

the class ServerClusterAsyncGraphTest method executeTest.

@Override
protected void executeTest() throws Exception {
    {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            g.createVertexType("Post");
            g.createVertexType("User");
            g.createEdgeType("Own");
            g.addVertex("class:User");
            g.command(new OCommandSQL("insert into Post (content, timestamp) values('test', 1)")).execute();
        } finally {
            g.shutdown();
        }
    }
    // CHECK VERTEX CREATION ON ALL THE SERVERS
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g2 = factory2.getNoTx();
        try {
            Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Post")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            Assert.assertNotNull(result.iterator().next());
        } finally {
            g2.shutdown();
        }
    }
    {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            g.command(new OCommandSQL("create edge Own from (select from User) to (select from Post)").onAsyncReplicationError(new OAsyncReplicationError() {

                @Override
                public ACTION onAsyncReplicationError(Throwable iException, int iRetry) {
                    return iException instanceof ONeedRetryException && iRetry <= 3 ? ACTION.RETRY : ACTION.IGNORE;
                }
            })).execute();
        } finally {
            g.shutdown();
        }
    }
    Thread.sleep(1000);
    // CHECK VERTEX CREATION ON ALL THE SERVERS
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g2 = factory2.getNoTx();
        try {
            Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Own")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            Assert.assertNotNull(result.iterator().next());
            result = g2.command(new OCommandSQL("select from Post")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            final OrientVertex v = result.iterator().next();
            Assert.assertNotNull(v);
            final Iterable<Edge> inEdges = v.getEdges(Direction.IN);
            Assert.assertTrue(inEdges.iterator().hasNext());
            Assert.assertNotNull(inEdges.iterator().next());
            result = g2.command(new OCommandSQL("select from User")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            final OrientVertex v2 = result.iterator().next();
            Assert.assertNotNull(v2);
            final Iterable<Edge> outEdges = v2.getEdges(Direction.OUT);
            Assert.assertTrue(outEdges.iterator().hasNext());
            Assert.assertNotNull(outEdges.iterator().next());
        } finally {
            g2.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAsyncReplicationError(com.orientechnologies.orient.core.replication.OAsyncReplicationError) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Edge(com.tinkerpop.blueprints.Edge)

Example 3 with OrientVertex

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

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

Example 5 with OrientVertex

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

the class TestAsyncReplMode2ServersAddEdge method dbClient2.

protected void dbClient2() {
    sleep(500);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL2());
        try {
            sleep(500);
            OrientVertex parentV1 = graph.getVertex(parentV1Id);
            assertEquals(NUM_OF_LOOP_ITERATIONS + 1, parentV1.getRecord().getVersion());
        } 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

OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)155 Test (org.junit.Test)73 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)42 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)40 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)37 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)35 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)26 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)25 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)25 Vertex (com.tinkerpop.blueprints.Vertex)24 HashMap (java.util.HashMap)20 OBasicCommandContext (com.orientechnologies.orient.core.command.OBasicCommandContext)13 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)13 Edge (com.tinkerpop.blueprints.Edge)12 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 GraphNoTxAbstractTest (com.orientechnologies.orient.graph.GraphNoTxAbstractTest)9 ORID (com.orientechnologies.orient.core.id.ORID)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 GraphTxAbstractTest (com.orientechnologies.orient.graph.GraphTxAbstractTest)7