Search in sources :

Example 51 with OrientGraphNoTx

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

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

the class TestDistributedDatabaseRepair method executeTest.

@Override
protected void executeTest() throws Exception {
    final OrientGraphFactory localFactory0 = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName(), false);
    final OrientGraphFactory localFactory1 = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName(), false);
    final OrientGraphFactory localFactory2 = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName(), false);
    try {
        final OrientGraphNoTx graph = localFactory0.getNoTx();
        graph.createVertexType("ProductType");
        graph.shutdown();
        testNoWinner(localFactory0, localFactory1, localFactory2);
        testWinnerIsMajority(localFactory0, localFactory1, localFactory2);
        testWinnerIsMajorityPlusVersion(localFactory0, localFactory1, localFactory2);
    // testRepairClusters(localFactory0, localFactory1, localFactory2);
    } finally {
        localFactory0.close();
        localFactory1.close();
        localFactory2.close();
    }
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)

Example 53 with OrientGraphNoTx

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

the class DistributedHookTest method executeTest.

@Override
protected void executeTest() throws Exception {
    for (int s = 1; s <= SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        g.getRawGraph().registerHook(new TestHookSourceNode(), ORecordHook.HOOK_POSITION.REGULAR);
        try {
            // CREATE (VIA COMMAND)
            OIdentifiable inserted = g.command(new OCommandSQL("insert into OUser (name, password, status) values ('novo" + s + "','teste','ACTIVE') RETURN @rid")).execute();
            Assert.assertNotNull(inserted);
            Assert.assertEquals(beforeCreate.get(), s);
            Assert.assertEquals(afterCreate.get(), s);
            ODocument loadedDoc = inserted.getIdentity().copy().getRecord();
            // UPDATE
            loadedDoc.field("additionalProperty", "test");
            loadedDoc.save();
            Assert.assertEquals(beforeUpdate.get(), s);
            Assert.assertEquals(afterUpdate.get(), s);
            // DELETE
            loadedDoc.delete();
            Assert.assertEquals(beforeDelete.get(), s);
            Assert.assertEquals(afterDelete.get(), s);
        } 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) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 54 with OrientGraphNoTx

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

the class OGraphCommandExecutorSQLFactory method getAnyGraph.

/**
 * @return any graph if available, otherwise a Non Transactional OrientGraph implementation from the current database in thread
 *         local.
 */
public static OrientBaseGraph getAnyGraph(final OModifiableBoolean shouldBeShutDown) {
    final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OrientBaseGraph result = OrientBaseGraph.getActiveGraph();
    if (result != null) {
        final ODatabaseDocument graphDb = result.getRawGraph();
        // CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT
        if (canReuseActiveGraph(graphDb, database)) {
            if (!graphDb.isClosed()) {
                graphDb.activateOnCurrentThread();
                shouldBeShutDown.setValue(false);
                return result;
            }
        }
    }
    // Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local
    shouldBeShutDown.setValue(true);
    ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal) database);
    return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database);
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 55 with OrientGraphNoTx

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

the class OGraphShortestPathWorkload method execute.

@Override
public void execute(final OStressTesterSettings settings, final ODatabaseIdentifier databaseIdentifier) {
    connectionStrategy = settings.loadBalancing;
    // RETRIEVE THE STARTING VERTICES
    final OrientGraphNoTx g = getGraphNoTx(databaseIdentifier);
    try {
        for (OIdentifiable id : g.getRawGraph().browseClass("V")) {
            startingVertices.add(id.getIdentity());
            if (limit > -1 && startingVertices.size() >= limit)
                break;
        }
    } finally {
        g.shutdown();
    }
    result.total = startingVertices.size();
    executeOperation(databaseIdentifier, result, settings, new OCallable<Void, OBaseWorkLoadContext>() {

        @Override
        public Void call(final OBaseWorkLoadContext context) {
            final OWorkLoadContext graphContext = ((OWorkLoadContext) context);
            final OrientBaseGraph graph = graphContext.graph;
            for (int i = 0; i < startingVertices.size(); ++i) {
                final Iterable<OrientVertex> commandResult = graph.command(new OCommandSQL("select shortestPath(?,?, 'both')")).execute(startingVertices.get(context.currentIdx), startingVertices.get(i));
                for (OrientVertex v : commandResult) {
                    Collection depth = v.getRecord().field("shortestPath");
                    if (depth != null && !depth.isEmpty()) {
                        totalDepth.addAndGet(depth.size());
                        long max = maxDepth.get();
                        while (depth.size() > max) {
                            if (maxDepth.compareAndSet(max, depth.size()))
                                break;
                            max = maxDepth.get();
                        }
                    } else
                        notConnected.incrementAndGet();
                }
            }
            result.current.incrementAndGet();
            return null;
        }
    });
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Collection(java.util.Collection) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Aggregations

OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)72 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)28 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 Test (org.junit.Test)22 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)20 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)17 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)17 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)16 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 Vertex (com.tinkerpop.blueprints.Vertex)6 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)5 OGraphMLReader (com.orientechnologies.orient.graph.graphml.OGraphMLReader)5 OGraphRepair (com.tinkerpop.blueprints.impls.orient.OGraphRepair)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 Edge (com.tinkerpop.blueprints.Edge)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)3 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)3 File (java.io.File)3