use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class BlueprintsConcurrentGraphChangesTestNoTx method deleteEdgesConcurrently.
private void deleteEdgesConcurrently() throws Exception {
ExecutorService executorService = Executors.newCachedThreadPool();
beginTime = System.currentTimeMillis();
List<Future<Void>> futures = new ArrayList<Future<Void>>();
for (int i = 0; i < THREADS; i++) futures.add(executorService.submit(new ConcurrentEdgeRemover()));
latchEdgeDelete.countDown();
for (Future<Void> future : futures) future.get();
final OrientBaseGraph g = getGraph();
printStats(g);
g.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class SQLMoveVertexCommandInTxTest method testMoveWithUniqueIndex.
@Test
public void testMoveWithUniqueIndex() {
graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
@Override
public Object call(OrientBaseGraph iArgument) {
customer.createProperty("id", OType.LONG).createIndex(OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX);
return null;
}
});
for (int i = 0; i < 100; ++i) new ODocument("Customer").field("id", i).save();
graph.commit();
Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where id = 0) TO CLUSTER:Customer_genius")).execute();
Iterable<OrientVertex> result2 = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where id = 1) TO CLASS:Customer")).execute();
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class GraphDatabaseTest method testEmbeddedDoc.
public void testEmbeddedDoc() {
database.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
@Override
public Object call(OrientBaseGraph iArgument) {
return iArgument.getRawGraph().getMetadata().getSchema().createClass("NonVertex");
}
});
Vertex vertex = database.addVertex(null, "name", "vertexWithEmbedded");
ODocument doc = new ODocument();
doc.field("foo", "bar");
vertex.setProperty("emb1", doc);
ODocument doc2 = new ODocument("V");
doc2.field("foo", "bar");
vertex.setProperty("emb2", doc2);
ODocument doc3 = new ODocument("NonVertex");
doc3.field("foo", "bar");
vertex.setProperty("emb3", doc3);
Object res1 = vertex.getProperty("emb1");
Assert.assertNotNull(res1);
Assert.assertTrue(res1 instanceof ODocument);
Object res2 = vertex.getProperty("emb2");
Assert.assertNotNull(res2);
Assert.assertFalse(res2 instanceof ODocument);
Object res3 = vertex.getProperty("emb3");
Assert.assertNotNull(res3);
Assert.assertTrue(res3 instanceof ODocument);
database.commit();
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class DatabaseConflictStrategyAutoMergeTest method dbClient2.
private void dbClient2() {
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(CLIENT_ORIENT_URL_MAIN);
OrientVertex parentV1 = null;
OrientVertex parentV2 = null;
int countPropValue = 0;
try {
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
countPropValue++;
if (parentV1 == null) {
parentV1 = graph.getVertex(parentV1Id);
}
parentV1.setProperty("cnt", countPropValue);
graph.commit();
if (parentV2 == null) {
parentV2 = graph.getVertex(parentV2Id);
}
parentV2.setProperty("cnt", countPropValue);
graph.commit();
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class GraphTransactionConsistency method testTransactionConsistency.
public void testTransactionConsistency() throws InterruptedException {
final OrientGraphFactory factory = new OrientGraphFactory("plocal:target/GraphTransactionConsistency", false);
database = txMode ? factory.getTx() : factory.getNoTx();
System.out.println("Checking consistency of database...");
System.out.println("Records found V=" + database.countVertices() + " E=" + database.countEdges());
final Iterable<OrientVertex> vertices = database.command(new OCommandSQL("select from V")).execute();
for (OrientVertex v : vertices) {
final ODocument doc = v.getRecord();
Assert.assertNotNull(doc);
final ORidBag out = doc.field("out_");
if (out != null) {
for (Iterator<OIdentifiable> it = out.rawIterator(); it.hasNext(); ) {
final OIdentifiable edge = it.next();
Assert.assertNotNull(edge);
final ODocument rec = edge.getRecord();
Assert.assertNotNull(rec);
Assert.assertNotNull(rec.field("out"));
Assert.assertEquals(((ODocument) rec.field("out")).getIdentity(), v.getIdentity());
Assert.assertNotNull(rec.field("in"));
}
}
final ORidBag in = doc.field("in_");
if (in != null) {
for (Iterator<OIdentifiable> it = in.rawIterator(); it.hasNext(); ) {
final OIdentifiable edge = it.next();
Assert.assertNotNull(edge);
final ODocument rec = edge.getRecord();
Assert.assertNotNull(rec);
Assert.assertNotNull(rec.field("in"));
Assert.assertEquals(((ODocument) rec.field("in")).getIdentity(), v.getIdentity());
Assert.assertNotNull(rec.field("out"));
}
}
}
System.out.println("Consistency ok.");
final Thread[] threads = new Thread[THREADS];
for (int i = 0; i < THREADS; ++i) {
final int threadNum = i;
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
OrientBaseGraph graph = txMode ? factory.getTx() : factory.getNoTx();
try {
System.out.println("THREAD " + threadNum + " Start transactions (" + TXNUM + ")");
for (int i = 0; i < TXNUM; ++i) {
final OrientVertex v1 = graph.addVertex(null, "v", i, "type", "Main", "lastUpdate", new Date());
for (int e = 0; e < EDGENUM; ++e) {
final OrientVertex v2 = graph.addVertex(null, "v", i, "e", e, "type", "Connected", "lastUpdate", new Date());
v1.addEdge("E", v2);
}
if (i % TXBATCH == 0) {
System.out.println("THREAD " + threadNum + " Committing batch of " + TXBATCH + " (i=" + i + ")");
System.out.flush();
graph.commit();
System.out.println("THREAD " + threadNum + " Commit ok - records found V=" + graph.countVertices() + " E=" + graph.countEdges());
System.out.flush();
}
}
} finally {
graph.shutdown();
}
}
});
Thread.sleep(1000);
threads[i].start();
}
for (int i = 0; i < THREADS; ++i) {
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
database.shutdown();
}
Aggregations