Search in sources :

Example 76 with OrientVertex

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

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

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

Example 79 with OrientVertex

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

the class BasicShardingNoReplicaScenarioTest method executeTest.

@Override
public void executeTest() throws Exception {
    OHazelcastPlugin manager1 = (OHazelcastPlugin) serverInstance.get(0).getServerInstance().getDistributedManager();
    final OModifiableDistributedConfiguration databaseConfiguration = manager1.getDatabaseConfiguration(this.getDatabaseName()).modify();
    ODocument cfg = databaseConfiguration.getDocument();
    OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
    OrientGraphNoTx graphNoTx = null;
    try {
        graphNoTx = localFactory.getNoTx();
        final OrientVertexType clientType = graphNoTx.createVertexType("Client", 1);
        OModifiableDistributedConfiguration dCfg = new OModifiableDistributedConfiguration(cfg);
        for (int i = 0; i < serverInstance.size(); ++i) {
            final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
            clientType.addCluster("client_" + serverName);
            dCfg.setServerOwner("client_" + serverName, serverName);
        }
        manager1.updateCachedDatabaseConfiguration(this.getDatabaseName(), dCfg, true);
        final OrientVertexType.OrientVertexProperty prop = clientType.createProperty("name", OType.STRING);
        prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
        assertTrue(graphNoTx.getRawGraph().getMetadata().getIndexManager().existsIndex("Client.name"));
        Thread.sleep(500);
        graphNoTx.getRawGraph().close();
        // writes on the three clusters
        executeMultipleWritesOnShards(executeTestsOnServers, "plocal");
        // check consistency (no-replica)
        checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
        // network fault on server3
        System.out.println("Shutdown on server3.\n");
        simulateServerFault(serverInstance.get(2), "shutdown");
        assertFalse(serverInstance.get(2).isActive());
        waitForDatabaseIsOffline(executeTestsOnServers.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
        // check consistency (no-replica)
        executeTestsOnServers.remove(2);
        checkAvailabilityOnShardsNoReplica(executeTestsOnServers, executeTestsOnServers);
        // this query doesn't return any result
        try {
            System.out.print("Checking that records on server3 are not available in the cluster...");
            graphNoTx = localFactory.getNoTx();
            ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
            final String uniqueId = "client_asia-s2-t10-v0";
            Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
            List<OrientVertex> result = new LinkedList<OrientVertex>();
            for (Vertex v : it) {
                result.add((OrientVertex) v);
            }
            assertEquals(0, result.size());
            System.out.println("Done");
            graphNoTx.getRawGraph().close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
        // restarting server3
        serverInstance.get(2).startServer(getDistributedServerConfiguration(serverInstance.get(SERVERS - 1)));
        System.out.println("Server 3 restarted.");
        assertTrue(serverInstance.get(2).isActive());
        waitForDatabaseIsOnline(0, serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
        // checking server3 status by querying a record inserted on it
        try {
            System.out.print("Checking server3 status by querying a record inserted on it...");
            localFactory = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName());
            graphNoTx = localFactory.getNoTx();
            ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
            final String uniqueId = "client_asia-s2-t10-v0";
            Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
            List<OrientVertex> result = new LinkedList<OrientVertex>();
            for (Vertex v : it) {
                result.add((OrientVertex) v);
            }
            assertEquals(1, result.size());
            graphNoTx.getRawGraph().close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.toString());
        }
        // check consistency (no-replica)
        executeTestsOnServers.add(serverInstance.get(2));
        checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    } finally {
        if (!graphNoTx.getRawGraph().isClosed()) {
            ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
            graphNoTx.getRawGraph().close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        }
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OModifiableDistributedConfiguration(com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration) LinkedList(java.util.LinkedList) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 80 with OrientVertex

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

the class ConcurrentDistributedUpdateTest method createWriter.

protected Callable<Void> createWriter(final int serverId, final int threadId, final String databaseURL) {
    return new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            final String id = serverId + "." + threadId;
            boolean isRunning = true;
            final OrientBaseGraph graph = new OrientGraph(databaseURL);
            try {
                String query = "select from Test where prop2='v2-1'";
                for (int i = 0; i < 100 && isRunning; i++) {
                    if ((i % 25) == 0) {
                        log("[" + id + "] Records Processed: [" + i + "]");
                    }
                    Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
                    boolean update = true;
                    for (Vertex vtx : vtxs) {
                        if (update) {
                            update = true;
                            for (int k = 0; k < 10 && update; k++) {
                                OrientVertex vtx1 = (OrientVertex) vtx;
                                try {
                                    vtx1.setProperty("prop5", "prop55");
                                    graph.commit();
                                    // log("[" + id + "/" + i + "/" + k + "] OK!\n");
                                    break;
                                } catch (OConcurrentModificationException ex) {
                                    vtx1.reload();
                                } catch (ODistributedRecordLockedException ex) {
                                    log("[" + id + "/" + i + "/" + k + "] Distributed lock Exception " + ex + " for vertex " + vtx1 + " \n");
                                    //                    ex.printStackTrace();
                                    update = false;
                                    //                    isRunning = false;
                                    break;
                                } catch (Exception ex) {
                                    log("[" + id + "/" + i + "/" + k + "] Exception " + ex + " for vertex " + vtx1 + "\n\n");
                                    ex.printStackTrace();
                                    isRunning = false;
                                    break;
                                }
                            }
                            if (!isRunning)
                                break;
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
                ex.printStackTrace();
            } finally {
                log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
                graph.shutdown();
                runningWriters.countDown();
            }
            Assert.assertTrue(isRunning);
            return null;
        }
    };
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) ODistributedRecordLockedException(com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException) 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) Callable(java.util.concurrent.Callable) ODistributedRecordLockedException(com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL)

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