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 2016/02/13 13:30:59 UTC
[12/37] incubator-tinkerpop git commit: Use GraphProvider.clear() to
auto-clear graphs created in tests
Use GraphProvider.clear() to auto-clear graphs created in tests
Was formerlly just calling Graph.close() which wasn't enough to actually empty graphs of data. This led to test errors for some graph providers. This change actually calls GraphProvider.clear() which by definition should empty a graph of data at the end of a test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/597c3504
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/597c3504
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/597c3504
Branch: refs/heads/master
Commit: 597c350459cf0ade1791180b0660d415064e17c4
Parents: 51140a4
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Feb 10 14:51:20 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Feb 10 14:51:20 2016 -0500
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../upgrade/release-3.1.x-incubating.asciidoc | 26 ++++++++++++++++++++
.../tinkerpop/gremlin/AbstractGremlinTest.java | 2 +-
.../apache/tinkerpop/gremlin/GraphManager.java | 26 ++++++++++++--------
.../apache/tinkerpop/gremlin/GraphProvider.java | 3 +++
.../neo4j/AbstractNeo4jGraphProvider.java | 3 +--
6 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/597c3504/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0cd221f..fc53b72 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ TinkerPop 3.1.2 (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Optimized memory-usage in `TraversalVertexProgram`.
+* `Graph` instances are not merely "closed" at the end of tests, they are "cleared" via `GraphProvider.clear()`, which should in turn cleans up old data for an implementation.
* Greatly reduced the amount of objects required in OLAP for the `ReducingBarrierStep` steps.
[[release-3.1.1-incubating]]
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/597c3504/docs/src/upgrade/release-3.1.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.1.x-incubating.asciidoc b/docs/src/upgrade/release-3.1.x-incubating.asciidoc
index 280d760..840d20c 100644
--- a/docs/src/upgrade/release-3.1.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.1.x-incubating.asciidoc
@@ -22,6 +22,32 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
*A 187 On The Undercover Gremlinz*
+TinkerPop 3.1.2
+---------------
+
+*Release Date: NOT OFFICIALLY RELEASED YET*
+
+Please see the link:https://github.com/apache/incubator-tinkerpop/blob/3.1.1-incubating/CHANGELOG.asciidoc#tinkerpop-312-release-date-XXXXXXXXXXXXXXXXXXXXXXXXXX[changelog] for a complete list of all the modifications that are part of this release.
+
+Upgrading for Providers
+~~~~~~~~~~~~~~~~~~~~~~~
+
+IMPORTANT: It is recommended that providers also review all the upgrade instructions specified for users. Many of the
+changes there may prove important for the provider's implementation.
+
+Graph System Providers
+^^^^^^^^^^^^^^^^^^^^^^
+
+GraphProvider.clear() Semantics
++++++++++++++++++++++++++++++++
+
+The semantics of the various `clear()` methods on `GraphProvider` didn't really change, but it would be worth reviewing
+their implementations to ensure that implementations can be called successfully in an idempotent fashion. Multiple
+calls to `clear()` may occur for a single test on the same `Graph` instance, as `3.1.1-incubating` introduced an
+automated method for clearing graphs at the end of a test and some tests call `clear()` manually.
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1146[TINKERPOP-1146]
+
TinkerPop 3.1.1
---------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/597c3504/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 14b1bcf..49a03e1 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
@@ -138,7 +138,7 @@ public abstract class AbstractGremlinTest {
// which wraps injected GraphProviders with a ManagedGraphProvider instance. If this doesn't happen, there
// is no way to trace open graphs.
if(graphProvider instanceof GraphManager.ManagedGraphProvider)
- ((GraphManager.ManagedGraphProvider)graphProvider).tryCloseGraphs();
+ ((GraphManager.ManagedGraphProvider)graphProvider).tryClearGraphs();
else
logger.warn("The {} is not of type ManagedGraphProvider and therefore graph instances may leak between test cases.", graphProvider.getClass());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/597c3504/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphManager.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphManager.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphManager.java
index 39524bf..55ffcf8 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphManager.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/GraphManager.java
@@ -24,6 +24,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.javatuples.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@@ -65,22 +68,25 @@ public class GraphManager {
/**
* This class provides a way to intercepts calls to {@link Graph} implementation's {@link GraphProvider} instances.
* When {@link #openTestGraph(Configuration)} is called the created object is stored in a list and when tests are
- * complete the {@link #tryCloseGraphs()} is called. When this is called, an attempt is made to close all open graphs.
+ * complete the {@link #tryClearGraphs()} is called. When this is called, an attempt is made to close all open graphs.
*/
public static class ManagedGraphProvider implements GraphProvider {
+ private static final Logger logger = LoggerFactory.getLogger(ManagedGraphProvider.class);
private final GraphProvider innerGraphProvider;
- private final List<Graph> openGraphs = new ArrayList<>();
+ private final List<Pair<Graph, Configuration>> openGraphs = new ArrayList<>();
public ManagedGraphProvider(final GraphProvider innerGraphProvider){
this.innerGraphProvider = innerGraphProvider;
}
- public void tryCloseGraphs(){
- for(Graph graph : openGraphs) {
+ public void tryClearGraphs(){
+ for(Pair<Graph, Configuration> p : openGraphs) {
try {
- graph.close();
+ innerGraphProvider.clear(p.getValue0(), p.getValue1());
}catch (Exception e){
- e.printStackTrace();
+ logger.warn(String.format("Automatic close of Graph instance [%s] and config [%s] generated failure.",
+ p.getValue0() != null ? p.getValue0().toString() : "null",
+ p.getValue1() != null ? p.getValue1().toString() : "null"), e);
}
}
}
@@ -102,15 +108,15 @@ public class GraphManager {
@Override
public Graph standardTestGraph(final Class<?> test, final String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
- final Graph graph = innerGraphProvider.standardTestGraph(test, testMethodName, loadGraphWith);
- openGraphs.add(graph);
- return graph;
+ // call the ManagedGraphProvider.openTestGraph() so that the created Graph/Configuration instances
+ // are tracked
+ return openTestGraph(standardGraphConfiguration(test, testMethodName, loadGraphWith));
}
@Override
public Graph openTestGraph(final Configuration config) {
final Graph graph = innerGraphProvider.openTestGraph(config);
- openGraphs.add(graph);
+ openGraphs.add(Pair.with(graph, config));
return graph;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/597c3504/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 1d343c8..f14fb96 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
@@ -152,12 +152,15 @@ public interface GraphProvider {
/**
* Clears a {@link Graph} of all data and settings. Implementations will have different ways of handling this.
+ * It is typically expected that {@link Graph#close()} will be called and open transactions will be closed.
* For a brute force approach, implementers can simply delete data directories provided in the configuration.
* Implementers may choose a more elegant approach if it exists.
* <p/>
* Implementations should be able to accept an argument of null for the Graph, in which case the only action
* that can be performed is a clear given the configuration. The method will typically be called this way
* as clean up task on setup to ensure that a persisted graph has a clear space to create a test graph.
+ * <p/>
+ * Calls to this method may occur multiple times for a specific test. Develop this method to be idempotent.
*/
public void clear(final Graph graph, final Configuration configuration) throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/597c3504/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGraphProvider.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGraphProvider.java b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGraphProvider.java
index 82a9801..ebe8099 100644
--- a/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGraphProvider.java
+++ b/neo4j-gremlin/src/test/java/org/apache/tinkerpop/gremlin/neo4j/AbstractNeo4jGraphProvider.java
@@ -57,8 +57,7 @@ public abstract class AbstractNeo4jGraphProvider extends AbstractGraphProvider {
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
if (null != graph) {
- if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
- graph.tx().rollback();
+ if (graph.tx().isOpen()) graph.tx().rollback();
graph.close();
}