use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testOrderByWithRange.
/**
* This test builds a mixed index and tests index queries with order and range/limit.
* It also tests if index query cache is utilised correctly.
*/
@Test
public void testOrderByWithRange() {
final PropertyKey age = makeKey("age", Integer.class);
final JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(age).buildMixedIndex(INDEX);
finishSchema();
for (int i = 0; i < 100; i++) {
tx.addVertex("age", i);
}
tx.commit();
Supplier<GraphTraversal> common = () -> graph.traversal().V().has("age", P.gte(0)).order();
Supplier<GraphTraversal> traversal;
// traverse with limit 30 (cache cold miss)
traversal = () -> common.get().by(ORDER_AGE_ASC).limit(30).values("age");
assertBackendHit((TraversalMetrics) traversal.get().profile().next());
assertIntRange(traversal.get(), 0, 30);
traversal = () -> common.get().by(ORDER_AGE_DESC).limit(30).values("age");
assertBackendHit((TraversalMetrics) traversal.get().profile().next());
assertIntRange(traversal.get(), 99, 69);
// traverse with limit 30 (cache hit)
traversal = () -> common.get().by(ORDER_AGE_ASC).limit(30).values("age");
assertNoBackendHit((TraversalMetrics) traversal.get().profile().next());
assertIntRange(traversal.get(), 0, 30);
// traverse with limit followed by orderBy
traversal = () -> graph.traversal().V().has("age", P.gte(0)).limit(30).order().by(ORDER_AGE_ASC).values("age");
assertBackendHit((TraversalMetrics) traversal.get().profile().next());
assertNoBackendHit((TraversalMetrics) traversal.get().profile().next());
// traverse with range(10, 20) (cache hit)
traversal = () -> common.get().by(ORDER_AGE_DESC).range(10, 20).values("age");
assertNoBackendHit((TraversalMetrics) traversal.get().profile().next());
assertIntRange(traversal.get(), 89, 79);
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphSONModuleTest method testTinkerPopPredicatesAsGraphSON.
@ParameterizedTest(name = "GraphSON Version: {0}")
@EnumSource(value = GraphSONVersion.class, mode = EnumSource.Mode.EXCLUDE, names = { "V1_0" })
public void testTinkerPopPredicatesAsGraphSON(GraphSONVersion graphSONVersion) throws Exception {
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal();
GraphTraversal[] traversals = { g.V().has("age", gt(13)), g.V().has("age", within(20, 29)), g.V().has("age", P.not(within(20, 29))) };
graphsonSerializationTest(traversals, graphSONVersion);
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphSONModuleTest method graphsonSerializationTest.
private void graphsonSerializationTest(GraphTraversal[] traversals, GraphSONVersion version) throws Exception {
final GraphSONMapper mapper = GraphSONMapper.build().version(version).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.instance()).create();
final GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create();
final GraphSONReader reader = GraphSONReader.build().mapper(mapper).create();
for (GraphTraversal traversal : traversals) {
Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
ByteArrayOutputStream serializationStream = new ByteArrayOutputStream();
writer.writeObject(serializationStream, expectedBytecode);
ByteArrayInputStream inputStream = new ByteArrayInputStream(serializationStream.toByteArray());
Bytecode result = reader.readObject(inputStream, Bytecode.class);
assertEquals(expectedBytecode, result);
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphIoRegistryTest method testTokenIoRegistyInConfig.
@Test
public void testTokenIoRegistyInConfig() throws SerializationException {
final GraphSONMessageSerializerV3d0 serializer = new GraphSONMessageSerializerV3d0();
final Map<String, Object> config = new HashMap<>();
config.put(TOKEN_IO_REGISTRIES, Collections.singletonList(JanusGraphIoRegistry.class.getName()));
serializer.configure(config, Collections.emptyMap());
GraphTraversal traversal = EmptyGraph.instance().traversal().addV().property("loc", Geoshape.point(1.0f, 1.0f));
Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
String serializedMessage = serializer.serializeRequestAsString(RequestMessage.build(Tokens.OPS_BYTECODE).processor("traversal").addArg(Tokens.ARGS_GREMLIN, expectedBytecode).create());
RequestMessage requestMessage1 = serializer.deserializeRequest(serializedMessage);
Bytecode result = (Bytecode) requestMessage1.getArgs().get(Tokens.ARGS_GREMLIN);
assertEquals(expectedBytecode, result);
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project janusgraph by JanusGraph.
the class JanusGraphTest method testLimitBatchSizeForMultiQuery.
@Test
public void testLimitBatchSizeForMultiQuery() {
int numV = 100;
JanusGraphVertex a = graph.addVertex();
JanusGraphVertex[] bs = new JanusGraphVertex[numV];
JanusGraphVertex[] cs = new JanusGraphVertex[numV];
for (int i = 0; i < numV; ++i) {
bs[i] = graph.addVertex();
cs[i] = graph.addVertex();
cs[i].property("foo", "bar");
a.addEdge("knows", bs[i]);
bs[i].addEdge("knows", cs[i]);
}
int barrierSize = 27;
int limit = 40;
// test batching for `out()`
Supplier<GraphTraversal<?, ?>> traversal = () -> graph.traversal().V(bs).barrier(barrierSize).out();
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), true);
TraversalMetrics profile = traversal.get().profile().next();
assertEquals(3, countBackendQueriesOfSize(barrierSize * 2, profile.getMetrics()));
assertEquals(1, countBackendQueriesOfSize((numV - 3 * barrierSize) * 2, profile.getMetrics()));
// test early abort with limit for `out()`
traversal = () -> graph.traversal().V(bs).barrier(barrierSize).out().limit(limit);
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), true);
profile = traversal.get().profile().next();
assertEquals((int) Math.ceil((double) limit / barrierSize), countBackendQueriesOfSize(barrierSize * 2, profile.getMetrics()));
// test batching for `values()`
traversal = () -> graph.traversal().V(cs).barrier(barrierSize).values("foo");
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), true);
profile = traversal.get().profile().next();
assertEquals(3, countBackendQueriesOfSize(barrierSize, profile.getMetrics()));
assertEquals(1, countBackendQueriesOfSize(numV - 3 * barrierSize, profile.getMetrics()));
// test early abort with limit for `values()`
traversal = () -> graph.traversal().V(cs).barrier(barrierSize).values("foo").limit(limit);
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), true);
profile = traversal.get().profile().next();
assertEquals((int) Math.ceil((double) limit / barrierSize), countBackendQueriesOfSize(barrierSize, profile.getMetrics()));
// test batching with unlimited batch size
traversal = () -> graph.traversal().V(bs).barrier(barrierSize).out();
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), false);
profile = traversal.get().profile().next();
assertEquals(0, countBackendQueriesOfSize(barrierSize, profile.getMetrics()));
assertEquals(0, countBackendQueriesOfSize(barrierSize * 2, profile.getMetrics()));
assertEquals(1, countBackendQueriesOfSize(bs.length * 2, profile.getMetrics()));
// test nested VertexStep with unlimited batch size
traversal = () -> graph.traversal().V(bs).barrier(barrierSize).where(__.out());
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), false);
profile = traversal.get().profile().next();
assertEquals(0, countBackendQueriesOfSize(barrierSize, profile.getMetrics()));
assertEquals(0, countBackendQueriesOfSize(barrierSize * 2, profile.getMetrics()));
assertEquals(1, countBackendQueriesOfSize(bs.length * 2, profile.getMetrics()));
// test nested VertexStep with non-nested barrier
traversal = () -> graph.traversal().V(bs).barrier(barrierSize).where(__.out());
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), true);
profile = traversal.get().profile().next();
assertEquals(3, countBackendQueriesOfSize(barrierSize * 2, profile.getMetrics()));
assertEquals(1, countBackendQueriesOfSize((numV - 3 * barrierSize) * 2, profile.getMetrics()));
// test batching with repeat step
traversal = () -> graph.traversal().V(a).repeat(__.barrier(barrierSize).out()).times(2);
assertEqualResultWithAndWithoutLimitBatchSize(traversal);
clopen(option(USE_MULTIQUERY), true, option(LIMIT_BATCH_SIZE), true);
profile = traversal.get().profile().next();
assertEquals(3, countBackendQueriesOfSize(barrierSize * 2, profile.getMetrics()));
assertEquals(1, countBackendQueriesOfSize((numV - 3 * barrierSize) * 2, profile.getMetrics()));
}
Aggregations