use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestGraphIntentMassiveInsert method testIntent.
@Test
public void testIntent() {
final OrientGraph graph = new OrientGraph("memory:default", false);
graph.setUseLightweightEdges(true);
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
final OrientVertexType c1 = graph.createVertexType("C1");
c1.createProperty("p1", OType.INTEGER);
graph.createEdgeType("parent");
graph.begin();
final OrientVertex first = graph.addVertex("class:C1");
first.setProperty("p1", -1);
for (int i = 0; i < 10; i++) {
final OrientVertex v = graph.addVertex("class:C1");
v.setProperty("p1", i);
first.addEdge("parent", v);
//this search fills _source
graph.command(new OSQLSynchQuery("SELECT from V where p1='" + i + "'")).execute();
}
graph.commit();
//here NPE will be thrown
final Iterable<Edge> edges = first.getEdges(Direction.BOTH);
Iterator<Edge> ter = edges.iterator();
for (int i = 0; i < 10; i++) {
assertTrue(ter.hasNext());
assertEquals(ter.next().getVertex(Direction.IN).getProperty("p1"), i);
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class ConcurrentTxTest method testMultithreadedProvokeOConcurrentModificationException2.
@Test(expected = OConcurrentModificationException.class)
public void testMultithreadedProvokeOConcurrentModificationException2() throws Throwable {
// Create vertex
OrientGraph mainTx = graphFactory.getTx();
mainTx.begin();
OrientVertex vertex = mainTx.addVertex(null, PROPERTY_NAME, "init");
mainTx.commit();
mainTx.shutdown();
int threadCount = 200;
final Object recordId = vertex.getId();
final CyclicBarrier barrier = new CyclicBarrier(threadCount);
List<Thread> threads = new ArrayList<Thread>();
final AtomicReference<Throwable> t = new AtomicReference<Throwable>(null);
// Spawn two threads and modify the vertex
for (int i = 0; i < threadCount; i++) {
final int threadNo = i;
Thread thread = run(new Runnable() {
@Override
public void run() {
OrientGraph tx = graphFactory.getTx();
try {
tx.begin();
OrientVertex secondVertexHandle = tx.getVertex(recordId);
secondVertexHandle.setProperty(PROPERTY_NAME, threadNo);
waitFor(barrier);
tx.commit();
} catch (Exception e) {
t.set(e);
} finally {
tx.shutdown();
}
}
});
threads.add(thread);
}
// Wait for threads
for (Thread thread : threads) {
thread.join();
}
if (t.get() != null) {
throw t.get();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class EdgeBug method setupClasses.
private void setupClasses() {
OrientGraph db = new OrientGraph("memory:temp", "admin", "admin");
db.createVertexType("rawCategory");
db.createVertexType("rawField");
db.commit();
db.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class EdgeBug method populateDatabase.
private void populateDatabase() {
OrientGraph db = new OrientGraph("memory:temp", "admin", "admin");
aVertex = db.addVertex("class:rawCategory");
aVertex.setProperty("name", "a");
bVertex = db.addVertex("class:rawCategory");
bVertex.setProperty("name", "b");
asubVertex = db.addVertex("class:rawField");
asubVertex.setProperty("name", "asub");
bsubVertex = db.addVertex("class:rawField");
bsubVertex.setProperty("name", "bsub");
asubVertex.addEdge("hasParent", aVertex);
bsubVertex.addEdge("hasParent", bVertex);
db.commit();
db.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class EdgeIndexingTest method testOutLinksUniqueness.
/**
* Test that "in_vertex" has edges to only single "out_vertex" but we may have several edges to single "out_vertex".
*/
@Test
public void testOutLinksUniqueness() {
final String url = "memory:" + this.getClass().getSimpleName();
OrientGraph graph = new OrientGraph(url);
graph.drop();
graph = new OrientGraph(url);
graph.setUseLightweightEdges(true);
graph.createEdgeType("link");
graph.setAutoStartTx(false);
OClass outVertexType = graph.createVertexType("IndexedOutVertex");
outVertexType.createProperty("out_link", OType.LINKBAG);
outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");
graph.setAutoStartTx(true);
Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");
Vertex vertexInOne = graph.addVertex(null);
Vertex vertexInTwo = graph.addVertex(null);
vertexOutOne.addEdge("link", vertexInOne);
vertexOutOne.addEdge("link", vertexInTwo);
graph.commit();
Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
vertexOutTwo.addEdge("link", vertexInTwo);
try {
graph.commit();
// in vertex can be linked by only one out vertex.
Assert.fail();
} catch (ORecordDuplicatedException e) {
}
graph.drop();
}
Aggregations