Search in sources :

Example 66 with OrientGraph

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

the class DirtyManagerGraph method testLoopOfNewTree.

@Test
public void testLoopOfNewTree() {
    OrientGraph graph = new OrientGraph("memory:" + DirtyManagerGraph.class.getSimpleName());
    Object prev = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValue();
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
    try {
        graph.createEdgeType("next");
        OrientVertex vertex = graph.addVertex(null);
        OrientVertex vertex1 = graph.addVertex(null);
        OrientVertex vertex2 = graph.addVertex(null);
        OrientVertex vertex3 = graph.addVertex(null);
        OrientEdge edge1 = (OrientEdge) vertex.addEdge("next", vertex1);
        OrientEdge edge2 = (OrientEdge) vertex1.addEdge("next", vertex2);
        OrientEdge edge3 = (OrientEdge) vertex2.addEdge("next", vertex3);
        OrientEdge edge4 = (OrientEdge) vertex3.addEdge("next", vertex);
        ODocument rec = vertex.getRecord();
        ODirtyManager manager = ORecordInternal.getDirtyManager(rec);
        List<OIdentifiable> pointed = manager.getPointed(vertex.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge1.getRecord()));
        assertTrue(pointed.contains(edge4.getRecord()));
        pointed = manager.getPointed(vertex1.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge1.getRecord()));
        assertTrue(pointed.contains(edge2.getRecord()));
        pointed = manager.getPointed(vertex2.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge2.getRecord()));
        assertTrue(pointed.contains(edge3.getRecord()));
        pointed = manager.getPointed(vertex3.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(edge3.getRecord()));
        assertTrue(pointed.contains(edge4.getRecord()));
        pointed = manager.getPointed(edge1.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex.getRecord()));
        assertTrue(pointed.contains(vertex1.getRecord()));
        pointed = manager.getPointed(edge2.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex1.getRecord()));
        assertTrue(pointed.contains(vertex2.getRecord()));
        pointed = manager.getPointed(edge3.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex2.getRecord()));
        assertTrue(pointed.contains(vertex3.getRecord()));
        pointed = manager.getPointed(edge4.getRecord());
        assertEquals(2, pointed.size());
        assertTrue(pointed.contains(vertex3.getRecord()));
        assertTrue(pointed.contains(vertex.getRecord()));
    } finally {
        OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(prev);
        graph.drop();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 67 with OrientGraph

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

the class GraphNonBlockingQueryRemote method testNonBlockingClose.

@Test
public void testNonBlockingClose() throws ExecutionException, InterruptedException {
    OrientGraph database = new OrientGraph("remote:localhost:3064/" + GraphNonBlockingQueryRemote.class.getSimpleName());
    database.createVertexType("Prod").createProperty("something", OType.STRING);
    for (int i = 0; i < 21; i++) {
        OrientVertex vertex = database.addVertex("class:Prod");
        vertex.setProperty("something", "value");
        vertex.save();
    }
    database.commit();
    final CountDownLatch ended = new CountDownLatch(21);
    try {
        OSQLNonBlockingQuery<Object> test = new OSQLNonBlockingQuery<Object>("select * from Prod ", new OCommandResultListener() {

            int resultCount = 0;

            @Override
            public boolean result(Object iRecord) {
                resultCount++;
                ODocument odoc = ((ODocument) iRecord);
                for (String name : odoc.fieldNames()) {
                    // <----------- PROBLEM
                    assertEquals("something", name);
                }
                ended.countDown();
                return resultCount > 20 ? false : true;
            }

            @Override
            public void end() {
                ended.countDown();
            }

            @Override
            public Object getResult() {
                return resultCount;
            }
        });
        database.command(test).execute();
        assertTrue(ended.await(10, TimeUnit.SECONDS));
    } finally {
        database.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLNonBlockingQuery(com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) CountDownLatch(java.util.concurrent.CountDownLatch) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OrientGraphRemoteTest(com.tinkerpop.blueprints.impls.orient.OrientGraphRemoteTest) Test(org.junit.Test)

Example 68 with OrientGraph

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

the class ODatabaseFailDueCloseTest method setup.

@BeforeClass
public static void setup() {
    createGraph();
    pool = new OrientGraphFactory("memory:temp", "admin", "admin").setupPool(1, 10);
    OrientGraph graph = pool.getTx();
    try {
        fillTheGraph(graph);
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) BeforeClass(org.junit.BeforeClass)

Example 69 with OrientGraph

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

the class ODatabaseFailDueCloseTest method test1.

@Test()
public void test1() {
    final OrientGraph graph = pool.getTx();
    try {
        String queryText = "SELECT @rid as rid, localName FROM Person WHERE ( 'milano' IN out('lives').localName OR 'roma' IN out('lives').localName ) ORDER BY age ASC";
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(queryText);
        List<ODocument> results = graph.getRawGraph().query(query);
        assertNotNull(results);
        assertTrue(results.size() > 0);
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 70 with OrientGraph

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

the class ODatabaseFailDueCloseTest method test2.

@Test
public void test2() {
    final OrientGraph graph = pool.getTx();
    try {
        String queryText = "SELECT @rid as rid, localName FROM Person WHERE age > 30";
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(queryText);
        List<ODocument> results = graph.getRawGraph().query(query);
        assertNotNull(results);
        assertTrue(results.size() > 0);
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) 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