use of org.janusgraph.graphdb.internal.InternalVertexLabel in project janusgraph by JanusGraph.
the class JanusGraphOperationCountingTest method testReadOperations.
@SuppressWarnings("unchecked")
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();
JanusGraphTransaction 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(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 nameInternal = (InternalRelationType) name;
InternalRelationType knowsInternal = (InternalRelationType) knows;
InternalRelationType uidInternal = (InternalRelationType) uid;
assertNull(nameInternal.getBaseType());
assertNull(knowsInternal.getBaseType());
IndexType index = Iterables.getOnlyElement(uidInternal.getKeyIndexes());
assertEquals(1, index.getFieldKeys().length);
assertEquals(ElementCategory.VERTEX, index.getElement());
assertEquals(ConsistencyModifier.LOCK, ((CompositeIndexType) index).getConsistencyModifier());
assertEquals(1, Iterables.size(uidInternal.getRelationIndexes()));
assertEquals(1, Iterables.size(nameInternal.getRelationIndexes()));
assertEquals(nameInternal, Iterables.getOnlyElement(nameInternal.getRelationIndexes()));
assertEquals(knowsInternal, Iterables.getOnlyElement(knowsInternal.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();
JanusGraphVertex 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(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) {
verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE, 4L));
verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE, 1L));
} else if (i > 20) {
// Needs a couple of iterations for cache to be cleaned
verifyStoreMetrics(EDGESTORE_NAME);
verifyStoreMetrics(INDEXSTORE_NAME);
}
}
}
Aggregations