Search in sources :

Example 1 with TitanKey

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

Example 2 with TitanKey

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));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitanKey(com.thinkaurelius.titan.core.TitanKey) TitanEdge(com.thinkaurelius.titan.core.TitanEdge) Test(org.junit.Test) PerformanceTest(com.thinkaurelius.titan.testutil.PerformanceTest)

Example 3 with TitanKey

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

Example 4 with TitanKey

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

Example 5 with TitanKey

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

Aggregations

TitanKey (com.thinkaurelius.titan.core.TitanKey)6 Vertex (com.tinkerpop.blueprints.Vertex)4 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)3 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)2 Edge (com.tinkerpop.blueprints.Edge)2 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)1 PerformanceTest (com.thinkaurelius.titan.testutil.PerformanceTest)1 DistributionGenerator (com.tinkerpop.furnace.alpha.generators.DistributionGenerator)1 PowerLawDistribution (com.tinkerpop.furnace.alpha.generators.PowerLawDistribution)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1