use of com.thinkaurelius.titan.core.TitanGraph in project titan by thinkaurelius.
the class VertexIDAssignerTest method testIDAssignment.
@Test
public void testIDAssignment() {
LongSet vertexIds = new LongHashSet();
LongSet relationIds = new LongHashSet();
int totalRelations = 0;
int totalVertices = 0;
for (int trial = 0; trial < 10; trial++) {
for (boolean flush : new boolean[] { true, false }) {
TitanGraph graph = getInMemoryGraph();
int numVertices = 1000;
List<TitanVertex> vertices = new ArrayList<TitanVertex>(numVertices);
List<InternalRelation> relations = new ArrayList<InternalRelation>();
TitanVertex old = null;
totalRelations += 2 * numVertices;
totalVertices += numVertices;
try {
for (int i = 0; i < numVertices; i++) {
TitanVertex next = graph.addVertex();
InternalRelation edge = null;
if (old != null) {
edge = (InternalRelation) old.addEdge("knows", next);
}
InternalRelation property = (InternalRelation) next.property("age", 25);
if (flush) {
idAssigner.assignID((InternalVertex) next, next.vertexLabel());
idAssigner.assignID(property);
if (edge != null)
idAssigner.assignID(edge);
}
relations.add(property);
if (edge != null)
relations.add(edge);
vertices.add(next);
old = next;
}
if (!flush)
idAssigner.assignIDs(relations);
//Check if we should have exhausted the id pools
if (totalRelations > maxIDAssignments || totalVertices > maxIDAssignments)
fail();
//Verify that ids are set and unique
for (TitanVertex v : vertices) {
assertTrue(v.hasId());
long id = v.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(vertexIds.add(id));
}
for (InternalRelation r : relations) {
assertTrue(r.hasId());
long id = r.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(relationIds.add(id));
}
} catch (IDPoolExhaustedException e) {
//Since the id assignment process is randomized, we divide by 3/2 to account for minor variations
assertTrue("Max Avail: " + maxIDAssignments + " vs. [" + totalVertices + "," + totalRelations + "]", totalRelations >= maxIDAssignments / 3 * 2 || totalVertices >= maxIDAssignments / 3 * 2);
} finally {
graph.tx().rollback();
graph.close();
}
}
}
}
use of com.thinkaurelius.titan.core.TitanGraph in project incubator-atlas by apache.
the class Titan0Graph method clear.
@Override
public void clear() {
TitanGraph graph = getGraph();
if (graph.isOpen()) {
// only a shut down graph can be cleared
graph.shutdown();
}
TitanCleanup.clear(graph);
}
use of com.thinkaurelius.titan.core.TitanGraph in project incubator-atlas by apache.
the class Titan1Graph method clear.
@Override
public void clear() {
TitanGraph graph = getGraph();
if (graph.isOpen()) {
// only a shut down graph can be cleared
graph.close();
}
TitanCleanup.clear(graph);
}
Aggregations