You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/24 11:32:48 UTC
[2/4] incubator-tinkerpop git commit: Remove GraphStrategy
implementations.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
index e5b1a79..db98150 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
@@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.strategy.GraphStrategy;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.junit.After;
import org.junit.Before;
@@ -56,20 +55,11 @@ public abstract class AbstractGremlinTest {
protected Graph graph;
protected GraphTraversalSource g;
protected Configuration config;
- protected GraphStrategy[] strategiesToTest;
protected GraphProvider graphProvider;
@Rule
public TestName name = new TestName();
- public AbstractGremlinTest() {
- this(null);
- }
-
- public AbstractGremlinTest(final GraphStrategy... strategiesToTest) {
- this.strategiesToTest = strategiesToTest;
- }
-
@Before
public void setup() throws Exception {
graphProvider = GraphManager.getGraphProvider();
@@ -80,7 +70,7 @@ public abstract class AbstractGremlinTest {
graphProvider.clear(config);
// not sure how the strategy can ever be null, but it seems to happen in the performance tests
- graph = graphProvider.openTestGraph(config, strategiesToTest);
+ graph = graphProvider.openTestGraph(config);
g = graphProvider.traversal(graph);
final Method testMethod = this.getClass().getMethod(cleanMethodName(name.getMethodName()));
@@ -136,7 +126,6 @@ public abstract class AbstractGremlinTest {
graphProvider.clear(graph, config);
g = null;
config = null;
- strategiesToTest = null;
graphProvider = null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
index f9aced9..d6e5bb3 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphProvider.java
@@ -37,7 +37,6 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.structure.strategy.GraphStrategy;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
import java.util.Collections;
@@ -119,18 +118,7 @@ public interface GraphProvider {
* already been modified by the implementation as necessary for {@link Graph} creation.
*/
default public Graph openTestGraph(final Configuration config) {
- return openTestGraph(config, null);
- }
-
- /**
- * Creates a new {@link org.apache.tinkerpop.gremlin.structure.Graph} instance from the Configuration object using
- * {@link org.apache.tinkerpop.gremlin.structure.util.GraphFactory}. The assumption here is that the {@code Configuration}
- * has been created by one of the {@link #newGraphConfiguration(String, Class, String)} methods and has therefore
- * already been modified by the implementation as necessary for {@link Graph} creation.
- */
- default public Graph openTestGraph(final Configuration config, final GraphStrategy... strategies) {
- final Graph graph = GraphFactory.open(config);
- return null == strategies ? graph : graph.strategy(strategies);
+ return GraphFactory.open(config);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
index 50a3d8e..8044a85 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
@@ -21,12 +21,6 @@ package org.apache.tinkerpop.gremlin.structure;
import org.apache.tinkerpop.gremlin.AbstractGremlinSuite;
import org.apache.tinkerpop.gremlin.algorithm.generator.CommunityGeneratorTest;
import org.apache.tinkerpop.gremlin.algorithm.generator.DistributionGeneratorTest;
-import org.apache.tinkerpop.gremlin.structure.strategy.IdStrategyTest;
-import org.apache.tinkerpop.gremlin.structure.strategy.PartitionStrategyTest;
-import org.apache.tinkerpop.gremlin.structure.strategy.ReadOnlyStrategyTest;
-import org.apache.tinkerpop.gremlin.structure.strategy.SequenceStrategyTest;
-import org.apache.tinkerpop.gremlin.structure.strategy.StrategyGraphTest;
-import org.apache.tinkerpop.gremlin.structure.strategy.SubgraphStrategyTest;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdgeTest;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPropertyTest;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexPropertyTest;
@@ -50,8 +44,6 @@ import java.util.stream.Stream;
* "Suite" implements {@link org.apache.tinkerpop.gremlin.GraphProvider} as a convenience only. It could be implemented in a
* separate class file):
* <code>
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
* @RunWith(StructureStandardSuite.class)
* @StructureStandardSuite.GraphProviderClass(TinkerGraphStructureStandardTest.class) public class TinkerGraphStructureStandardTest implements GraphProvider {
* }
@@ -64,6 +56,8 @@ import java.util.stream.Stream;
* Set the {@code gremlin.structure.tests} environment variable to a comma separated list of test classes to execute.
* This setting can be helpful to restrict execution of tests to specific ones being focused on during development.
* <br/>
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class StructureStandardSuite extends AbstractGremlinSuite {
@@ -79,17 +73,11 @@ public class StructureStandardSuite extends AbstractGremlinSuite {
FeatureSupportTest.class,
GraphTest.class,
GraphConstructionTest.class,
- IdStrategyTest.class,
IoTest.class,
VertexPropertyTest.class,
VariablesTest.class,
- PartitionStrategyTest.class,
PropertyTest.class,
- ReadOnlyStrategyTest.class,
- SequenceStrategyTest.class,
SerializationTest.class,
- SubgraphStrategyTest.class,
- StrategyGraphTest.class,
TransactionTest.class,
VertexTest.class
};
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategyTest.java
deleted file mode 100644
index 7f7ce37..0000000
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategyTest.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.strategy;
-
-import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
-import org.apache.tinkerpop.gremlin.FeatureRequirement;
-import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
-import org.apache.tinkerpop.gremlin.GraphManager;
-import org.apache.tinkerpop.gremlin.process.traversal.T;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.junit.Test;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.runner.RunWith;
-
-import java.util.UUID;
-
-import static org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS;
-import static org.junit.Assert.*;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-@RunWith(Enclosed.class)
-public class IdStrategyTest {
- private static final String idKey = "myId";
-
- public static class DefaultIdStrategyTest extends AbstractGremlinTest {
-
- public DefaultIdStrategyTest() {
- super(IdStrategy.build(idKey).create());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldInjectAnIdAndReturnBySpecifiedIdForVertex() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex(T.id, "test", "something", "else");
- tryCommit(graph, c -> {
- assertNotNull(v);
- assertEquals("test", v.id());
- assertEquals("test", v.property(strategy.getIdKey()).value());
- assertEquals("else", v.property("something").value());
-
- final Vertex found = g.V("test").next();
- assertEquals("test", found.id());
- assertEquals("test", found.property(strategy.getIdKey()).value());
- assertEquals("else", found.property("something").value());
-
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldInjectAnIdAndReturnBySpecifiedIdForEdge() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex(T.id, "test", "something", "else");
- final Edge e = v.addEdge("self", v, T.id, "edge-id", "try", "this");
- tryCommit(graph, c -> {
- assertNotNull(e);
- assertEquals("edge-id", e.id());
- assertEquals("edge-id", e.property(strategy.getIdKey()).value());
- assertEquals("this", e.property("try").value());
-
- final Edge found = g.E("edge-id").next();
- assertEquals("edge-id", found.id());
- assertEquals("edge-id", found.property(strategy.getIdKey()).value());
- assertEquals("this", found.property("try").value());
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldCreateAnIdAndReturnByCreatedIdForVertex() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex("something", "else");
- tryCommit(graph, c -> {
- assertNotNull(v);
- assertNotNull(UUID.fromString(v.id().toString()));
- assertNotNull(UUID.fromString(v.property(strategy.getIdKey()).value().toString()));
- assertEquals("else", v.property("something").value());
-
- final Vertex found = g.V(v.id()).next();
- assertNotNull(UUID.fromString(found.id().toString()));
- assertNotNull(UUID.fromString(found.property(strategy.getIdKey()).value().toString()));
- assertEquals("else", found.property("something").value());
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldCreateAnIdAndReturnByCreatedIdForEdge() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex("something", "else");
- final Edge e = v.addEdge("self", v, "try", "this");
- tryCommit(graph, c -> {
- assertNotNull(e);
- assertNotNull(UUID.fromString(e.id().toString()));
- assertNotNull(UUID.fromString(e.property(strategy.getIdKey()).value().toString()));
- assertEquals("this", e.property("try").value());
-
- final Edge found = g.E(e.id()).next();
- assertNotNull(UUID.fromString(found.id().toString()));
- assertNotNull(UUID.fromString(found.property(strategy.getIdKey()).value().toString()));
- assertEquals("this", found.property("try").value());
- });
- }
- }
-
- public static class VertexIdMakerIdStrategyTest extends AbstractGremlinTest {
- public VertexIdMakerIdStrategyTest() {
- super(IdStrategy.build(idKey).vertexIdMaker(() -> "100").create());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldCreateAnIdAndReturnByCreatedId() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex("something", "else");
- tryCommit(graph, c -> {
- assertNotNull(v);
- assertEquals("100", v.id());
- assertEquals("100", v.property(strategy.getIdKey()).value());
- assertEquals("else", v.property("something").value());
-
- final Vertex found = g.V("100").next();
- assertEquals("100", found.id());
- assertEquals("100", found.property(strategy.getIdKey()).value());
- assertEquals("else", found.property("something").value());
-
- });
- }
- }
-
- public static class EdgeIdMakerIdStrategyTest extends AbstractGremlinTest {
- public EdgeIdMakerIdStrategyTest() {
- super(IdStrategy.build(idKey).edgeIdMaker(() -> "100").create());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldCreateAnIdAndReturnByCreatedId() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex("something", "else");
- final Edge e = v.addEdge("self", v, "try", "this");
- tryCommit(graph, c -> {
- assertNotNull(e);
- assertEquals("100", e.id());
- assertEquals("100", e.property(strategy.getIdKey()).value());
- assertEquals("this", e.property("try").value());
-
- final Edge found = g.E("100").next();
- assertEquals("100", found.id());
- assertEquals("100", found.property(strategy.getIdKey()).value());
- assertEquals("this", found.property("try").value());
- });
- }
- }
-
- public static class VertexIdNotSupportedIdStrategyTest extends AbstractGremlinTest {
- public VertexIdNotSupportedIdStrategyTest() {
- super(IdStrategy.build(idKey).supportsVertexId(false).create());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
- public void shouldInjectAnIdAndReturnBySpecifiedId() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Object o = GraphManager.getGraphProvider().convertId("1");
- final Vertex v = graph.addVertex(T.id, o, "something", "else");
- tryCommit(graph, c -> {
- assertNotNull(v);
- assertEquals(o, v.id());
- assertFalse(v.property(strategy.getIdKey()).isPresent());
- assertEquals("else", v.property("something").value());
-
- final Vertex found = g.V(o).next();
- assertEquals(o, found.id());
- assertFalse(found.property(strategy.getIdKey()).isPresent());
- assertEquals("else", found.property("something").value());
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
- public void shouldAllowDirectSettingOfIdField() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Object o = GraphManager.getGraphProvider().convertId("1");
- final Vertex v = graph.addVertex(T.id, o, "something", "else", strategy.getIdKey(), "should be ok to set this as supportsEdgeId=true");
- tryCommit(graph, c -> {
- assertNotNull(v);
- assertEquals(o, v.id());
- assertEquals("should be ok to set this as supportsEdgeId=true", v.property(strategy.getIdKey()).value());
- assertEquals("else", v.property("something").value());
-
- final Vertex found = g.V(o).next();
- assertEquals(o, found.id());
- assertEquals("should be ok to set this as supportsEdgeId=true", found.property(strategy.getIdKey()).value());
- assertEquals("else", found.property("something").value());
- });
-
- try {
- v.addEdge("self", v, T.id, o, "something", "else", strategy.getIdKey(), "this should toss and exception as supportsVertexId=false");
- fail("An exception should be tossed here because supportsEdgeId=true");
- } catch (IllegalArgumentException iae) {
- assertNotNull(iae);
- }
-
- try {
- final Edge e = v.addEdge("self", v, T.id, o, "something", "else");
- e.property(strategy.getIdKey(), "this should toss and exception as supportsVertexId=false");
- fail("An exception should be tossed here because supportsEdgeId=true");
- } catch (IllegalArgumentException iae) {
- assertNotNull(iae);
- }
- }
- }
-
- public static class EdgeIdNotSupportedIdStrategyTest extends AbstractGremlinTest {
- public EdgeIdNotSupportedIdStrategyTest() {
- super(IdStrategy.build(idKey).supportsEdgeId(false).create());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
- public void shouldInjectAnIdAndReturnBySpecifiedId() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex(T.id, "test", "something", "else");
- final Edge e = v.addEdge("self", v, T.id, "edge-id", "try", "this");
- tryCommit(graph, c -> {
- assertNotNull(e);
- assertEquals("edge-id", e.id());
- assertFalse(e.property(strategy.getIdKey()).isPresent());
- assertEquals("this", e.property("try").value());
-
- final Edge found = g.E("edge-id").next();
- assertEquals("edge-id", found.id());
- assertFalse(found.property(strategy.getIdKey()).isPresent());
- assertEquals("this", found.property("try").value());
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
- public void shouldAllowDirectSettingOfIdField() {
- final IdStrategy strategy = (IdStrategy) ((StrategyGraph) graph).getStrategy();
- final Vertex v = graph.addVertex(T.id, "test", "something", "else");
- final Edge e = v.addEdge("self", v, T.id, "edge-id", "try", "this", strategy.getIdKey(), "should be ok to set this as supportsEdgeId=false");
- tryCommit(graph, c -> {
- assertNotNull(e);
- assertEquals("edge-id", e.id());
- assertEquals("this", e.property("try").value());
- assertEquals("should be ok to set this as supportsEdgeId=false", e.property(strategy.getIdKey()).value());
-
- final Edge found = graph.edges("edge-id").next();
- assertEquals("edge-id", found.id());
- assertEquals("this", found.property("try").value());
- assertEquals("should be ok to set this as supportsEdgeId=false", found.property(strategy.getIdKey()).value());
- });
-
- try {
- graph.addVertex(T.id, "test", "something", "else", strategy.getIdKey(), "this should toss and exception as supportsVertexId=true");
- fail("An exception should be tossed here because supportsVertexId=true");
- } catch (IllegalArgumentException iae) {
- assertNotNull(iae);
- }
-
- try {
- v.property(strategy.getIdKey(), "this should toss and exception as supportsVertexId=true");
- fail("An exception should be tossed here because supportsVertexId=true");
- } catch (IllegalArgumentException iae) {
- assertNotNull(iae);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/PartitionStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/PartitionStrategyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/PartitionStrategyTest.java
deleted file mode 100644
index 3099d9c..0000000
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/PartitionStrategyTest.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.strategy;
-
-import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
-import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.junit.Test;
-
-import java.util.NoSuchElementException;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class PartitionStrategyTest extends AbstractGremlinTest {
- private static final String partition = "gremlin.partitionGraphStrategy.partition";
-
- public PartitionStrategyTest() {
- super(PartitionStrategy.build().partitionKey(partition).startPartition("A").create());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldAppendPartitionToVertex() {
- final Vertex v = graph.addVertex("any", "thing");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertEquals("A", ((StrategyVertex) v).getBaseVertex().property(partition).value());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldHidePartitionKeyOnVertex() {
- final Vertex v = graph.addVertex("any", "thing");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertFalse(v.property(partition).isPresent());
- assertFalse(v.properties(partition).hasNext());
- assertFalse(v.values(partition).hasNext());
- assertFalse(v.keys().contains(partition));
- assertEquals("A", ((StrategyVertex) v).getBaseVertex().property(partition).value());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldAppendPartitionToEdge() {
- final Vertex v1 = graph.addVertex("any", "thing");
- final Vertex v2 = graph.addVertex("some", "thing");
- final Edge e = v1.addEdge("connectsTo", v2, "every", "thing");
-
- assertNotNull(v1);
- assertEquals("thing", v1.property("any").value());
- assertEquals("A", ((StrategyVertex) v2).getBaseVertex().property(partition).value());
-
- assertNotNull(v2);
- assertEquals("thing", v2.property("some").value());
- assertEquals("A", ((StrategyVertex) v2).getBaseVertex().property(partition).value());
-
- assertNotNull(e);
- assertEquals("thing", e.property("every").value());
- assertEquals("connectsTo", e.label());
- assertEquals("A", ((StrategyEdge) e).getBaseEdge().property(partition).value());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldHidePartitionKeyOnEdge() {
- final Vertex v1 = graph.addVertex("any", "thing");
- final Vertex v2 = graph.addVertex("some", "thing");
- final Edge e = v1.addEdge("connectsTo", v2, "every", "thing");
-
- assertNotNull(e);
- assertEquals("thing", e.property("every").value());
- assertEquals("connectsTo", e.label());
- assertFalse(e.property(partition).isPresent());
- assertFalse(e.properties(partition).hasNext());
- assertFalse(e.values(partition).hasNext());
- assertFalse(e.keys().contains(partition));
- assertEquals("A", ((StrategyEdge) e).getBaseEdge().property(partition).value());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldWriteVerticesToMultiplePartitions() {
- final Vertex vA = graph.addVertex("any", "a");
- final PartitionStrategy strategy = (PartitionStrategy) ((StrategyGraph) graph).getStrategy();
- strategy.setWritePartition("B");
- final Vertex vB = graph.addVertex("any", "b");
-
- assertNotNull(vA);
- assertEquals("a", vA.property("any").value());
- assertEquals("A", ((StrategyVertex) vA).getBaseVertex().property(partition).value());
-
- assertNotNull(vB);
- assertEquals("b", vB.property("any").value());
- assertEquals("B", ((StrategyVertex) vB).getBaseVertex().property(partition).value());
-
- /* not applicable to SubgraphStrategy
- final GraphTraversal t = g.V();
- assertTrue(t.strategies().get().stream().anyMatch(o -> o.getClass().equals(PartitionGraphStrategy.PartitionGraphTraversalStrategy.class)));
- */
-
- g.V().forEachRemaining(v -> {
- assertTrue(v instanceof StrategyVertex);
- assertEquals("a", v.property("any").value());
- });
-
- strategy.removeReadPartition("A");
- strategy.addReadPartition("B");
-
- g.V().forEachRemaining(v -> {
- assertTrue(v instanceof StrategyVertex);
- assertEquals("b", v.property("any").value());
- });
-
- strategy.addReadPartition("A");
- assertEquals(new Long(2), g.V().count().next());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldThrowExceptionOnvInDifferentPartition() {
- final Vertex vA = graph.addVertex("any", "a");
- assertEquals(vA.id(), g.V(vA.id()).id().next());
-
- final PartitionStrategy strategy = (PartitionStrategy) ((StrategyGraph) graph).getStrategy();
- strategy.clearReadPartitions();
-
- try {
- g.V(vA.id());
- } catch (Exception ex) {
- final Exception expected = Graph.Exceptions.elementNotFound(Vertex.class, vA.id());
- assertEquals(expected.getClass(), ex.getClass());
- assertEquals(expected.getMessage(), ex.getMessage());
- }
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldThrowExceptionOneInDifferentPartition() {
- final Vertex vA = graph.addVertex("any", "a");
- final Edge e = vA.addEdge("knows", vA);
- assertEquals(e.id(), g.E(e.id()).id().next());
-
- final PartitionStrategy strategy = (PartitionStrategy) ((StrategyGraph) graph).getStrategy();
- strategy.clearReadPartitions();
-
- try {
- g.E(e.id());
- } catch (Exception ex) {
- final Exception expected = Graph.Exceptions.elementNotFound(Edge.class, e.id());
- assertEquals(expected.getClass(), ex.getClass());
- assertEquals(expected.getMessage(), ex.getMessage());
- }
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldWriteToMultiplePartitions() {
- final Vertex vA = graph.addVertex("any", "a");
- final Vertex vAA = graph.addVertex("any", "aa");
- final Edge eAtoAA = vA.addEdge("a->a", vAA);
-
- final PartitionStrategy strategy = (PartitionStrategy) ((StrategyGraph) graph).getStrategy();
- strategy.setWritePartition("B");
- final Vertex vB = graph.addVertex("any", "b");
- vA.addEdge("a->b", vB);
-
- strategy.setWritePartition("C");
- final Vertex vC = graph.addVertex("any", "c");
- final Edge eBtovC = vB.addEdge("b->c", vC);
- final Edge eAtovC = vA.addEdge("a->c", vC);
-
- strategy.clearReadPartitions();
- assertEquals(0, IteratorUtils.count(graph.vertices()));
- assertEquals(0, IteratorUtils.count(graph.edges()));
-
- strategy.addReadPartition("A");
- assertEquals(new Long(2), g.V().count().next());
- assertEquals(new Long(1), g.E().count().next());
- assertEquals(new Long(1), g.V(vA.id()).outE().count().next());
- assertEquals(eAtoAA.id(), g.V(vA.id()).outE().next().id());
- assertEquals(new Long(1), g.V(vA.id()).out().count().next());
- assertEquals(vAA.id(), g.V(vA.id()).out().next().id());
-
- final Vertex vA1 = g.V(vA.id()).next();
- assertEquals(1, IteratorUtils.count(vA1.edges(Direction.OUT)));
- assertEquals(eAtoAA.id(), vA1.edges(Direction.OUT).next().id());
- assertEquals(1, IteratorUtils.count(vA1.vertices(Direction.OUT)));
- assertEquals(vAA.id(), vA1.vertices(Direction.OUT).next().id());
-
- strategy.addReadPartition("B");
- assertEquals(new Long(3), g.V().count().next());
- assertEquals(new Long(2), g.E().count().next());
-
- strategy.addReadPartition("C");
- assertEquals(new Long(4), g.V().count().next());
- assertEquals(new Long(4), g.E().count().next());
-
- strategy.removeReadPartition("A");
- strategy.removeReadPartition("B");
-
- assertEquals(1, IteratorUtils.count(graph.vertices()));
- // two edges are in the "C" partition, but one each of their incident vertices are not
- assertEquals(0, IteratorUtils.count(graph.edges()));
-
- assertEquals(new Long(0), g.V(vC.id()).inE().count().next());
- assertEquals(new Long(0), g.V(vC.id()).in().count().next());
-
- strategy.addReadPartition("B");
- // only one edge in, due to excluded vertices; vA is not in {B,C}
- assertEquals(new Long(1), g.V(vC.id()).inE().count().next());
- assertEquals(new Long(1), g.V(vC.id()).in().count().next());
- assertEquals(vC.id(), g.E(eBtovC.id()).inV().id().next());
- assertEquals(vB.id(), g.E(eBtovC.id()).outV().id().next());
-
- try {
- g.E(eAtovC.id()).next();
- fail("Edge should not be in the graph because vA is not in partitions {B,C}");
- } catch (Exception ex) {
- assertTrue(ex instanceof NoSuchElementException);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategyTest.java
deleted file mode 100644
index 4d71355..0000000
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/ReadOnlyStrategyTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.strategy;
-
-import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
-import org.apache.tinkerpop.gremlin.FeatureRequirement;
-import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.util.function.ThrowingConsumer;
-import org.junit.Test;
-
-import static org.apache.tinkerpop.gremlin.structure.Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES;
-import static org.apache.tinkerpop.gremlin.structure.Graph.Features.VariableFeatures.FEATURE_VARIABLES;
-import static org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class ReadOnlyStrategyTest extends AbstractGremlinTest {
- public ReadOnlyStrategyTest() {
- }
-
- @Test
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ADD_VERTICES)
- public void shouldNotAllowAddVertex() {
- assertException(g -> g.addVertex());
- }
-
- @Test
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ADD_VERTICES)
- public void shouldNotAllowRemoveVertex() {
- graph.addVertex();
- assertException(g -> g.vertices().forEachRemaining(Vertex::remove));
- }
-
- @Test
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ADD_VERTICES)
- @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = FEATURE_ADD_EDGES)
- public void shouldNotAllowRemoveEdge() {
- final Vertex v = graph.addVertex();
- v.addEdge("friend", v);
- assertException(g -> {
- final Edge e = g.traversal().E().next();
- e.remove();
- });
- }
-
- @Test
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ADD_VERTICES)
- @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = FEATURE_ADD_EDGES)
- public void shouldNotAllowAddEdge() {
- graph.addVertex();
- assertException(g -> {
- final Vertex v = g.traversal().V().next();
- v.addEdge("friend", v);
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldNotAllowVertexSetProperties() {
- graph.addVertex();
- assertException(g -> g.traversal().V().next().<String>property("test", "test"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldNotAllowVertexSetProperty() {
- graph.addVertex();
- assertException(g -> g.traversal().V().next().<String>property("test", "test"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
- public void shouldNotAllowVertexPropertySetProperty() {
- graph.addVertex();
- assertException(g -> {
- final VertexProperty p = g.traversal().V().next().<String>property("test", "test");
- p.property("property", "on-a-property");
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldNotAllowEdgeSetProperties() {
- final Vertex v = graph.addVertex();
- v.addEdge("friend", v);
- assertException(g -> g.traversal().E().next().<String>property("test", "test"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldNotAllowEdgeSetProperty() {
- final Vertex v = graph.addVertex();
- v.addEdge("friend", v);
- assertException(g -> g.traversal().E().next().<String>property("test", "test"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldNotAllowVertexPropertyRemoval() {
- final Vertex v = graph.addVertex();
- v.property("test", "test");
- final Property<String> p = v.property("test");
- assertEquals("test", p.value());
-
- assertException(g -> {
- final VertexProperty<Object> prop = g.traversal().V().next().properties("test").next();
- prop.remove();
- });
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
- public void shouldNotAllowEdgePropertyRemoval() {
- final Vertex v = graph.addVertex();
- final Edge e = v.addEdge("friend", v);
- e.property("test", "test");
- final Property<String> p = e.property("test");
- assertEquals("test", p.value());
-
- assertException(g -> {
- final Property<String> prop = g.traversal().E().next().property("test");
- prop.remove();
- });
- }
-
- @Test
- @FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES)
- public void shouldNotAllowVariableModifications() {
- assertException(g -> {
- g.variables().set("will", "not work");
- });
- }
-
- @Test(expected = UnsupportedOperationException.class)
- @FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES)
- public void shouldNotAllowVariableAsMapModifications() {
- graph.variables().set("will", "be read-only");
- final StrategyGraph swg = graph.strategy(ReadOnlyStrategy.instance());
- swg.variables().asMap().put("will", "not work");
- }
-
- private void assertException(final ThrowingConsumer<Graph> stt) {
- try {
- final StrategyGraph swg = graph.strategy(ReadOnlyStrategy.instance());
- stt.accept(swg);
- fail();
- } catch (Exception ex) {
- final Exception expectedException = ReadOnlyStrategy.Exceptions.graphUsesReadOnlyStrategy();
- assertEquals(expectedException.getClass(), ex.getClass());
- assertEquals(expectedException.getMessage(), ex.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4da1081c/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/SequenceStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/SequenceStrategyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/SequenceStrategyTest.java
deleted file mode 100644
index c9bf3cb..0000000
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/SequenceStrategyTest.java
+++ /dev/null
@@ -1,703 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.strategy;
-
-import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
-import org.apache.tinkerpop.gremlin.FeatureRequirement;
-import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.util.function.TriFunction;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.junit.Test;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class SequenceStrategyTest extends AbstractGremlinTest {
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldOverwritePropertyValuesToVertex() {
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working1"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.remove("anonymous");
- o.remove("working1");
- o.addAll(Arrays.asList("anonymous", "working2"));
- o.addAll(Arrays.asList("try", "anything"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.remove("anonymous");
- o.remove("working2");
- o.addAll(Arrays.asList("anonymous", "working3"));
- return f.apply(o.toArray());
- };
- }
- }
- ).create());
-
- final Vertex v = swg.addVertex("any", "thing");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertEquals(1, IteratorUtils.list(v.values("anonymous")).size());
- assertTrue(IteratorUtils.list(v.values("anonymous")).contains("working3"));
- assertEquals("anything", v.property("try").value());
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldAllowForALocalGraphStrategyCallInSequence() {
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("ts", "timestamped"));
- return f.apply(o.toArray());
- };
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, VertexProperty<V>>> getVertexPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (k, v) -> {
- ctx.getCurrent().getBaseVertex().property("timestamp", "timestamped");
-
- // dynamically construct a strategy to force this call to addVertex to stay localized
- // to this GraphStrategy (i.e. the first GraphStrategy in the sequence is ignored)
- // note that this will not call GraphStrategy implementations after this one in the
- // sequence either
- final StrategyContext<StrategyGraph> innerCtx = new StrategyContext<>(ctx.getStrategyGraph(), ctx.getStrategyGraph());
- this.getAddVertexStrategy(innerCtx, composingStrategy)
- .apply(ctx.getStrategyGraph().getBaseGraph()::addVertex)
- .apply(Arrays.asList("strategy", "bypassed").toArray());
-
- return f.apply(k, v);
- };
- }
- }
- ).create());
-
- final Vertex v = swg.addVertex("any", "thing");
- v.property("set", "prop");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertEquals(1, IteratorUtils.list(v.values("anonymous")).size());
- assertTrue(IteratorUtils.list(v.values("ts")).contains("timestamped"));
- assertTrue(IteratorUtils.list(v.values("set")).contains("prop"));
-
- final Vertex vStrat = (Vertex) g.V().has("strategy", "bypassed").next();
- assertEquals(0, IteratorUtils.list(vStrat.values("anonymous")).size());
- assertTrue(IteratorUtils.list(v.values("ts")).contains("timestamped"));
- assertTrue(IteratorUtils.list(v.values("timestamp")).contains("timestamped"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldAllowForANeighborhoodGraphStrategyCallInSequence() {
- final SequenceStrategy innerSequenceStrategy = SequenceStrategy.build().sequence(new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("ts1", "timestamped"));
- return f.apply(o.toArray());
- };
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, VertexProperty<V>>> getVertexPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (k, v) -> {
- ctx.getCurrent().getBaseVertex().property("timestamp", "timestamped");
-
- // dynamically construct a strategy to force this call to addVertex to stay localized
- // to the innerSequenceGraphStrategy. note that this will only call GraphStrategy implementations
- // in this sequence
- final StrategyContext<StrategyGraph> innerCtx = new StrategyContext<>(ctx.getStrategyGraph(), ctx.getStrategyGraph());
- composingStrategy.getAddVertexStrategy(innerCtx, composingStrategy)
- .apply(ctx.getStrategyGraph().getBaseGraph()::addVertex)
- .apply(Arrays.asList("strategy", "bypassed").toArray());
-
- return f.apply(k, v);
- };
- }
- }, new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("ts2", "timestamped"));
- return f.apply(o.toArray());
- };
- }
- }).create();
-
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working"));
- return f.apply(o.toArray());
- };
- }
- },
- innerSequenceStrategy
- ).create());
-
- final Vertex v = swg.addVertex("any", "thing");
- v.property("set", "prop");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertEquals(1, IteratorUtils.list(v.values("anonymous")).size());
- assertTrue(IteratorUtils.list(v.values("ts1")).contains("timestamped"));
- assertTrue(IteratorUtils.list(v.values("ts2")).contains("timestamped"));
- assertTrue(IteratorUtils.list(v.values("set")).contains("prop"));
-
- final Vertex vStrat = (Vertex) g.V().has("strategy", "bypassed").next();
- assertEquals(0, IteratorUtils.list(vStrat.values("anonymous")).size());
- assertTrue(IteratorUtils.list(v.values("ts1")).contains("timestamped"));
- assertTrue(IteratorUtils.list(v.values("ts2")).contains("timestamped"));
- assertTrue(IteratorUtils.list(v.values("timestamp")).contains("timestamped"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldAlterArgumentsToAddVertexInOrderOfSequence() {
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working1"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.replaceAll(it -> it.equals("working1") ? "working2" : it);
- o.addAll(Arrays.asList("try", "anything"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return UnaryOperator.identity();
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.replaceAll(it -> it.equals("working2") ? "working3" : it);
- return f.apply(o.toArray());
- };
- }
- }
- ).create());
-
- final Vertex v = swg.addVertex("any", "thing");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertEquals("working3", v.property("anonymous").value());
- assertEquals("anything", v.property("try").value());
- }
-
- @Test(expected = RuntimeException.class)
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldShortCircuitStrategyWithException() {
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working1"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- throw new RuntimeException("test");
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working3"));
- return f.apply(o.toArray());
- };
- }
- }
- ).create());
-
- swg.addVertex("any", "thing");
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldShortCircuitStrategyWithNoOp() {
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working1"));
- return f.apply(o.toArray());
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- // if "f" is not applied then the next step and following steps won't process
- return (f) -> (args) -> null;
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working3"));
- return f.apply(o.toArray());
- };
- }
- }
- ).create());
-
- assertNull(swg.addVertex("any", "thing"));
- }
-
- @Test
- @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
- public void shouldDoSomethingBeforeAndAfter() {
- final StrategyGraph swg = graph.strategy(SequenceStrategy.build().sequence(
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final Vertex v = f.apply(args);
- // this means that the next strategy and those below it executed including
- // the implementation
- assertEquals("working2", v.property("anonymous").value());
- // now do something with that vertex after the fact
- v.properties("anonymous").forEachRemaining(Property::remove);
- v.property("anonymous", "working1");
- return v;
- };
-
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final Vertex v = f.apply(args);
- // this means that the next strategy and those below it executed including
- // the implementation
- assertEquals("working3", v.property("anonymous").value());
- // now do something with that vertex after the fact
- v.properties("anonymous").forEachRemaining(Property::remove);
- v.property("anonymous", "working2");
- return v;
- };
- }
- },
- new GraphStrategy() {
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext ctx, final GraphStrategy composingStrategy) {
- return (f) -> (args) -> {
- final List<Object> o = new ArrayList<>(Arrays.asList(args));
- o.addAll(Arrays.asList("anonymous", "working3"));
- return f.apply(o.toArray());
- };
- }
- }
- ).create());
-
- final Vertex v = swg.addVertex("any", "thing");
-
- assertNotNull(v);
- assertEquals("thing", v.property("any").value());
- assertEquals("working1", v.property("anonymous").value());
- }
-
- @Test
- public void shouldHaveAllMethodsImplemented() throws Exception {
- final Method[] methods = GraphStrategy.class.getDeclaredMethods();
- final SpyGraphStrategy spy = new SpyGraphStrategy();
- final SequenceStrategy strategy = SequenceStrategy.build().sequence(spy).create();
-
- // invoke all the strategy methods
- Stream.of(methods).forEach(method -> {
- try {
- method.invoke(strategy, new StrategyContext(new StrategyGraph(graph), new StrategyWrapped() {
- }), strategy);
- } catch (Exception ex) {
- ex.printStackTrace();
- fail("Should be able to invoke function");
- throw new RuntimeException("fail");
- }
- });
-
- // check the spy to see that all methods were executed
- assertEquals(methods.length, spy.getCount());
- }
-
- public class SpyGraphStrategy implements GraphStrategy {
-
- private int count = 0;
-
- public int getCount() {
- return count;
- }
-
- private UnaryOperator spy() {
- count++;
- return UnaryOperator.identity();
- }
-
- @Override
- public UnaryOperator<Function<Object[], Iterator<Vertex>>> getGraphIteratorsVertexIteratorStrategy(final StrategyContext<StrategyGraph> ctx, GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Function<Object[], Iterator<Edge>>> getGraphIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Function<Object[], Vertex>> getAddVertexStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<TriFunction<String, Vertex, Object[], Edge>> getAddEdgeStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Void>> getRemoveEdgeStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Void>> getRemoveVertexStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Void>> getRemovePropertyStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String, VertexProperty<V>>> getVertexGetPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String, Property<V>>> getEdgeGetPropertyStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, VertexProperty<V>>> getVertexPropertyStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<BiFunction<String, V, Property<V>>> getEdgePropertyStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Object>> getVertexIdStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Graph>> getVertexGraphStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Object>> getEdgeIdStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Graph>> getEdgeGraphStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<String>> getVertexLabelStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<String>> getEdgeLabelStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Set<String>>> getVertexKeysStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Set<String>>> getEdgeKeysStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String, V>> getVertexValueStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String, V>> getEdgeValueStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Set<String>>> getVariableKeysStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <R> UnaryOperator<Function<String, Optional<R>>> getVariableGetStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<BiConsumer<String, Object>> getVariableSetStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Consumer<String>> getVariableRemoveStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Map<String, Object>>> getVariableAsMapStrategy(final StrategyContext<StrategyVariables> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Supplier<Void>> getGraphCloseStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<VertexProperty<V>>>> getVertexIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<Property<V>>>> getEdgeIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<V>>> getVertexIteratorsValueIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Function<String[], Iterator<V>>> getEdgeIteratorsValueIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<BiFunction<Direction, String[], Iterator<Vertex>>> getVertexIteratorsVertexIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<BiFunction<Direction, String[], Iterator<Edge>>> getVertexIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyVertex> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Void>> getRemoveVertexPropertyStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Function<Direction, Iterator<Vertex>>> getEdgeIteratorsVertexIteratorStrategy(final StrategyContext<StrategyEdge> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Object>> getVertexPropertyIdStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<String>> getVertexPropertyLabelStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Graph>> getVertexPropertyGraphStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
-
- @Override
- public <V> UnaryOperator<Supplier<Set<String>>> getVertexPropertyKeysStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<Vertex>> getVertexPropertyGetElementStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V, U> UnaryOperator<BiFunction<String, V, Property<V>>> getVertexPropertyPropertyStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V, U> UnaryOperator<Function<String[], Iterator<Property<V>>>> getVertexPropertyIteratorsPropertyIteratorStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V, U> UnaryOperator<Function<String[], Iterator<V>>> getVertexPropertyIteratorsValueIteratorStrategy(final StrategyContext<StrategyVertexProperty<U>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Function<Object[], GraphTraversal<Vertex, Vertex>>> getGraphVStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public UnaryOperator<Function<Object[], GraphTraversal<Edge, Edge>>> getGraphEStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<V>> getVertexPropertyValueStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<V>> getPropertyValueStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<String>> getVertexPropertyKeyStrategy(final StrategyContext<StrategyVertexProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
-
- @Override
- public <V> UnaryOperator<Supplier<String>> getPropertyKeyStrategy(final StrategyContext<StrategyProperty<V>> ctx, final GraphStrategy composingStrategy) {
- return spy();
- }
- }
-}