use of com.thinkaurelius.titan.core.TitanKey in project titan by thinkaurelius.
the class TitanGraphQueryTestSuite method testGraphQueryForVertices.
@Override
public void testGraphQueryForVertices() {
TitanGraph g = (TitanGraph) graphTest.generateGraph();
if (g.getType("age") == null) {
TitanKey age = g.makeKey("age").dataType(Integer.class).single().make();
}
g.shutdown();
super.testGraphQueryForVertices();
}
use of com.thinkaurelius.titan.core.TitanKey in project titan by thinkaurelius.
the class TitanGraphPerformanceMemoryTest method testTransactionalMemory.
@Test
public void testTransactionalMemory() throws Exception {
graph.makeKey("uid").dataType(Long.class).indexed(Vertex.class).single(TypeMaker.UniquenessConsistency.NO_LOCK).unique(TypeMaker.UniquenessConsistency.NO_LOCK).make();
graph.makeKey("name").dataType(String.class).single(TypeMaker.UniquenessConsistency.NO_LOCK).make();
TitanKey time = graph.makeKey("time").dataType(Integer.class).single(TypeMaker.UniquenessConsistency.NO_LOCK).make();
graph.makeLabel("friend").signature(time).directed().make();
graph.commit();
final Random random = new Random();
final int rounds = 100;
final int commitSize = 1500;
final AtomicInteger uidCounter = new AtomicInteger(0);
Thread[] writeThreads = new Thread[4];
long start = System.currentTimeMillis();
for (int t = 0; t < writeThreads.length; t++) {
writeThreads[t] = new Thread(new Runnable() {
@Override
public void run() {
for (int r = 0; r < rounds; r++) {
TitanTransaction tx = graph.newTransaction();
TitanVertex previous = null;
for (int c = 0; c < commitSize; c++) {
TitanVertex v = tx.addVertex();
long uid = uidCounter.incrementAndGet();
v.setProperty("uid", uid);
v.setProperty("name", "user" + uid);
if (previous != null) {
v.addEdge("friend", previous).setProperty("time", Math.abs(random.nextInt()));
}
previous = v;
}
tx.commit();
}
}
});
writeThreads[t].start();
}
for (int t = 0; t < writeThreads.length; t++) {
writeThreads[t].join();
}
System.out.println("Write time for " + (rounds * commitSize * writeThreads.length) + " vertices & edges: " + (System.currentTimeMillis() - start));
final int maxUID = uidCounter.get();
final int trials = 1000;
final String fixedName = "john";
Thread[] readThreads = new Thread[Runtime.getRuntime().availableProcessors() * 2];
start = System.currentTimeMillis();
for (int t = 0; t < readThreads.length; t++) {
readThreads[t] = new Thread(new Runnable() {
@Override
public void run() {
TitanTransaction tx = graph.newTransaction();
long ruid = random.nextInt(maxUID) + 1;
tx.getVertex("uid", ruid).setProperty("name", fixedName);
for (int t = 1; t <= trials; t++) {
TitanVertex v = tx.getVertex("uid", random.nextInt(maxUID) + 1);
assertEquals(2, Iterables.size(v.getProperties()));
int count = 0;
for (TitanEdge e : v.getEdges()) {
count++;
assertTrue(((Number) e.getProperty("time")).longValue() >= 0);
}
assertTrue(count <= 2);
// if (t%(trials/10)==0) System.out.println(t);
}
assertEquals(fixedName, tx.getVertex("uid", ruid).getProperty("name"));
tx.commit();
}
});
readThreads[t].start();
}
for (int t = 0; t < readThreads.length; t++) {
readThreads[t].join();
}
System.out.println("Read time for " + (trials * readThreads.length) + " vertex lookups: " + (System.currentTimeMillis() - start));
}
use of com.thinkaurelius.titan.core.TitanKey in project titan by thinkaurelius.
the class GraphOfTheGodsFactory method load.
public static void load(final TitanGraph graph) {
graph.makeKey("name").dataType(String.class).indexed(Vertex.class).unique().make();
graph.makeKey("age").dataType(Integer.class).indexed(INDEX_NAME, Vertex.class).make();
graph.makeKey("type").dataType(String.class).make();
final TitanKey time = graph.makeKey("time").dataType(Integer.class).make();
final TitanKey reason = graph.makeKey("reason").dataType(String.class).indexed(INDEX_NAME, Edge.class).make();
graph.makeKey("place").dataType(Geoshape.class).indexed(INDEX_NAME, Edge.class).make();
graph.makeLabel("father").manyToOne().make();
graph.makeLabel("mother").manyToOne().make();
graph.makeLabel("battled").sortKey(time).make();
graph.makeLabel("lives").signature(reason).make();
graph.makeLabel("pet").make();
graph.makeLabel("brother").make();
graph.commit();
// vertices
Vertex saturn = graph.addVertex(null);
saturn.setProperty("name", "saturn");
saturn.setProperty("age", 10000);
saturn.setProperty("type", "titan");
Vertex sky = graph.addVertex(null);
ElementHelper.setProperties(sky, "name", "sky", "type", "location");
Vertex sea = graph.addVertex(null);
ElementHelper.setProperties(sea, "name", "sea", "type", "location");
Vertex jupiter = graph.addVertex(null);
ElementHelper.setProperties(jupiter, "name", "jupiter", "age", 5000, "type", "god");
Vertex neptune = graph.addVertex(null);
ElementHelper.setProperties(neptune, "name", "neptune", "age", 4500, "type", "god");
Vertex hercules = graph.addVertex(null);
ElementHelper.setProperties(hercules, "name", "hercules", "age", 30, "type", "demigod");
Vertex alcmene = graph.addVertex(null);
ElementHelper.setProperties(alcmene, "name", "alcmene", "age", 45, "type", "human");
Vertex pluto = graph.addVertex(null);
ElementHelper.setProperties(pluto, "name", "pluto", "age", 4000, "type", "god");
Vertex nemean = graph.addVertex(null);
ElementHelper.setProperties(nemean, "name", "nemean", "type", "monster");
Vertex hydra = graph.addVertex(null);
ElementHelper.setProperties(hydra, "name", "hydra", "type", "monster");
Vertex cerberus = graph.addVertex(null);
ElementHelper.setProperties(cerberus, "name", "cerberus", "type", "monster");
Vertex tartarus = graph.addVertex(null);
ElementHelper.setProperties(tartarus, "name", "tartarus", "type", "location");
// edges
jupiter.addEdge("father", saturn);
jupiter.addEdge("lives", sky).setProperty("reason", "loves fresh breezes");
jupiter.addEdge("brother", neptune);
jupiter.addEdge("brother", pluto);
neptune.addEdge("lives", sea).setProperty("reason", "loves waves");
neptune.addEdge("brother", jupiter);
neptune.addEdge("brother", pluto);
hercules.addEdge("father", jupiter);
hercules.addEdge("mother", alcmene);
ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1, "place", Geoshape.point(38.1f, 23.7f));
ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2, "place", Geoshape.point(37.7f, 23.9f));
ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12, "place", Geoshape.point(39f, 22f));
pluto.addEdge("brother", jupiter);
pluto.addEdge("brother", neptune);
pluto.addEdge("lives", tartarus).setProperty("reason", "no fear of death");
pluto.addEdge("pet", cerberus);
cerberus.addEdge("lives", tartarus);
// commit the transaction to disk
graph.commit();
}
use of com.thinkaurelius.titan.core.TitanKey in project titan by thinkaurelius.
the class Schema method makeTypes.
public void makeTypes(TitanGraph g) {
Preconditions.checkArgument(edgeLabels <= edgePropKeys);
TitanTransaction tx = g.newTransaction();
for (int i = 0; i < vertexPropKeys; i++) {
tx.makeKey(getVertexPropertyName(i)).dataType(Integer.class).indexed(Vertex.class).single().make();
}
for (int i = 0; i < edgePropKeys; i++) {
tx.makeKey(getEdgePropertyName(i)).dataType(Integer.class).indexed(Edge.class).single().make();
}
for (int i = 0; i < edgeLabels; i++) {
String labelName = getEdgeLabelName(i);
String pkName = getSortKeyForLabel(labelName);
TitanKey pk = tx.getPropertyKey(pkName);
tx.makeLabel(getEdgeLabelName(i)).sortKey(pk).make();
}
tx.makeKey(UID_PROP).dataType(Long.class).indexed(Vertex.class).single().unique().make();
tx.commit();
}
use of com.thinkaurelius.titan.core.TitanKey in project titan by thinkaurelius.
the class TitanGraphQueryTestSuite method testGraphQueryForEdges.
@Override
public void testGraphQueryForEdges() {
TitanGraph g = (TitanGraph) graphTest.generateGraph();
if (g.getType("weight") == null) {
TitanKey weight = g.makeKey("weight").dataType(Double.class).single().make();
}
g.shutdown();
super.testGraphQueryForEdges();
}
Aggregations