Search in sources :

Example 1 with InternalVertexLabel

use of com.thinkaurelius.titan.graphdb.internal.InternalVertexLabel in project titan by thinkaurelius.

the class TitanOperationCountingTest method testReadOperations.

public void testReadOperations(boolean cache) {
    metricsPrefix = "testReadOperations" + cache;
    resetEdgeCacheCounts();
    makeVertexIndexedUniqueKey("uid", Integer.class);
    mgmt.setConsistency(mgmt.getGraphIndex("uid"), ConsistencyModifier.LOCK);
    finishSchema();
    if (cache)
        clopen(option(DB_CACHE), true, option(DB_CACHE_CLEAN_WAIT), 0, option(DB_CACHE_TIME), 0);
    else
        clopen();
    TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
    tx.makePropertyKey("name").dataType(String.class).make();
    tx.makeEdgeLabel("knows").make();
    tx.makeVertexLabel("person").make();
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME);
    verifyLockingOverwrite(INDEXSTORE_NAME, 3);
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));
    resetMetrics();
    metricsPrefix = GraphDatabaseConfiguration.METRICS_SCHEMA_PREFIX_DEFAULT;
    resetMetrics();
    //Test schema caching
    for (int t = 0; t < 10; t++) {
        tx = graph.buildTransaction().groupName(metricsPrefix).start();
        //Retrieve name by index (one backend call each)
        assertTrue(tx.containsRelationType("name"));
        assertTrue(tx.containsRelationType("knows"));
        assertTrue(tx.containsVertexLabel("person"));
        PropertyKey name = tx.getPropertyKey("name");
        EdgeLabel knows = tx.getEdgeLabel("knows");
        VertexLabel person = tx.getVertexLabel("person");
        PropertyKey uid = tx.getPropertyKey("uid");
        //Retrieve name as property (one backend call each)
        assertEquals("name", name.name());
        assertEquals("knows", knows.name());
        assertEquals("person", person.name());
        assertEquals("uid", uid.name());
        //Looking up the definition (one backend call each)
        assertEquals(Cardinality.SINGLE, name.cardinality());
        assertEquals(Multiplicity.MULTI, knows.multiplicity());
        assertFalse(person.isPartitioned());
        assertEquals(Integer.class, uid.dataType());
        //Retrieving in and out relations for the relation types...
        InternalRelationType namei = (InternalRelationType) name;
        InternalRelationType knowsi = (InternalRelationType) knows;
        InternalRelationType uidi = (InternalRelationType) uid;
        assertNull(namei.getBaseType());
        assertNull(knowsi.getBaseType());
        IndexType index = Iterables.getOnlyElement(uidi.getKeyIndexes());
        assertEquals(1, index.getFieldKeys().length);
        assertEquals(ElementCategory.VERTEX, index.getElement());
        assertEquals(ConsistencyModifier.LOCK, ((CompositeIndexType) index).getConsistencyModifier());
        assertEquals(1, Iterables.size(uidi.getRelationIndexes()));
        assertEquals(1, Iterables.size(namei.getRelationIndexes()));
        assertEquals(namei, Iterables.getOnlyElement(namei.getRelationIndexes()));
        assertEquals(knowsi, Iterables.getOnlyElement(knowsi.getRelationIndexes()));
        //.. and vertex labels
        assertEquals(0, ((InternalVertexLabel) person).getTTL());
        tx.commit();
        //Needs to read on first iteration, after that it doesn't change anymore
        verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE, 19l));
        verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE, 4l, /* name, knows, person, uid */
        M_ACQUIRE_LOCK, 0l));
    }
    //Create some graph data
    metricsPrefix = "add" + cache;
    tx = graph.buildTransaction().groupName(metricsPrefix).start();
    TitanVertex v = tx.addVertex(), u = tx.addVertex("person");
    v.property(VertexProperty.Cardinality.single, "uid", 1);
    u.property(VertexProperty.Cardinality.single, "name", "juju");
    Edge e = v.addEdge("knows", u);
    e.property("name", "edge");
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME);
    verifyLockingOverwrite(INDEXSTORE_NAME, 1);
    for (int i = 1; i <= 30; i++) {
        metricsPrefix = "op" + i + cache;
        tx = graph.buildTransaction().groupName(metricsPrefix).start();
        v = getOnlyElement(tx.query().has("uid", 1).vertices());
        assertEquals(1, v.<Integer>value("uid").intValue());
        u = getOnlyElement(v.query().direction(Direction.BOTH).labels("knows").vertices());
        e = getOnlyElement(u.query().direction(Direction.IN).labels("knows").edges());
        assertEquals("juju", u.value("name"));
        assertEquals("edge", e.value("name"));
        tx.commit();
        if (!cache || i == 0) {
            verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE, 4l));
            verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE, 1l));
        } else if (cache && i > 20) {
            //Needs a couple of iterations for cache to be cleaned
            verifyStoreMetrics(EDGESTORE_NAME);
            verifyStoreMetrics(INDEXSTORE_NAME);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalVertexLabel(com.thinkaurelius.titan.graphdb.internal.InternalVertexLabel) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Aggregations

InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)1 InternalVertexLabel (com.thinkaurelius.titan.graphdb.internal.InternalVertexLabel)1 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)1 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1