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);
}
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();
}
}
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();
}
}
}
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);
}
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;
}
});
}
Aggregations