Search in sources :

Example 21 with OrientGraphFactory

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

the class ServerClusterGraphTest 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)")).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 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) 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 22 with OrientGraphFactory

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

the class ServerClusterQueryTest method checkSum.

private void checkSum() {
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            final Iterable<OrientVertex> result = g.command(new OCommandSQL("select sum(amount) as total from v")).execute(v2.getIdentity());
            final Iterator<OrientVertex> it = result.iterator();
            Assert.assertTrue(it.hasNext());
            final OrientVertex r1 = it.next();
            Assert.assertEquals(r1.getProperty("total"), 46);
        } finally {
            g.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 23 with OrientGraphFactory

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

the class ServerClusterQueryTest method checkShardedOrderBy.

private void checkShardedOrderBy() {
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            Iterable<OrientVertex> result = g.command(new OCommandSQL("select amount from v order by amount asc")).execute(v2.getIdentity());
            Iterator<OrientVertex> it = result.iterator();
            Assert.assertTrue(it.hasNext());
            OrientVertex r1 = it.next();
            Assert.assertTrue(it.hasNext());
            OrientVertex r2 = it.next();
            Assert.assertTrue(it.hasNext());
            OrientVertex r3 = it.next();
            Assert.assertFalse(it.hasNext());
            Assert.assertEquals(10, r1.getProperty("amount"));
            Assert.assertEquals(15, r2.getProperty("amount"));
            Assert.assertEquals(21, r3.getProperty("amount"));
            result = g.command(new OCommandSQL("select amount from v order by amount desc")).execute(v2.getIdentity());
            it = result.iterator();
            Assert.assertTrue(it.hasNext());
            r1 = it.next();
            Assert.assertTrue(it.hasNext());
            r2 = it.next();
            Assert.assertTrue(it.hasNext());
            r3 = it.next();
            Assert.assertFalse(it.hasNext());
            Assert.assertEquals(21, r1.getProperty("amount"));
            Assert.assertEquals(15, r2.getProperty("amount"));
            Assert.assertEquals(10, r3.getProperty("amount"));
        } finally {
            g.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 24 with OrientGraphFactory

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

the class ServerClusterQueryTest method checkNestedQueryContext.

private void checkNestedQueryContext() {
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            final Iterable<OrientVertex> result = g.command(new OCommandSQL("select *, $depth as d from (traverse in('E1') from ?)")).execute(v2.getIdentity());
            final Iterator<OrientVertex> it = result.iterator();
            Assert.assertTrue(it.hasNext());
            final OrientVertex r1 = it.next();
            Assert.assertTrue(it.hasNext());
            final OrientVertex r2 = it.next();
            Assert.assertFalse(it.hasNext());
            Assert.assertEquals(r1.getProperty("d"), 0);
            Assert.assertEquals(r2.getProperty("d"), 1);
        } finally {
            g.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 25 with OrientGraphFactory

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

the class ServerClusterRemoteInsertBalancedTest method testRoundRobinOnRequest.

private void testRoundRobinOnRequest() {
    final OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/" + getDatabaseName());
    factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_REQUEST.toString());
    OrientGraphNoTx graph = factory.getNoTx();
    Map<Integer, Integer> clusterIds = new HashMap<Integer, Integer>();
    try {
        for (int i = 0; i < ITERATIONS; ++i) {
            final OrientVertex v = graph.addVertex("class:Client");
            Integer value = clusterIds.get(v.getIdentity().getClusterId());
            if (value == null)
                value = 1;
            else
                value++;
            clusterIds.put(v.getIdentity().getClusterId(), value);
        }
    } finally {
        graph.shutdown();
    }
    Assert.assertTrue(clusterIds.size() > 1);
}
Also used : HashMap(java.util.HashMap) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Aggregations

OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)40 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)19 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)8 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)4 Before (org.junit.Before)4 Test (org.junit.Test)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)2 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)2 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)2 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)2 ODistributedException (com.orientechnologies.orient.server.distributed.ODistributedException)2