@Override public GraphTraversalSource traversal(final Graph graph, final TraversalStrategy... strategies) { return graph.traversal().withStrategies(strategies); }
@Override public GraphTraversalSource traversal(final Graph graph, final TraversalStrategy... strategies) { return new GraphTraversalSource(graph).withComputer(FulgoraGraphComputer.class).withStrategies(strategies); }
/** * Create a {@link GraphTraversalSource} from a {@link Graph} instance. The default implementation does not use * {@link GraphComputer} so providers should override as necessary if their implementation is testing * something that requires a different engine type, like {@link GraphComputer}. * <p/> * Implementations should apply strategies as necessary to the * {@link org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource} before calling * it's {@code create} method. */ public default GraphTraversalSource traversal(final Graph graph, final TraversalStrategy... strategies) { return this.traversal(graph).withStrategies(strategies); }
@Before public void setupTest() { super.setupTest(); g = g.withStrategies(MatchAlgorithmStrategy.build().algorithm(MatchStep.GreedyMatchAlgorithm.class).create()); } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) public void shouldAppendPartitionToVertexPropertyOverMultiProperty() { final PartitionStrategy partitionStrategy = PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create(); final Vertex v = g.withStrategies(partitionStrategy).addV().property(VertexProperty.Cardinality.list, "any", "thing") .property(VertexProperty.Cardinality.list, "any", "more").next(); assertNotNull(v); assertThat((List<String>) IteratorUtils.asList(g.V(v).properties("any")).stream().map(p -> ((VertexProperty) p).value()).collect(Collectors.toList()), containsInAnyOrder("thing", "more")); assertEquals("A", v.property(partition).value()); assertThat((List<String>) IteratorUtils.asList(g.V(v).properties("any")).stream().map(p -> ((VertexProperty) p).value(partition)).collect(Collectors.toList()), containsInAnyOrder("A", "A")); }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationWithStrategy() { return translator.translate(g.withStrategies(ReadOnlyStrategy.instance()) .withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()) .V().out().in("link").out().in("link").asAdmin().getBytecode()); } }
@Test @LoadGraphWith(MODERN) public void shouldFilterComplexVertexCriterion() throws Exception { checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").where(out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().where(has("name", "marko").out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("marko", "vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.or(both().has("name", "marko"), has("name", "marko"))).create()). V().where(bothE().count().is(P.neq(0))).values("name")); }
@Test(expected = NoSuchElementException.class) @LoadGraphWith(MODERN) public void shouldGetExcludedVertex() throws Exception { final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("josh", "lop", "ripple")); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertices(vertexCriterion).create()); sg.V(convertToVertexId("marko")).next(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForValueMapWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).valueMap().count().next()); assertEquals("thing", ((List) gOverA.V(v).valueMap().next().get("any")).get(0)); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForPropertyMapWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).propertyMap().count().next()); assertEquals("thing", ((List<VertexProperty>) gOverA.V(v).propertyMap().next().get("any")).get(0).value()); }
@Test @LoadGraphWith(MODERN) public void shouldFilterVertexCriterionAndKeepLabels() throws Exception { // this will exclude "peter" final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("ripple", "josh", "marko")); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertices(vertexCriterion).create()); assertEquals(9, g.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); assertEquals(2, sg.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); final List<Object> list = sg.V().as("a").out().in().as("b").dedup("a", "b").values("name").toList(); assertThat(list, hasItems("marko", "josh")); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForProperties() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); try { gOverA.V(v).properties(partition).next(); fail("Should have thrown exception"); } catch (Exception ex) { assertThat(ex.getMessage(), startsWith("Cannot explicitly request the partitionKey in the traversal")); } }
@Test(expected = IllegalStateException.class) @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForPropertyMap() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); gOverA.V(v).propertyMap(partition).next(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForValueMap() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); try { gOverA.V(v).valueMap(partition).next(); fail("Should have thrown exception"); } catch (Exception ex) { } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldNotAppendPartitionToVertexProperty() { final PartitionStrategy partitionStrategy = PartitionStrategy.build() .includeMetaProperties(false) .partitionKey(partition).writePartition("A").readPartitions("A").create(); final Vertex v = g.withStrategies(partitionStrategy).addV().property("any", "thing").next(); assertNotNull(v); assertEquals("thing", g.V(v).values("any").next()); assertEquals("A", g.V(v).values(partition).next()); assertThat(g.V(v).properties("any").properties().hasNext(), is(false)); }
@Test(expected = NoSuchElementException.class) @LoadGraphWith(MODERN) public void shouldGetExcludedEdge() throws Exception { final Traversal<Edge, ?> edgeCriterion = __.or( has("weight", 1.0d).hasLabel("knows"), // 8 has("weight", 0.4d).hasLabel("created").outV().has("name", "marko"), // 9 has("weight", 1.0d).hasLabel("created") // 10 ); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().edges(edgeCriterion).create()); sg.E(sg.E(convertToEdgeId("marko", "knows", "vadas")).next()).next(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldAppendPartitionToVertex() { final PartitionStrategy partitionStrategy = PartitionStrategy.build() .partitionKey(partition).writePartition("A").readPartitions("A").create(); final Vertex v = g.withStrategies(partitionStrategy).addV().property("any", "thing").next(); assertNotNull(v); assertEquals("thing", g.V(v).values("any").next()); assertEquals("A", g.V(v).values(partition).next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldAppendPartitionToVertexProperty() { final PartitionStrategy partitionStrategy = PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create(); final Vertex v = g.withStrategies(partitionStrategy).addV().property("any", "thing").next(); assertNotNull(v); assertEquals("thing", g.V(v).values("any").next()); assertEquals("A", g.V(v).values(partition).next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForValuesWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).values().count().next()); assertEquals("thing", gOverA.V(v).values().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldHidePartitionKeyForPropertiesWithEmptyKeys() { final GraphTraversalSource gOverA = g.withStrategies(PartitionStrategy.build() .includeMetaProperties(true) .partitionKey(partition).writePartition("A").readPartitions("A").create()); final Vertex v = gOverA.addV().property("any", "thing").next(); assertEquals(1L, (long) gOverA.V(v).properties().count().next()); assertEquals("thing", gOverA.V(v).properties().value().next()); }