Search in sources :

Example 71 with OrientGraph

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

the class TestGraphIntentMassiveInsert method testIntent.

@Test
public void testIntent() {
    final OrientGraph graph = new OrientGraph("memory:default", false);
    graph.setUseLightweightEdges(true);
    graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
    final OrientVertexType c1 = graph.createVertexType("C1");
    c1.createProperty("p1", OType.INTEGER);
    graph.createEdgeType("parent");
    graph.begin();
    final OrientVertex first = graph.addVertex("class:C1");
    first.setProperty("p1", -1);
    for (int i = 0; i < 10; i++) {
        final OrientVertex v = graph.addVertex("class:C1");
        v.setProperty("p1", i);
        first.addEdge("parent", v);
        //this search fills _source
        graph.command(new OSQLSynchQuery("SELECT from V where p1='" + i + "'")).execute();
    }
    graph.commit();
    //here NPE will be thrown
    final Iterable<Edge> edges = first.getEdges(Direction.BOTH);
    Iterator<Edge> ter = edges.iterator();
    for (int i = 0; i < 10; i++) {
        assertTrue(ter.hasNext());
        assertEquals(ter.next().getVertex(Direction.IN).getProperty("p1"), i);
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Edge(com.tinkerpop.blueprints.Edge) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) Test(org.junit.Test)

Example 72 with OrientGraph

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

the class ConcurrentTxTest method testMultithreadedProvokeOConcurrentModificationException2.

@Test(expected = OConcurrentModificationException.class)
public void testMultithreadedProvokeOConcurrentModificationException2() throws Throwable {
    // Create vertex
    OrientGraph mainTx = graphFactory.getTx();
    mainTx.begin();
    OrientVertex vertex = mainTx.addVertex(null, PROPERTY_NAME, "init");
    mainTx.commit();
    mainTx.shutdown();
    int threadCount = 200;
    final Object recordId = vertex.getId();
    final CyclicBarrier barrier = new CyclicBarrier(threadCount);
    List<Thread> threads = new ArrayList<Thread>();
    final AtomicReference<Throwable> t = new AtomicReference<Throwable>(null);
    // Spawn two threads and modify the vertex
    for (int i = 0; i < threadCount; i++) {
        final int threadNo = i;
        Thread thread = run(new Runnable() {

            @Override
            public void run() {
                OrientGraph tx = graphFactory.getTx();
                try {
                    tx.begin();
                    OrientVertex secondVertexHandle = tx.getVertex(recordId);
                    secondVertexHandle.setProperty(PROPERTY_NAME, threadNo);
                    waitFor(barrier);
                    tx.commit();
                } catch (Exception e) {
                    t.set(e);
                } finally {
                    tx.shutdown();
                }
            }
        });
        threads.add(thread);
    }
    // Wait for threads
    for (Thread thread : threads) {
        thread.join();
    }
    if (t.get() != null) {
        throw t.get();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 73 with OrientGraph

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

the class EdgeBug method setupClasses.

private void setupClasses() {
    OrientGraph db = new OrientGraph("memory:temp", "admin", "admin");
    db.createVertexType("rawCategory");
    db.createVertexType("rawField");
    db.commit();
    db.shutdown();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph)

Example 74 with OrientGraph

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

the class EdgeBug method populateDatabase.

private void populateDatabase() {
    OrientGraph db = new OrientGraph("memory:temp", "admin", "admin");
    aVertex = db.addVertex("class:rawCategory");
    aVertex.setProperty("name", "a");
    bVertex = db.addVertex("class:rawCategory");
    bVertex.setProperty("name", "b");
    asubVertex = db.addVertex("class:rawField");
    asubVertex.setProperty("name", "asub");
    bsubVertex = db.addVertex("class:rawField");
    bsubVertex.setProperty("name", "bsub");
    asubVertex.addEdge("hasParent", aVertex);
    bsubVertex.addEdge("hasParent", bVertex);
    db.commit();
    db.shutdown();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph)

Example 75 with OrientGraph

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

the class EdgeIndexingTest method testOutLinksUniqueness.

/**
   * Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
   */
@Test
public void testOutLinksUniqueness() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url);
    graph.drop();
    graph = new OrientGraph(url);
    graph.setUseLightweightEdges(true);
    graph.createEdgeType("link");
    graph.setAutoStartTx(false);
    OClass outVertexType = graph.createVertexType("IndexedOutVertex");
    outVertexType.createProperty("out_link", OType.LINKBAG);
    outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");
    graph.setAutoStartTx(true);
    Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");
    Vertex vertexInOne = graph.addVertex(null);
    Vertex vertexInTwo = graph.addVertex(null);
    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    graph.commit();
    Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
    vertexOutTwo.addEdge("link", vertexInTwo);
    try {
        graph.commit();
        // in vertex can be linked by only one out vertex.
        Assert.fail();
    } catch (ORecordDuplicatedException e) {
    }
    graph.drop();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.junit.Test)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)94 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)43 Test (org.junit.Test)33 Vertex (com.tinkerpop.blueprints.Vertex)22 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)18 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)12 Edge (com.tinkerpop.blueprints.Edge)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)7 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)7 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)6 Test (org.testng.annotations.Test)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4