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/04/09 20:44:07 UTC
incubator-tinkerpop git commit: Major refactoring of TinkerGraph to
get id management consistent. TINKERPOP3-581
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/TINKERPOP3-581 59028c8ad -> 3cc550e25
Major refactoring of TinkerGraph to get id management consistent. TINKERPOP3-581
Introduced an IdManager interface to help control id conversions and explicity id management within TinkerGraph. This allowed all tests to pass that involved the above refenced ticket. Still have a broken test in hadoop-graph to debug. Lots of cleanup to do yet.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/3cc550e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/3cc550e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/3cc550e2
Branch: refs/heads/TINKERPOP3-581
Commit: 3cc550e25b420df62612d9f7c86b4452d70706cd
Parents: 59028c8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 9 14:42:12 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 9 14:42:12 2015 -0400
----------------------------------------------------------------------
.../strategy/decoration/ElementIdStrategy.java | 8 +-
.../engine/GremlinExecutorPerformanceTest.java | 2 +-
.../gremlin/AbstractGraphProvider.java | 9 +-
.../tinkerpop/gremlin/AbstractGremlinSuite.java | 2 +-
.../tinkerpop/gremlin/AbstractGremlinTest.java | 13 +-
.../apache/tinkerpop/gremlin/GraphProvider.java | 23 ++-
.../generator/CommunityGeneratorTest.java | 4 +-
.../generator/DistributionGeneratorTest.java | 6 +-
.../traversal/step/sideEffect/SubgraphTest.java | 4 +-
.../structure/GraphConstructionTest.java | 4 +-
.../tinkerpop/gremlin/structure/GraphTest.java | 4 +-
.../tinkerpop/gremlin/structure/IoTest.java | 31 ++--
.../gremlin/structure/TransactionTest.java | 2 +-
.../gremlin/hadoop/structure/HadoopGraph.java | 45 ++++-
.../gremlin/hadoop/HadoopGraphProvider.java | 4 +-
.../tinkergraph/structure/TinkerGraph.java | 173 ++++++++++++++++---
.../tinkergraph/structure/TinkerHelper.java | 43 +----
.../tinkergraph/structure/TinkerVertex.java | 10 +-
.../structure/TinkerVertexProperty.java | 2 +-
.../tinkergraph/TinkerGraphProvider.java | 58 ++++++-
20 files changed, 307 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
index ec47787..d84073d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
@@ -80,13 +80,11 @@ public final class ElementIdStrategy extends AbstractTraversalStrategy {
// note that it is then only necessary to replace the step if the id is a non-element. other tests
// in the suite validate that items in getIds() is uniform so it is ok to just test the first item
// in the list.
- if (graphStep.getIds().length > 0) {
+ if (graphStep.getIds().length > 0 && !(graphStep.getIds()[0] instanceof Element)) {
if (graphStep instanceof HasContainerHolder) {
- if (!(graphStep.getIds()[0] instanceof Element))
- ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds())));
+ ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds())));
} else {
- if (!(graphStep.getIds()[0] instanceof Element))
- TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds()))), graphStep, traversal);
+ TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds()))), graphStep, traversal);
}
graphStep.clearIds();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorPerformanceTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorPerformanceTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorPerformanceTest.java
index 5378141..651aaab 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorPerformanceTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorPerformanceTest.java
@@ -68,7 +68,7 @@ public class GremlinExecutorPerformanceTest extends AbstractGremlinTest {
public void setup() throws Exception {
super.setup();
syntaxGraphConfig = graphProvider.newGraphConfiguration("gremlin-executor-test",
- GremlinExecutorPerformanceTest.class, testName.getMethodName());
+ GremlinExecutorPerformanceTest.class, testName.getMethodName(), null);
syntaxGraph = graphProvider.openTestGraph(syntaxGraphConfig);
generator = new GremlinGenerator(syntaxGraph, rand);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java
index b27ab72..8fe041b 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java
@@ -52,17 +52,19 @@ public abstract class AbstractGraphProvider implements GraphProvider {
* @param graphName a value that represents a unique configuration for a graph
* @param test the test class
* @param testMethodName the name of the test method
+ * @param loadGraphWith the data set to load and will be null if no data is to be loaded
* @return a configuration {@link java.util.Map} that should be unique per the {@code graphName}
*/
public abstract Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test,
- final String testMethodName);
+ final String testMethodName, final LoadGraphWith.GraphData loadGraphWith);
@Override
public Configuration newGraphConfiguration(final String graphName, final Class<?> test,
final String testMethodName,
- final Map<String, Object> configurationOverrides) {
+ final Map<String, Object> configurationOverrides,
+ final LoadGraphWith.GraphData loadGraphWith) {
final Configuration conf = new BaseConfiguration();
- getBaseConfiguration(graphName, test, testMethodName).entrySet().stream()
+ getBaseConfiguration(graphName, test, testMethodName, loadGraphWith).entrySet().stream()
.forEach(e -> conf.setProperty(e.getKey(), e.getValue()));
// assign overrides but don't allow gremlin.graph setting to be overridden. the test suite should
@@ -84,6 +86,7 @@ public abstract class AbstractGraphProvider implements GraphProvider {
}
}
+ // todo: these aren't used - remove???
protected static void deleteDirectory(final File directory) {
if (directory.exists()) {
for (File file : directory.listFiles()) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
index 4ab600f..3d02968 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinSuite.java
@@ -145,7 +145,7 @@ public abstract class AbstractGremlinSuite extends Suite {
final Set<Class> implementations = graphProvider.getImplementations();
final Set<Class> noImplementationRegistered = new HashSet<>();
- final Configuration conf = graphProvider.newGraphConfiguration("prototype", AbstractGremlinSuite.class, "validateStructureInterfacesRegistered");
+ final Configuration conf = graphProvider.newGraphConfiguration("prototype", AbstractGremlinSuite.class, "validateStructureInterfacesRegistered", null);
final Graph graph = graphProvider.openTestGraph(conf);
final Set<Class> structureInterfaces = new HashSet<>(STRUCTURE_INTERFACES);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/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 b1fcc42..7c17c4a 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
@@ -65,22 +65,22 @@ public abstract class AbstractGremlinTest {
@Before
public void setup() throws Exception {
+ final Method testMethod = this.getClass().getMethod(cleanMethodName(name.getMethodName()));
+ final LoadGraphWith[] loadGraphWiths = testMethod.getAnnotationsByType(LoadGraphWith.class);
+ final LoadGraphWith loadGraphWith = loadGraphWiths.length == 0 ? null : loadGraphWiths[0];
+ final LoadGraphWith.GraphData loadGraphWithData = null == loadGraphWith ? null : loadGraphWith.value();
+
graphProvider = GraphManager.getGraphProvider();
- config = graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName());
+ config = graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), loadGraphWithData);
// this should clear state from a previously unfinished test. since the graph does not yet exist,
// persisted graphs will likely just have their directories removed
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);
g = graphProvider.traversal(graph);
graphComputerClass = g.getGraphComputer().isPresent() ? Optional.of(g.getGraphComputer().get().getClass()) : Optional.empty();
- final Method testMethod = this.getClass().getMethod(cleanMethodName(name.getMethodName()));
-
- final LoadGraphWith[] loadGraphWiths = testMethod.getAnnotationsByType(LoadGraphWith.class);
-
// get feature requirements on the test method and add them to the list of ones to check
final FeatureRequirement[] featureRequirement = testMethod.getAnnotationsByType(FeatureRequirement.class);
final List<FeatureRequirement> frs = new ArrayList<>(Arrays.asList(featureRequirement));
@@ -110,7 +110,6 @@ public abstract class AbstractGremlinTest {
beforeLoadGraphWith(graph);
// load a graph with sample data if the annotation is present on the test
- final LoadGraphWith loadGraphWith = loadGraphWiths.length == 0 ? null : loadGraphWiths[0];
graphProvider.loadGraphData(graph, loadGraphWith, this.getClass(), name.getMethodName());
afterLoadGraphWith(graph);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/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 da355b9..3b80820 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
@@ -104,17 +104,17 @@ public interface GraphProvider {
/**
* Creates a new {@link org.apache.tinkerpop.gremlin.structure.Graph} instance using the default
- * {@link org.apache.commons.configuration.Configuration} from {@link #standardGraphConfiguration(Class, String)}.
+ * {@link org.apache.commons.configuration.Configuration} from {@link #standardGraphConfiguration(Class, String, LoadGraphWith.GraphData)}.
* The default implementation converts the passes the
*/
- default public Graph standardTestGraph(final Class<?> test, final String testMethodName) {
- return GraphFactory.open(standardGraphConfiguration(test, testMethodName));
+ default public Graph standardTestGraph(final Class<?> test, final String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
+ return GraphFactory.open(standardGraphConfiguration(test, testMethodName, loadGraphWith));
}
/**
* 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
+ * has been created by one of the {@link #newGraphConfiguration(String, Class, String, LoadGraphWith.GraphData)} methods and has therefore
* already been modified by the implementation as necessary for {@link Graph} creation.
*/
default public Graph openTestGraph(final Configuration config) {
@@ -127,8 +127,8 @@ public interface GraphProvider {
* should always return a configuration instance that generates the same {@link org.apache.tinkerpop.gremlin.structure.Graph} from the
* {@link org.apache.tinkerpop.gremlin.structure.util.GraphFactory}.
*/
- default public Configuration standardGraphConfiguration(final Class<?> test, final String testMethodName) {
- return newGraphConfiguration("standard", test, testMethodName, Collections.<String, Object>emptyMap());
+ default public Configuration standardGraphConfiguration(final Class<?> test, final String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
+ return newGraphConfiguration("standard", test, testMethodName, Collections.<String, Object>emptyMap(), loadGraphWith);
}
/**
@@ -179,11 +179,13 @@ public interface GraphProvider {
* @param test the test class
* @param testMethodName the name of the test
* @param configurationOverrides settings to override defaults with.
+ * @param loadGraphWith the data set to load and will be null if no data is to be loaded
*/
public Configuration newGraphConfiguration(final String graphName,
final Class<?> test,
final String testMethodName,
- final Map<String, Object> configurationOverrides);
+ final Map<String, Object> configurationOverrides,
+ final LoadGraphWith.GraphData loadGraphWith);
/**
* When implementing this method ensure that a test suite can override any settings EXCEPT the
@@ -193,11 +195,13 @@ public interface GraphProvider {
* @param graphName a unique test graph name
* @param test the test class
* @param testMethodName the name of the test
+ * @param loadGraphWith the data set to load and will be null if no data is to be loaded
*/
default public Configuration newGraphConfiguration(final String graphName,
final Class<?> test,
- final String testMethodName) {
- return newGraphConfiguration(graphName, test, testMethodName, new HashMap<>());
+ final String testMethodName,
+ final LoadGraphWith.GraphData loadGraphWith) {
+ return newGraphConfiguration(graphName, test, testMethodName, new HashMap<>(), loadGraphWith);
}
/**
@@ -231,6 +235,7 @@ public interface GraphProvider {
* @return The reconstituted identifier.
*/
public default <ID> ID reconstituteGraphSONIdentifier(final Class<? extends Element> clazz, final Object id) {
+ // todo: do we still need this?
return (ID) id;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/CommunityGeneratorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/CommunityGeneratorTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/CommunityGeneratorTest.java
index 8414bd5..7102ce5 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/CommunityGeneratorTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/CommunityGeneratorTest.java
@@ -82,7 +82,7 @@ public class CommunityGeneratorTest {
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldGenerateDifferentGraph() throws Exception {
- final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
final Graph graph1 = graphProvider.openTestGraph(configuration);
try {
@@ -111,7 +111,7 @@ public class CommunityGeneratorTest {
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldGenerateSameGraph() throws Exception {
- final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
final Graph graph1 = graphProvider.openTestGraph(configuration);
try {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/DistributionGeneratorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/DistributionGeneratorTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/DistributionGeneratorTest.java
index d0f3d96..2ca996c 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/DistributionGeneratorTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/algorithm/generator/DistributionGeneratorTest.java
@@ -75,10 +75,10 @@ public class DistributionGeneratorTest {
// try this a few times because it's possible that the distribution generator is not random enough.
// if it doesn't generate a random one after 5 times then there must be a problem
do {
- final Configuration configuration1 = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName());
+ final Configuration configuration1 = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
final Graph g1 = graphProvider.openTestGraph(configuration1);
- final Configuration configuration2 = graphProvider.newGraphConfiguration("g2", this.getClass(), name.getMethodName());
+ final Configuration configuration2 = graphProvider.newGraphConfiguration("g2", this.getClass(), name.getMethodName(), null);
final Graph g2 = graphProvider.openTestGraph(configuration2);
try {
@@ -112,7 +112,7 @@ public class DistributionGeneratorTest {
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldGenerateSameGraph() throws Exception {
- final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
final Graph g1 = graphProvider.openTestGraph(configuration);
try {
final Iterable<Vertex> vordered = verticesByOid(graph);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SubgraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SubgraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SubgraphTest.java
index 14f905b..99aae9f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SubgraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SubgraphTest.java
@@ -55,7 +55,7 @@ public abstract class SubgraphTest extends AbstractGremlinProcessTest {
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
public void g_V_withSideEffectXsgX_outEXknowsX_subgraphXsgX_name_capXsgX() throws Exception {
- final Configuration config = graphProvider.newGraphConfiguration("subgraph", this.getClass(), name.getMethodName());
+ final Configuration config = graphProvider.newGraphConfiguration("subgraph", this.getClass(), name.getMethodName(), MODERN);
graphProvider.clear(config);
Graph subgraph = graphProvider.openTestGraph(config);
/////
@@ -87,7 +87,7 @@ public abstract class SubgraphTest extends AbstractGremlinProcessTest {
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
public void g_V_withSideEffectXsgX_repeatXbothEXcreatedX_subgraphXsgX_outVX_timesX5X_name_dedup() throws Exception {
- final Configuration config = graphProvider.newGraphConfiguration("subgraph", this.getClass(), name.getMethodName());
+ final Configuration config = graphProvider.newGraphConfiguration("subgraph", this.getClass(), name.getMethodName(), MODERN);
graphProvider.clear(config);
final Graph subgraph = graphProvider.openTestGraph(config);
/////
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphConstructionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphConstructionTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphConstructionTest.java
index bfde55e..2131159 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphConstructionTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphConstructionTest.java
@@ -43,7 +43,7 @@ public class GraphConstructionTest extends AbstractGremlinTest {
@Test
public void shouldOpenGraphThroughGraphFactoryViaApacheConfig() throws Exception {
final Graph expectedGraph = graph;
- final Configuration c = graphProvider.newGraphConfiguration("temp1", this.getClass(), name.getMethodName());
+ final Configuration c = graphProvider.newGraphConfiguration("temp1", this.getClass(), name.getMethodName(), null);
final Graph createdGraph = GraphFactory.open(c);
assertNotNull(createdGraph);
@@ -65,7 +65,7 @@ public class GraphConstructionTest extends AbstractGremlinTest {
*/
@Test
public void shouldMaintainOriginalConfigurationObjectGivenToFactory() {
- final Configuration originalConfig = graphProvider.newGraphConfiguration("temp2", this.getClass(), name.getMethodName());
+ final Configuration originalConfig = graphProvider.newGraphConfiguration("temp2", this.getClass(), name.getMethodName(), null);
final Graph createdGraph = GraphFactory.open(originalConfig);
final Configuration configInGraph = createdGraph.configuration();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
index d5c63e8..f19902f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/GraphTest.java
@@ -1011,7 +1011,7 @@ public class GraphTest extends AbstractGremlinTest {
tryCommit(graph, assertVertexEdgeCounts(2, 1));
graph.close();
- final Graph reopenedGraph = graphProvider.standardTestGraph(this.getClass(), name.getMethodName());
+ final Graph reopenedGraph = graphProvider.standardTestGraph(this.getClass(), name.getMethodName(), null);
assertVertexEdgeCounts(2, 1).accept(reopenedGraph);
if (graph.features().vertex().properties().supportsStringValues()) {
@@ -1026,6 +1026,6 @@ public class GraphTest extends AbstractGremlinTest {
assertEquals("internet", edge.property("location").value());
});
- graphProvider.clear(reopenedGraph, graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName()));
+ graphProvider.clear(reopenedGraph, graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), null));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
index c3041f7..17170fc 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
@@ -76,6 +76,7 @@ import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@@ -160,7 +161,7 @@ public class IoTest extends AbstractGremlinTest {
try {
graph.io().writeGraphML(f.getAbsolutePath());
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.CLASSIC);
final Graph g1 = graphProvider.openTestGraph(configuration);
g1.io().readGraphML(f.getAbsolutePath());
@@ -245,8 +246,7 @@ public class IoTest extends AbstractGremlinTest {
validateXmlAgainstGraphMLXsd(f);
// reusing the same config used for creation of "g".
- final Configuration configuration = graphProvider.newGraphConfiguration(
- "g2", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("g2", this.getClass(), name.getMethodName(), null);
graphProvider.clear(configuration);
final Graph g2 = graphProvider.openTestGraph(configuration);
final GraphMLReader r = GraphMLReader.build().create();
@@ -290,8 +290,7 @@ public class IoTest extends AbstractGremlinTest {
assertEquals("AF4B5965-B176-4552-B3C1-FBBE2F52C305".toLowerCase(), idValue.get("elementId").asText());
// reusing the same config used for creation of "g".
- final Configuration configuration = graphProvider.newGraphConfiguration(
- "g2", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("g2", this.getClass(), name.getMethodName(), null);
graphProvider.clear(configuration);
final Graph g2 = graphProvider.openTestGraph(configuration);
@@ -322,7 +321,7 @@ public class IoTest extends AbstractGremlinTest {
final GryoWriter writer = GryoWriter.build().mapper(gryo).create();
final GryoReader reader = GryoReader.build().workingDirectory(tempPath).mapper(gryo).create();
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), null);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
@@ -342,7 +341,7 @@ public class IoTest extends AbstractGremlinTest {
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldMigrateGraphWithFloat() throws Exception {
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), null);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
@@ -362,7 +361,7 @@ public class IoTest extends AbstractGremlinTest {
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldMigrateGraph() throws Exception {
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
@@ -389,7 +388,7 @@ public class IoTest extends AbstractGremlinTest {
final GryoWriter writer = graph.io().gryoWriter().create();
writer.writeGraph(os, graph);
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
final GryoReader reader = graph.io().gryoReader().workingDirectory(tempPath).create();
@@ -416,7 +415,7 @@ public class IoTest extends AbstractGremlinTest {
try {
graph.io().writeGryo(f.getAbsolutePath());
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
final Graph g1 = graphProvider.openTestGraph(configuration);
g1.io().readGryo(f.getAbsolutePath());
@@ -443,7 +442,7 @@ public class IoTest extends AbstractGremlinTest {
final GryoWriter writer = graph.io().gryoWriter().create();
writer.writeGraph(os, graph);
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.CREW);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
final GryoReader reader = GryoReader.build()
@@ -473,7 +472,7 @@ public class IoTest extends AbstractGremlinTest {
final GryoWriter writer = graph.io().gryoWriter().create();
writer.writeGraph(os, graph);
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.CLASSIC);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
final GryoReader reader = graph.io().gryoReader().workingDirectory(tempPath).create();
@@ -497,7 +496,7 @@ public class IoTest extends AbstractGremlinTest {
final GraphSONWriter writer = graph.io().graphSONWriter().create();
writer.writeGraph(os, graph);
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.CLASSIC);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
final GraphSONReader reader = graph.io().graphSONReader().create();
@@ -521,7 +520,7 @@ public class IoTest extends AbstractGremlinTest {
final GraphSONWriter writer = graph.io().graphSONWriter().create();
writer.writeGraph(os, graph);
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
final GraphSONReader reader = graph.io().graphSONReader().create();
@@ -545,7 +544,7 @@ public class IoTest extends AbstractGremlinTest {
try {
graph.io().writeGraphSON(f.getAbsolutePath());
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
g1.io().readGraphSON(f.getAbsolutePath());
@@ -571,7 +570,7 @@ public class IoTest extends AbstractGremlinTest {
final GraphSONWriter writer = graph.io().graphSONWriter().create();
writer.writeGraph(os, graph);
- final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.CREW);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
final GraphSONReader reader = graph.io().graphSONReader().create();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
index 24dc683..c1be0c1 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
@@ -449,7 +449,7 @@ public class TransactionTest extends AbstractGremlinTest {
// the idea behind this test is to simulate a gremlin-server environment where two graphs of the same type
// are being mutated by multiple threads. originally replicated a bug that was part of OrientDB.
- final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName());
+ final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
graphProvider.clear(configuration);
final Graph g1 = graphProvider.openTestGraph(configuration);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
index 5355e33..e1fa5b3 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/HadoopGraph.java
@@ -40,8 +40,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.util.Collections;
import java.util.Iterator;
+import java.util.Objects;
import java.util.Optional;
+import java.util.stream.Stream;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -201,7 +204,26 @@ public class HadoopGraph implements Graph {
@Override
public Iterator<Vertex> vertices(final Object... vertexIds) {
try {
- return 0 == vertexIds.length ? new HadoopVertexIterator(this) : IteratorUtils.filter(new HadoopVertexIterator(this), vertex -> ElementHelper.idExists(vertex.id(), vertexIds));
+ if (0 == vertexIds.length) {
+ return new HadoopVertexIterator(this);
+ } else {
+ // base the conversion function on the first item in the id list as the expectation is that these
+ // id values will be a uniform list
+ if (vertexIds[0] instanceof Vertex) {
+ // based on the first item assume all vertices in the argument list
+ if (!Stream.of(vertexIds).allMatch(id -> id instanceof Vertex))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+
+ // no need to get the vertices again, so just flip it back - some implementation may want to treat this
+ // as a refresh operation. that's not necessary for hadoopgraph.
+ return Stream.of(vertexIds).map(id -> (Vertex) id).iterator();
+ } else {
+ final Class<?> firstClass = vertexIds[0].getClass();
+ if (!Stream.of(vertexIds).map(Object::getClass).allMatch(firstClass::equals))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); // todo: change exception to be ids of the same type
+ return IteratorUtils.filter(new HadoopVertexIterator(this), vertex -> ElementHelper.idExists(vertex.id(), vertexIds));
+ }
+ }
} catch (final IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
@@ -210,7 +232,26 @@ public class HadoopGraph implements Graph {
@Override
public Iterator<Edge> edges(final Object... edgeIds) {
try {
- return 0 == edgeIds.length ? new HadoopEdgeIterator(this) : IteratorUtils.filter(new HadoopEdgeIterator(this), edge -> ElementHelper.idExists(edge.id(), edgeIds));
+ if (0 == edgeIds.length) {
+ return new HadoopEdgeIterator(this);
+ } else {
+ // base the conversion function on the first item in the id list as the expectation is that these
+ // id values will be a uniform list
+ if (edgeIds[0] instanceof Edge) {
+ // based on the first item assume all Edges in the argument list
+ if (!Stream.of(edgeIds).allMatch(id -> id instanceof Edge))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
+
+ // no need to get the vertices again, so just flip it back - some implementation may want to treat this
+ // as a refresh operation. that's not necessary for hadoopgraph.
+ return Stream.of(edgeIds).map(id -> (Edge) id).iterator();
+ } else {
+ final Class<?> firstClass = edgeIds[0].getClass();
+ if (!Stream.of(edgeIds).map(Object::getClass).allMatch(firstClass::equals))
+ throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); // todo: change exception to be ids of the same type
+ return IteratorUtils.filter(new HadoopEdgeIterator(this), vertex -> ElementHelper.idExists(vertex.id(), edgeIds));
+ }
+ }
} catch (final IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGraphProvider.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGraphProvider.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGraphProvider.java
index b8ba425..d8615bc 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGraphProvider.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGraphProvider.java
@@ -24,7 +24,6 @@ import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.tinkerpop.gremlin.AbstractGraphProvider;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.TestHelper;
-import org.apache.tinkerpop.gremlin.hadoop.process.computer.giraph.GiraphGraphComputer;
import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopEdge;
import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopElement;
import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph;
@@ -33,7 +32,6 @@ import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopProperty;
import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopVertex;
import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopVertexProperty;
import org.apache.tinkerpop.gremlin.hadoop.structure.io.graphson.GraphSONInputFormat;
-import org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoInputFormat;
import org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoOutputFormat;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONResourceAccess;
@@ -98,7 +96,7 @@ public class HadoopGraphProvider extends AbstractGraphProvider {
}
@Override
- public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName) {
+ public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
return new HashMap<String, Object>() {{
put(Graph.GRAPH, HadoopGraph.class.getName());
put(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT, GraphSONInputFormat.class.getCanonicalName());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index 71d3eba..4acbf66 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -39,11 +39,9 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
@@ -73,6 +71,10 @@ public class TinkerGraph implements Graph {
this.setProperty(Graph.GRAPH, TinkerGraph.class.getName());
}};
+ public static final String CONFIG_VERTEX_ID = "tinkergraph.vertex.id";
+ public static final String CONFIG_EDGE_ID = "tinkergraph.edge.id";
+ public static final String CONFIG_VERTEX_PROPERTY_ID = "tinkergraph.vertex-property.id";
+
protected Long currentId = -1l;
protected Map<Object, Vertex> vertices = new ConcurrentHashMap<>();
protected Map<Object, Edge> edges = new ConcurrentHashMap<>();
@@ -82,16 +84,52 @@ public class TinkerGraph implements Graph {
protected TinkerIndex<TinkerVertex> vertexIndex = null;
protected TinkerIndex<TinkerEdge> edgeIndex = null;
- private final static TinkerGraph EMPTY_GRAPH = new TinkerGraph();
+ private final static TinkerGraph EMPTY_GRAPH = new TinkerGraph(EMPTY_CONFIGURATION);
+
+ protected IdManager<?> vertexIdManager;
+ protected IdManager<?> edgeIdManager;
+ protected IdManager<?> vertexPropertyIdManager;
- protected Class<?> vertexIdClass = null;
- protected Class<?> edgeIdClass = null;
- protected Class<?> vertexPropertyIdClass = null;
+ private final Configuration configuration;
/**
* An empty private constructor that initializes {@link TinkerGraph}.
*/
- private TinkerGraph() {
+ private TinkerGraph(final Configuration configuration) {
+ this.configuration = configuration;
+
+ final String vertexIdManagerConfigValue = configuration.getString(CONFIG_VERTEX_ID, DefaultIdManager.ANY.name());
+ try {
+ vertexIdManager = DefaultIdManager.valueOf(vertexIdManagerConfigValue);
+ } catch (IllegalArgumentException iae) {
+ try {
+ vertexIdManager = (IdManager) Class.forName(vertexIdManagerConfigValue).newInstance();
+ } catch (Exception ex) {
+ throw new IllegalStateException(String.format("Could not configure TinkerGraph vertex id manager with %s", vertexIdManagerConfigValue));
+ }
+ }
+
+ final String edgeIdManagerConfigValue = configuration.getString(CONFIG_EDGE_ID, DefaultIdManager.ANY.name());
+ try {
+ edgeIdManager = DefaultIdManager.valueOf(edgeIdManagerConfigValue);
+ } catch (IllegalArgumentException iae) {
+ try {
+ edgeIdManager = (IdManager) Class.forName(edgeIdManagerConfigValue).newInstance();
+ } catch (Exception ex) {
+ throw new IllegalStateException(String.format("Could not configure TinkerGraph edge id manager with %s", edgeIdManagerConfigValue));
+ }
+ }
+
+ final String vertexPropIdManagerConfigValue = configuration.getString(CONFIG_VERTEX_PROPERTY_ID, DefaultIdManager.ANY.name());
+ try {
+ vertexPropertyIdManager = DefaultIdManager.valueOf(vertexPropIdManagerConfigValue);
+ } catch (IllegalArgumentException iae) {
+ try {
+ vertexPropertyIdManager = (IdManager) Class.forName(vertexPropIdManagerConfigValue).newInstance();
+ } catch (Exception ex) {
+ throw new IllegalStateException(String.format("Could not configure TinkerGraph vertex property id manager with %s", vertexPropIdManagerConfigValue));
+ }
+ }
}
public static TinkerGraph empty() {
@@ -107,7 +145,7 @@ public class TinkerGraph implements Graph {
* Test Suite.
*/
public static TinkerGraph open() {
- return open(null);
+ return open(EMPTY_CONFIGURATION);
}
/**
@@ -126,7 +164,7 @@ public class TinkerGraph implements Graph {
* @return a newly opened {@link org.apache.tinkerpop.gremlin.structure.Graph}
*/
public static TinkerGraph open(final Configuration configuration) {
- return new TinkerGraph();
+ return new TinkerGraph(configuration);
}
////////////// STRUCTURE API METHODS //////////////////
@@ -141,16 +179,7 @@ public class TinkerGraph implements Graph {
if (this.vertices.containsKey(idValue))
throw Exceptions.vertexWithIdAlreadyExists(idValue);
} else {
- idValue = TinkerHelper.getNextId(this, Vertex.class);
- }
-
- // todo: enforce vertex id consistency with tests
- // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
- // if there is a value, ensure that the expected type matches what was provided.
- if (null == vertexIdClass)
- vertexIdClass = idValue.getClass();
- else if (!idValue.getClass().equals(vertexIdClass)) {
- throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", vertexIdClass, idValue.getClass()));
+ idValue = vertexIdManager.getNextId(this);
}
final Vertex vertex = new TinkerVertex(idValue, label, this);
@@ -205,12 +234,13 @@ public class TinkerGraph implements Graph {
@Override
public Configuration configuration() {
- return EMPTY_CONFIGURATION;
+ return configuration;
}
@Override
public Iterator<Vertex> vertices(final Object... vertexIds) {
// todo: this code looks a lot like edges() code - better reuse here somewhere?
+ // todo: what if we have Reference/DetachedVertex???????????????????????????
if (0 == vertexIds.length) {
return this.vertices.values().iterator();
} else if (1 == vertexIds.length) {
@@ -220,8 +250,7 @@ public class TinkerGraph implements Graph {
return IteratorUtils.of((Vertex) vertexIds[0]);
} else {
// convert the id to the expected data type and lookup the vertex
- final UnaryOperator<Object> conversionFunction = convertToId(vertexIds[0], vertexIdClass);
- final Vertex vertex = this.vertices.get(conversionFunction.apply(vertexIds[0]));
+ final Vertex vertex = this.vertices.get(vertexIdManager.convert(vertexIds[0]));
return null == vertex ? Collections.emptyIterator() : IteratorUtils.of(vertex);
}
} else {
@@ -239,8 +268,7 @@ public class TinkerGraph implements Graph {
final Class<?> firstClass = vertexIds[0].getClass();
if (!Stream.of(vertexIds).map(Object::getClass).allMatch(firstClass::equals))
throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); // todo: change exception to be ids of the same type
- final UnaryOperator<Object> conversionFunction = convertToId(vertexIds[0], vertexIdClass);
- return Stream.of(vertexIds).map(conversionFunction).map(this.vertices::get).filter(Objects::nonNull).iterator();
+ return Stream.of(vertexIds).map(vertexIdManager::convert).map(this.vertices::get).filter(Objects::nonNull).iterator();
}
}
}
@@ -256,8 +284,7 @@ public class TinkerGraph implements Graph {
return IteratorUtils.of((Edge) edgeIds[0]);
} else {
// convert the id to the expected data type and lookup the vertex
- final UnaryOperator<Object> conversionFunction = convertToId(edgeIds[0], edgeIdClass);
- final Edge edge = this.edges.get(conversionFunction.apply(edgeIds[0]));
+ final Edge edge = this.edges.get(edgeIdManager.convert(edgeIds[0]));
return null == edge ? Collections.emptyIterator() : IteratorUtils.of(edge);
}
} else {
@@ -275,8 +302,7 @@ public class TinkerGraph implements Graph {
final Class<?> firstClass = edgeIds[0].getClass();
if (!Stream.of(edgeIds).map(Object::getClass).allMatch(firstClass::equals))
throw Graph.Exceptions.idArgsMustBeEitherIdOrElement(); // todo: change exception to be ids of the same type
- final UnaryOperator<Object> conversionFunction = convertToId(edgeIds[0], vertexIdClass);
- return Stream.of(edgeIds).map(conversionFunction).map(this.edges::get).filter(Objects::nonNull).iterator();
+ return Stream.of(edgeIds).map(edgeIdManager::convert).map(this.edges::get).filter(Objects::nonNull).iterator();
}
}
}
@@ -464,4 +490,95 @@ public class TinkerGraph implements Graph {
return UnaryOperator.identity();
}
+
+ public interface IdManager<T> {
+ T getNextId(final TinkerGraph graph);
+ Class<? extends T> getIdClass();
+ T convert(final Object o);
+ }
+
+ public enum DefaultIdManager implements IdManager {
+ LONG {
+ private long currentId = -1l;
+ @Override
+ public Long getNextId(final TinkerGraph graph) {
+ return Stream.generate(() -> (++currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+ }
+
+ @Override
+ public Class<? extends Long> getIdClass() {
+ return Long.class;
+ }
+
+ @Override
+ public Object convert(final Object o) {
+ if (o instanceof Number)
+ return ((Number) o).longValue();
+ else if (o instanceof String)
+ return Long.parseLong((String) o);
+ else
+ throw new IllegalArgumentException("Expected an id that is convertible to Long");
+ }
+ },
+ INTEGER {
+ private int currentId = -1;
+ @Override
+ public Integer getNextId(final TinkerGraph graph) {
+ return Stream.generate(() -> (++currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+ }
+
+ @Override
+ public Class<? extends Integer> getIdClass() {
+ return Integer.class;
+ }
+
+ @Override
+ public Object convert(final Object o) {
+ if (o instanceof Number)
+ return ((Number) o).intValue();
+ else if (o instanceof String)
+ return Integer.parseInt((String) o);
+ else
+ throw new IllegalArgumentException("Expected an id that is convertible to Integer");
+ }
+ },
+ UUID {
+ @Override
+ public UUID getNextId(final TinkerGraph graph) {
+ return java.util.UUID.randomUUID();
+ }
+
+ @Override
+ public Class<? extends UUID> getIdClass() {
+ return java.util.UUID.class;
+ }
+
+ @Override
+ public Object convert(final Object o) {
+ if (o instanceof java.util.UUID)
+ return o;
+ else if (o instanceof String)
+ return java.util.UUID.fromString((String) o);
+ else
+ throw new IllegalArgumentException("Expected an id that is convertible to UUID");
+ }
+ },
+ ANY {
+ private long currentId = -1l;
+ @Override
+ public Long getNextId(final TinkerGraph graph) {
+ return Stream.generate(() -> (++currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
+ }
+
+ @Override
+ public Class<? extends Object> getIdClass() {
+ return Object.class;
+ }
+
+ @Override
+ public Object convert(final Object o) {
+ return o;
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
index 1b1311e..08570c8 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
@@ -21,7 +21,6 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -47,37 +46,6 @@ public final class TinkerHelper {
private TinkerHelper() {
}
- protected final synchronized static Number getNextId(final TinkerGraph graph, final Class<? extends Element> element) {
- final Class<?> idClass;
- if (Vertex.class.isAssignableFrom(element))
- idClass = graph.vertexIdClass;
- else if (Edge.class.isAssignableFrom(element))
- idClass = graph.edgeIdClass;
- else if (VertexProperty.class.isAssignableFrom(element))
- idClass = graph.vertexPropertyIdClass;
- else
- throw new IllegalArgumentException(String.format("Unexpected request for id for %s", element));
-
- final Number next = Stream.generate(() -> (++graph.currentId)).filter(id -> !graph.vertices.containsKey(id) && !graph.edges.containsKey(id)).findAny().get();
-
- // the class hasn't been set yet so assume Long - the class should be set by the caller after this
- // value is returned
- if (null == idClass)
- return next.longValue();
-
- if (idClass.equals(Long.class))
- return next.longValue();
- else if (idClass.equals(Integer.class))
- return next.intValue();
- else if (idClass.equals(Double.class))
- return next.doubleValue();
- else if (idClass.equals(Float.class))
- return next.floatValue();
- else
- throw new IllegalStateException(String.format("TinkerGraph generates numeric identifiers, but this instance has already been initialized a identifier of type %s for %s", idClass, element));
-
- }
-
protected static Edge addEdge(final TinkerGraph graph, final TinkerVertex outVertex, final TinkerVertex inVertex, final String label, final Object... keyValues) {
ElementHelper.validateLabel(label);
ElementHelper.legalPropertyKeyValueArray(keyValues);
@@ -89,16 +57,7 @@ public final class TinkerHelper {
if (graph.edges.containsKey(idValue))
throw Graph.Exceptions.edgeWithIdAlreadyExists(idValue);
} else {
- idValue = TinkerHelper.getNextId(graph, Edge.class);
- }
-
- // todo: enforce edge id consistency with tests
- // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
- // if there is a value, ensure that the expected type matches what was provided.
- if (null == graph.edgeIdClass)
- graph.edgeIdClass = idValue.getClass();
- else if (!idValue.getClass().equals(graph.edgeIdClass)) {
- throw new IllegalStateException(String.format("Expecting a edge identifier of %s but was %s", graph.edgeIdClass, idValue.getClass()));
+ idValue = graph.edgeIdManager.getNextId(graph);
}
edge = new TinkerEdge(idValue, outVertex, label, inVertex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
index a5713cc..e9a4632 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
@@ -96,15 +96,7 @@ public class TinkerVertex extends TinkerElement implements Vertex {
ElementHelper.attachProperties(vertexProperty, keyValues);
return vertexProperty;
} else {
- final Object idValue = optionalId.isPresent() ? optionalId.get() : TinkerHelper.getNextId(graph, VertexProperty.class);
-
- // todo: enforce vertexproperty id consistency with tests
- // if no value is defined on the graph for the expected id type then use whatever is currently set, otherwise
- // if there is a value, ensure that the expected type matches what was provided.
- if (null == graph.vertexPropertyIdClass)
- graph.vertexPropertyIdClass = idValue.getClass();
- else if (!idValue.getClass().equals(graph.vertexPropertyIdClass))
- throw new IllegalStateException(String.format("Expecting a vertex identifier of %s but was %s", graph.vertexPropertyIdClass, idValue.getClass()));
+ final Object idValue = optionalId.isPresent() ? optionalId.get() : graph.vertexPropertyIdManager.getNextId(graph);
final VertexProperty<V> vertexProperty = new TinkerVertexProperty<V>(idValue, this, key, value);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
index 2470733..0a8d3f3 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
@@ -52,7 +52,7 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
* with {@link TinkerGraphView}.
*/
public TinkerVertexProperty(final TinkerVertex vertex, final String key, final V value, final Object... propertyKeyValues) {
- super(TinkerHelper.getNextId((TinkerGraph) vertex.graph(), VertexProperty.class), key);
+ super(((TinkerGraph) vertex.graph()).vertexPropertyIdManager.getNextId((TinkerGraph) vertex.graph()), key);
this.vertex = vertex;
this.key = key;
this.value = value;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc550e2/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
index e873008..596e565 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/TinkerGraphProvider.java
@@ -20,7 +20,9 @@ package org.apache.tinkerpop.gremlin.tinkergraph;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.AbstractGraphProvider;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.GraphTest;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerEdge;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerElement;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
@@ -50,9 +52,15 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
}};
@Override
- public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName) {
+ public Map<String, Object> getBaseConfiguration(final String graphName, final Class<?> test, final String testMethodName,
+ final LoadGraphWith.GraphData loadGraphWith) {
+ final TinkerGraph.DefaultIdManager idManager = selectIdMakerFromGraphData(loadGraphWith);
+ final String idMaker = (idManager.equals(TinkerGraph.DefaultIdManager.ANY) ? selectIdMakerFromTest(test, testMethodName) : idManager).name();
return new HashMap<String, Object>() {{
put(Graph.GRAPH, TinkerGraph.class.getName());
+ put(TinkerGraph.CONFIG_VERTEX_ID, idMaker);
+ put(TinkerGraph.CONFIG_EDGE_ID, idMaker);
+ put(TinkerGraph.CONFIG_VERTEX_PROPERTY_ID, idMaker);
}};
}
@@ -66,4 +74,52 @@ public class TinkerGraphProvider extends AbstractGraphProvider {
public Set<Class> getImplementations() {
return IMPLEMENTATION;
}
+
+ /**
+ * Some tests require special configuration for TinkerGraph to properly configure the id manager.
+ */
+ private TinkerGraph.DefaultIdManager selectIdMakerFromTest(final Class<?> test, final String testMethodName) {
+ if (test.equals(GraphTest.class)) {
+ final Set<String> testsThatNeedLongIdManager = new HashSet<String>(){{
+ add("shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingDoubleRepresentations");
+ add("shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingIntegerRepresentations");
+ add("shouldIterateVerticesWithNumericIdSupportUsingFloatRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingFloatRepresentations");
+ add("shouldIterateVerticesWithNumericIdSupportUsingStringRepresentation");
+ add("shouldIterateVerticesWithNumericIdSupportUsingStringRepresentations");
+ }};
+
+ final Set<String> testsThatNeedUuidIdManager = new HashSet<String>(){{
+ add("shouldIterateVerticesWithUuidIdSupportUsingStringRepresentation");
+ add("shouldIterateVerticesWithUuidIdSupportUsingStringRepresentations");
+ }};
+
+ if (testsThatNeedLongIdManager.contains(testMethodName))
+ return TinkerGraph.DefaultIdManager.LONG;
+ else if (testsThatNeedUuidIdManager.contains(testMethodName))
+ return TinkerGraph.DefaultIdManager.UUID;
+ }
+
+ return TinkerGraph.DefaultIdManager.ANY;
+ }
+
+ /**
+ * Test that load with specific graph data can be configured with a specific id manager as the data type to
+ * be used in the test for that graph is known.
+ */
+ private TinkerGraph.DefaultIdManager selectIdMakerFromGraphData(final LoadGraphWith.GraphData loadGraphWith) {
+ if (null == loadGraphWith) return TinkerGraph.DefaultIdManager.ANY;
+ if (loadGraphWith.equals(LoadGraphWith.GraphData.CLASSIC))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.MODERN))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.CREW))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else if (loadGraphWith.equals(LoadGraphWith.GraphData.GRATEFUL))
+ return TinkerGraph.DefaultIdManager.INTEGER;
+ else
+ throw new IllegalStateException(String.format("Need to define a new %s for %s", TinkerGraph.IdManager.class.getName(), loadGraphWith.name()));
+ }
}