use of com.thinkaurelius.titan.core.TitanTransaction in project titan by thinkaurelius.
the class InMemoryConfigurationTest method testReadOnly.
@Test
public void testReadOnly() {
initialize(GraphDatabaseConfiguration.STORAGE_READONLY, true);
TitanTransaction tx = graph.newTransaction();
try {
tx.addVertex();
fail();
} catch (Exception e) {
} finally {
tx.rollback();
}
try {
graph.addVertex();
fail();
} catch (Exception e) {
} finally {
graph.tx().rollback();
}
}
use of com.thinkaurelius.titan.core.TitanTransaction in project titan by thinkaurelius.
the class TitanGraphPerformanceMemoryTest method testDeepTraversals.
@Test
public void testDeepTraversals() throws Exception {
// 1) Write random graph
final int numV = 5000;
final int numE = 50;
final String label = "knows";
final Random random = new Random();
final long[] vids = writeGraph(numV, numE, label);
Thread[] readThreads = new Thread[4];
final int trials = 500;
final int repetitions = 2;
long start = System.currentTimeMillis();
for (int t = 0; t < readThreads.length; t++) {
readThreads[t] = new Thread(new Runnable() {
@Override
public void run() {
for (int t = 1; t <= trials; t++) {
TitanTransaction tx = graph.newTransaction();
TitanVertex v = tx.getVertex(vids[random.nextInt(numV)]);
for (int r = 0; r < repetitions; r++) {
assertEquals((int) Math.pow(numE, 2), Iterables.size(new GremlinPipeline<Vertex, Vertex>(v).out(label).out(label)));
}
tx.commit();
}
}
});
readThreads[t].start();
}
for (int t = 0; t < readThreads.length; t++) {
readThreads[t].join();
}
System.out.println("Time in ms for [" + (readThreads.length * trials) + "] concurrent traversals with [" + repetitions + "] repetitions: " + (System.currentTimeMillis() - start));
}
use of com.thinkaurelius.titan.core.TitanTransaction 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.TitanTransaction in project titan by thinkaurelius.
the class GraphGenerator method generateData.
/**
* Generate a scale-free graph using parameters specified in the
* {@link Schema} object provided to this instance's constructor. The types
* must already exist. The types can be created by either calling
* {@link #generateTypesAndData(TitanGraph)} instead of this method or by
* calling {@link Schema#makeTypes(TitanGraph)} before calling this method.
*
* @param g A graph with types predefined. If it already contains vertices
* or relations, they may be overwritten.
*/
public void generateData(TitanGraph g) {
// Generate vertices
for (long i = uidCounter; i < schema.getVertexCount() + INITIAL_VERTEX_UID - 1; i++) {
Vertex v = g.addVertex(i);
// DistributionGenerator doesn't currently support VertexAnnotator
vertexAnnotator.annotate(v, null);
}
// Generate edges
for (int i = 0; i < schema.getEdgeLabels(); i++) {
DistributionGenerator gen = new DistributionGenerator(schema.getEdgeLabelName(i), edgeAnnotator);
gen.setOutDistribution(new PowerLawDistribution(GAMMA));
gen.setInDistribution(new PowerLawDistribution(GAMMA));
gen.generate(g, schema.getEdgeCount());
}
g.commit();
TitanTransaction tx = g.newTransaction();
// Add a vertex that has an out edge to every other vertex
Vertex hiOutDeg = tx.addVertex(Schema.SUPERNODE_UID);
String label = schema.getSupernodeOutLabel();
TitanKey uidKey = tx.getPropertyKey(Schema.UID_PROP);
hiOutDeg.setProperty(Schema.UID_PROP, Schema.SUPERNODE_UID);
String pKey = schema.getSortKeyForLabel(label);
for (long i = INITIAL_VERTEX_UID; i < schema.getVertexCount(); i++) {
Vertex in = tx.getVertex(uidKey, i);
Edge e = hiOutDeg.addEdge(label, in);
e.setProperty(pKey, (int) i);
}
tx.commit();
}
Aggregations