Search in sources :

Example 21 with TitanTransaction

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();
    }
}
Also used : TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) Test(org.junit.Test)

Example 22 with TitanTransaction

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));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) Random(java.util.Random) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) Test(org.junit.Test) PerformanceTest(com.thinkaurelius.titan.testutil.PerformanceTest)

Example 23 with TitanTransaction

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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) TitanKey(com.thinkaurelius.titan.core.TitanKey)

Example 24 with TitanTransaction

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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) DistributionGenerator(com.tinkerpop.furnace.alpha.generators.DistributionGenerator) PowerLawDistribution(com.tinkerpop.furnace.alpha.generators.PowerLawDistribution) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) Edge(com.tinkerpop.blueprints.Edge) TitanKey(com.thinkaurelius.titan.core.TitanKey)

Aggregations

TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)24 Test (org.junit.Test)12 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)10 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)10 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)5 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)5 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)4 TitanException (com.thinkaurelius.titan.core.TitanException)4 PerformanceTest (com.thinkaurelius.titan.testutil.PerformanceTest)4 Vertex (com.tinkerpop.blueprints.Vertex)4 Random (java.util.Random)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TitanConfigurationException (com.thinkaurelius.titan.core.TitanConfigurationException)3 TitanKey (com.thinkaurelius.titan.core.TitanKey)3 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)3 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)3 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)2 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)2 InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)2 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)2