tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [08/50] incubator-tinkerpop git commit: Refactored RemoteGraphProvider to speed up tests.
Date Fri, 18 Mar 2016 13:30:56 GMT
Refactored RemoteGraphProvider to speed up tests.

Cut the time down to about two-thirds of what it was by caching RemoteGraph instances, clearing
graphs on the server with a Client instance and re-using the Cluster object.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a2adbcec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a2adbcec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a2adbcec

Branch: refs/heads/master
Commit: a2adbcecf0b93510700dd9ef775b97a75592354d
Parents: 3312e27
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Sat Mar 12 06:34:29 2016 -0500
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Thu Mar 17 17:01:13 2016 -0400

----------------------------------------------------------------------
 .../driver/remote/DriverRemoteConnection.java   |  7 ++
 .../gremlin/remote/RemoteGraphProvider.java     | 73 +++++++++-----------
 .../tinkerpop/gremlin/AbstractGremlinTest.java  |  1 +
 3 files changed, 39 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a2adbcec/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteConnection.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteConnection.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteConnection.java
index 7de5aaf..9527dfc 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteConnection.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteConnection.java
@@ -74,6 +74,13 @@ public class DriverRemoteConnection implements RemoteConnection {
         this.conf = Optional.of(conf);
     }
 
+    public DriverRemoteConnection(final Cluster cluster, final Configuration conf) {
+        connectionGraphName = conf.getString("connectionGraphName", "graph");
+        client = cluster.connect(Client.Settings.build().unrollTraversers(false).create()).alias(connectionGraphName);
+        tryCloseCluster = false;
+        this.conf = Optional.of(conf);
+    }
+
     private DriverRemoteConnection(final Cluster cluster, final boolean tryCloseCluster,
final String connectionGraphName){
         client = cluster.connect(Client.Settings.build().unrollTraversers(false).create()).alias(connectionGraphName);
         this.connectionGraphName = connectionGraphName;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a2adbcec/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/RemoteGraphProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/RemoteGraphProvider.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/RemoteGraphProvider.java
index 5ac1579..eba0a5d 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/RemoteGraphProvider.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/remote/RemoteGraphProvider.java
@@ -21,6 +21,8 @@ package org.apache.tinkerpop.gremlin.remote;
 import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.AbstractGraphProvider;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.driver.Client;
+import org.apache.tinkerpop.gremlin.driver.Cluster;
 import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
 import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.DropTest;
@@ -54,10 +56,10 @@ public class RemoteGraphProvider extends AbstractGraphProvider {
         add(RemoteGraph.class);
     }};
 
-    private TestListener testListener = new RemoteGraphTestListener();
     private static GremlinServer server;
-
-    private Executor executors = Executors.newFixedThreadPool(4);
+    private Map<String,RemoteGraph> remoteCache = new HashMap<>();
+    private Cluster cluster = Cluster.open();
+    private Client client = cluster.connect();
 
     static {
         try {
@@ -68,8 +70,28 @@ public class RemoteGraphProvider extends AbstractGraphProvider {
     }
 
     @Override
+    public Graph openTestGraph(final Configuration config) {
+        final String serverGraphName = config.getString("connectionGraphName");
+        return remoteCache.computeIfAbsent(serverGraphName,
+                k -> RemoteGraph.open(new DriverRemoteConnection(cluster, config), TinkerGraph.class));
+    }
+
+    @Override
     public Map<String, Object> getBaseConfiguration(final String graphName, Class<?>
test, final String testMethodName,
                                                     final LoadGraphWith.GraphData loadGraphWith)
{
+        final String serverGraphName = getServerGraphName(loadGraphWith);
+
+        final Supplier<Graph> graphGetter = () -> server.getServerGremlinExecutor().getGraphManager().getGraphs().get(serverGraphName);
+        return new HashMap<String, Object>() {{
+            put(Graph.GRAPH, RemoteGraph.class.getName());
+            put(RemoteGraph.GREMLIN_SERVERGRAPH_GRAPH_CLASS, TinkerGraph.class.getName());
+            put(RemoteGraph.GREMLIN_SERVERGRAPH_SERVER_CONNECTION_CLASS, DriverRemoteConnection.class.getName());
+            put("connectionGraphName", serverGraphName);
+            put("hidden.for.testing.only", graphGetter);
+        }};
+    }
+
+    private static String getServerGraphName(LoadGraphWith.GraphData loadGraphWith) {
         final String serverGraphName;
         switch (loadGraphWith) {
             case CLASSIC:
@@ -88,28 +110,16 @@ public class RemoteGraphProvider extends AbstractGraphProvider {
                 serverGraphName = "graph";
                 break;
         }
-
-        final Supplier<Graph> graphGetter = () -> server.getServerGremlinExecutor().getGraphManager().getGraphs().get(serverGraphName);
-        return new HashMap<String, Object>() {{
-            put(Graph.GRAPH, RemoteGraph.class.getName());
-            put(RemoteGraph.GREMLIN_SERVERGRAPH_GRAPH_CLASS, TinkerGraph.class.getName());
-            put(RemoteGraph.GREMLIN_SERVERGRAPH_SERVER_CONNECTION_CLASS, DriverRemoteConnection.class.getName());
-            put("connectionGraphName", serverGraphName);
-            put("hidden.for.testing.only", graphGetter);
-        }};
+        return serverGraphName;
     }
 
     @Override
     public void clear(final Graph graph, final Configuration configuration) throws Exception
{
-        if (graph != null) {
-            executors.execute(() -> {
-                try {
-                    graph.close();
-                } catch (Exception ex) {
-                    ex.printStackTrace();
-                }
-            });
-        }
+        // doesn't bother to clear grateful because i don't believe that ever gets mutated
- read-only
+        client.submit("classic.clear();modern.clear();crew.clear();graph.clear();" +
+                    "TinkerFactory.generateClassic(classic);" +
+                    "TinkerFactory.generateModern(modern);" +
+                    "TinkerFactory.generateTheCrew(crew);null").all().get();
     }
 
     @Override
@@ -122,11 +132,6 @@ public class RemoteGraphProvider extends AbstractGraphProvider {
         return IMPLEMENTATION;
     }
 
-    @Override
-    public Optional<TestListener> getTestListener() {
-        return Optional.of(testListener);
-    }
-
     public static void startServer() throws Exception {
         final InputStream stream = RemoteGraphProvider.class.getResourceAsStream("gremlin-server-integration.yaml");
         final Settings settings = Settings.read(stream);
@@ -140,20 +145,4 @@ public class RemoteGraphProvider extends AbstractGraphProvider {
         server.stop().join();
         server = null;
     }
-
-    public class RemoteGraphTestListener implements TestListener {
-        @Override
-        public void onTestEnd(final Class<?> test, final String testName) {
-            if (test.equals(DropTest.Traversals.class) ||
-                    test.equals(AddEdgeTest.Traversals.class) ||
-                    test.equals(AddVertexTest.Traversals.class)) {
-                try {
-                    stopServer();
-                    startServer();
-                } catch (Exception ex) {
-                    throw new RuntimeException(ex);
-                }
-            }
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a2adbcec/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 3f5b5c3..9354c18 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
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.rules.TestName;
 import org.slf4j.Logger;


Mime
View raw message