Search in sources :

Example 31 with OrientVertex

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

the class OSQLFunctionDijkstraTest method testExecute.

@Test
public void testExecute() throws Exception {
    final List<OrientVertex> result = functionDijkstra.execute(null, null, null, new Object[] { v1, v4, "'weight'" }, new OBasicCommandContext());
    assertEquals(4, result.size());
    assertEquals(v1, result.get(0));
    assertEquals(v2, result.get(1));
    assertEquals(v3, result.get(2));
    assertEquals(v4, result.get(3));
}
Also used : OBasicCommandContext(com.orientechnologies.orient.core.command.OBasicCommandContext) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 32 with OrientVertex

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

the class ConcurrentSQLBatchUpdateSuperNodeTest method concurrentOptimisticUpdates.

@Test(enabled = true)
public void concurrentOptimisticUpdates() throws Exception {
    //    System.out.println("Started Test OPTIMISTIC Batch Update against SuperNode");
    counter.set(0);
    startedOn = System.currentTimeMillis();
    OrientBaseGraph graphPool = new OrientGraph(url);
    OrientVertex superNode = graphPool.addVertex(null, "optimisticSuperNode", true);
    graphPool.commit();
    OptimisticThread[] ops = new OptimisticThread[THREADS];
    for (int i = 0; i < THREADS; ++i) ops[i] = new OptimisticThread(url, superNode, i, "thread" + i);
    Thread[] threads = new Thread[THREADS];
    for (int i = 0; i < THREADS; ++i) threads[i] = new Thread(ops[i], "ConcurrentSQLBatchUpdateSuperNodeTest-optimistic" + i);
    for (int i = 0; i < THREADS; ++i) threads[i].start();
    for (int i = 0; i < THREADS; ++i) {
        threads[i].join();
    //      System.out.println("Thread " + i + " completed");
    }
    //    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Optimistic Done! Total updates executed in parallel: "
    //        + counter.get() + " total retries: " + totalRetries.get() + " average retries: "
    //        + ((float) totalRetries.get() / (float) counter.get()));
    Assert.assertEquals(counter.get(), OPTIMISTIC_CYCLES * THREADS);
    OrientVertex loadedSuperNode = graphPool.getVertex(superNode.getIdentity());
    for (int i = 0; i < THREADS; ++i) Assert.assertEquals(loadedSuperNode.countEdges(Direction.IN), OPTIMISTIC_CYCLES * THREADS);
    graphPool.shutdown();
//    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Optimistic Test completed in "
//        + (System.currentTimeMillis() - startedOn));
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.testng.annotations.Test)

Example 33 with OrientVertex

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

the class ConcurrentSQLBatchUpdateSuperNodeTest method concurrentPessimisticUpdates.

@Test(enabled = false)
public void concurrentPessimisticUpdates() throws Exception {
    //    System.out.println("Started Test PESSIMISTIC Batch Update against SuperNode");
    counter.set(0);
    startedOn = System.currentTimeMillis();
    OrientBaseGraph graphPool = new OrientGraph(url);
    graphPool.setThreadMode(OrientBaseGraph.THREAD_MODE.ALWAYS_AUTOSET);
    OrientVertex superNode = graphPool.addVertex(null, "pessimisticSuperNode", true);
    graphPool.commit();
    PessimisticThread[] ops = new PessimisticThread[THREADS];
    for (int i = 0; i < THREADS; ++i) ops[i] = new PessimisticThread(url, superNode, i, "thread" + i);
    Thread[] threads = new Thread[THREADS];
    for (int i = 0; i < THREADS; ++i) threads[i] = new Thread(ops[i], "ConcurrentSQLBatchUpdateSuperNodeTest-pessimistic" + i);
    for (int i = 0; i < THREADS; ++i) threads[i].start();
    for (int i = 0; i < THREADS; ++i) {
        threads[i].join();
    //      System.out.println("Thread " + i + " completed");
    }
    //    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Pessimistic Done! Total updates executed in parallel: "
    //        + counter.get() + " average retries: " + ((float) totalRetries.get() / (float) counter.get()));
    Assert.assertEquals(counter.get(), PESSIMISTIC_CYCLES * THREADS);
    OrientVertex loadedSuperNode = graphPool.getVertex(superNode.getIdentity());
    for (int i = 0; i < THREADS; ++i) Assert.assertEquals(loadedSuperNode.countEdges(Direction.IN), PESSIMISTIC_CYCLES * THREADS);
    graphPool.shutdown();
// System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Pessimistic Test completed in "
// + (System.currentTimeMillis() - startedOn));
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.testng.annotations.Test)

Example 34 with OrientVertex

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

the class DatabaseConflictStategyTest method startThread.

private Thread startThread(final int version, final long timeout, final String key) {
    Thread th = new Thread() {

        @Override
        public void run() {
            OrientVertex vtx1 = null;
            OrientGraph graph = getGraphFactory().getTx();
            Iterable<Vertex> vtxs = graph.getVertices();
            for (Vertex vtx : vtxs) {
                vtx1 = (OrientVertex) vtx;
            }
            try {
                Thread.sleep(timeout);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            vtx1.setProperty(key, "key-" + version);
            graph.commit();
            printVertex(version + "", vtx1);
            graph.shutdown();
        }
    };
    th.start();
    return th;
}
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)

Example 35 with OrientVertex

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

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