tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [3/7] tinkerpop git commit: Replace GraphManager with interface
Date Mon, 17 Apr 2017 13:30:05 GMT
Replace GraphManager with interface

This enabled settings-based customization of the GraphManager
implementation class, allowing implementors to customize the behavior of
the GraphManager.


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

Branch: refs/heads/master
Commit: 1f2cfa04bfb5c6758aecb2ff69a4a7942c1701f0
Parents: d19bac0
Author: Benjamin Anderson <b@banjiewen.net>
Authored: Fri Aug 19 22:33:16 2016 -0700
Committer: dpitera <dpitera@us.ibm.com>
Committed: Mon Mar 27 13:38:16 2017 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/server/GraphManager.java  | 112 ++-----------
 .../tinkerpop/gremlin/server/Settings.java      |   6 +
 .../gremlin/server/util/BasicGraphManager.java  | 162 +++++++++++++++++++
 .../server/util/ServerGremlinExecutor.java      |  24 ++-
 .../gremlin/server/GraphManagerTest.java        |  62 -------
 .../server/util/BasicGraphManagerTest.java      |  64 ++++++++
 6 files changed, 265 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f2cfa04/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GraphManager.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GraphManager.java
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GraphManager.java
index 3830efa..e74eccb 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GraphManager.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GraphManager.java
@@ -21,139 +21,49 @@ package org.apache.tinkerpop.gremlin.server;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
-import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import javax.script.Bindings;
-import javax.script.SimpleBindings;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Predicate;
-
-/**
- * Holder for {@link Graph} and {@link TraversalSource} instances configured for the server
to be passed to script
- * engine bindings. The {@link Graph} instances are read from the {@link Settings} for Gremlin
Server as defined in
- * the configuration file. The {@link TraversalSource} instances are rebound to the {@code
GraphManager} once
- * initialization scripts construct them.
- */
-public final class GraphManager {
-    private static final Logger logger = LoggerFactory.getLogger(GremlinServer.class);
-
-    private final Map<String, Graph> graphs = new ConcurrentHashMap<>();
-    private final Map<String, TraversalSource> traversalSources = new ConcurrentHashMap<>();
-
-    /**
-     * Create a new instance using the {@link Settings} from Gremlin Server.
-     */
-    public GraphManager(final Settings settings) {
-        settings.graphs.entrySet().forEach(e -> {
-            try {
-                final Graph newGraph = GraphFactory.open(e.getValue());
-                graphs.put(e.getKey(), newGraph);
-                logger.info("Graph [{}] was successfully configured via [{}].", e.getKey(),
e.getValue());
-            } catch (RuntimeException re) {
-                logger.warn(String.format("Graph [%s] configured at [%s] could not be instantiated
and will not be available in Gremlin Server.  GraphFactory message: %s",
-                        e.getKey(), e.getValue(), re.getMessage()), re);
-                if (re.getCause() != null) logger.debug("GraphFactory exception", re.getCause());
-            }
-        });
-    }
 
+public interface GraphManager {
     /**
-     * Get a list of the {@link Graph} instances and their binding names as defined in the
Gremlin Server
-     * configuration file.
+     * Get a list of the {@link Graph} instances and their binding names
      *
      * @return a {@link Map} where the key is the name of the {@link Graph} and the value
is the {@link Graph} itself
      */
-    public Map<String, Graph> getGraphs() {
-        return graphs;
-    }
+    public Map<String, Graph> getGraphs();
 
     /**
-     * Get a list of the {@link TraversalSource} instances and their binding names as defined
by Gremlin Server
-     * initialization scripts.
+     * Get a list of the {@link TraversalSource} instances and their binding names
      *
      * @return a {@link Map} where the key is the name of the {@link TraversalSource} and
the value is the
      *         {@link TraversalSource} itself
      */
-    public Map<String, TraversalSource> getTraversalSources() {
-        return traversalSources;
-    }
+    public Map<String, TraversalSource> getTraversalSources();
 
     /**
      * Get the {@link Graph} and {@link TraversalSource} list as a set of bindings.
      */
-    public Bindings getAsBindings() {
-        final Bindings bindings = new SimpleBindings();
-        graphs.forEach(bindings::put);
-        traversalSources.forEach(bindings::put);
-        return bindings;
-    }
+    public Bindings getAsBindings();
 
     /**
      * Rollback transactions across all {@link Graph} objects.
      */
-    public void rollbackAll() {
-        graphs.entrySet().forEach(e -> {
-            final Graph graph = e.getValue();
-            if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
-                graph.tx().rollback();
-        });
-    }
+    public void rollbackAll();
 
     /**
      * Selectively rollback transactions on the specified graphs or the graphs of traversal
sources.
      */
-    public void rollback(final Set<String> graphSourceNamesToCloseTxOn) {
-        closeTx(graphSourceNamesToCloseTxOn, Transaction.Status.ROLLBACK);
-    }
+    public void rollback(final Set<String> graphSourceNamesToCloseTxOn);
 
     /**
      * Commit transactions across all {@link Graph} objects.
      */
-    public void commitAll() {
-        graphs.entrySet().forEach(e -> {
-            final Graph graph = e.getValue();
-            if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
-                graph.tx().commit();
-        });
-    }
+    public void commitAll();
 
     /**
      * Selectively commit transactions on the specified graphs or the graphs of traversal
sources.
      */
-    public void commit(final Set<String> graphSourceNamesToCloseTxOn) {
-        closeTx(graphSourceNamesToCloseTxOn, Transaction.Status.COMMIT);
-    }
-
-    /**
-     * Selectively close transactions on the specified graphs or the graphs of traversal
sources.
-     */
-    private void closeTx(final Set<String> graphSourceNamesToCloseTxOn, final Transaction.Status
tx) {
-        final Set<Graph> graphsToCloseTxOn = new HashSet<>();
-
-        // by the time this method has been called, it should be validated that the source/graph
is present.
-        // might be possible that it could have been removed dynamically, but that i'm not
sure how one would do
-        // that as of right now unless they were embedded in which case they'd need to know
what they were doing
-        // anyway
-        graphSourceNamesToCloseTxOn.forEach(r -> {
-            if (graphs.containsKey(r))
-                graphsToCloseTxOn.add(graphs.get(r));
-            else
-                graphsToCloseTxOn.add(traversalSources.get(r).getGraph());
-        });
-
-        graphsToCloseTxOn.forEach(graph -> {
-            if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
{
-                if (tx == Transaction.Status.COMMIT)
-                    graph.tx().commit();
-                else
-                    graph.tx().rollback();
-            }
-        });
-    }
-}
\ No newline at end of file
+    public void commit(final Set<String> graphSourceNamesToCloseTxOn);
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f2cfa04/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
index e2f2ad5..36435a0 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.server.auth.AllowAllAuthenticator;
 import org.apache.tinkerpop.gremlin.server.auth.Authenticator;
 import org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer;
+import org.apache.tinkerpop.gremlin.server.util.BasicGraphManager;
 import info.ganglia.gmetric4j.gmetric.GMetric;
 import org.apache.tinkerpop.gremlin.server.util.LifeCycleHook;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -175,6 +176,11 @@ public class Settings {
     public String channelizer = WebSocketChannelizer.class.getName();
 
     /**
+     * The full class name of the {@link GraphManager} to use in Gremlin Server.
+     */
+    public String graphManager = BasicGraphManager.class.getName();
+
+    /**
      * Configured metrics for Gremlin Server.
      */
     public ServerMetrics metrics = null;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f2cfa04/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManager.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManager.java
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManager.java
new file mode 100644
index 0000000..9f514b8
--- /dev/null
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManager.java
@@ -0,0 +1,162 @@
+/*
+ * 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.server.util;
+
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+import org.apache.tinkerpop.gremlin.server.GraphManager;
+import org.apache.tinkerpop.gremlin.server.GremlinServer;
+import org.apache.tinkerpop.gremlin.server.Settings;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+
+/**
+ * Holder for {@link Graph} and {@link TraversalSource} instances configured for the server
to be passed to script
+ * engine bindings. The {@link Graph} instances are read from the {@link Settings} for Gremlin
Server as defined in
+ * the configuration file. The {@link TraversalSource} instances are rebound to the {@code
GraphManager} once
+ * initialization scripts construct them.
+ */
+public final class BasicGraphManager implements GraphManager {
+    private static final Logger logger = LoggerFactory.getLogger(GremlinServer.class);
+
+    private final Map<String, Graph> graphs = new ConcurrentHashMap<>();
+    private final Map<String, TraversalSource> traversalSources = new ConcurrentHashMap<>();
+
+    /**
+     * Create a new instance using the {@link Settings} from Gremlin Server.
+     */
+    public BasicGraphManager(final Settings settings) {
+        settings.graphs.entrySet().forEach(e -> {
+            try {
+                final Graph newGraph = GraphFactory.open(e.getValue());
+                graphs.put(e.getKey(), newGraph);
+                logger.info("Graph [{}] was successfully configured via [{}].", e.getKey(),
e.getValue());
+            } catch (RuntimeException re) {
+                logger.warn(String.format("Graph [%s] configured at [%s] could not be instantiated
and will not be available in Gremlin Server.  GraphFactory message: %s",
+                        e.getKey(), e.getValue(), re.getMessage()), re);
+                if (re.getCause() != null) logger.debug("GraphFactory exception", re.getCause());
+            }
+        });
+    }
+
+    /**
+     * Get a list of the {@link Graph} instances and their binding names as defined in the
Gremlin Server
+     * configuration file.
+     *
+     * @return a {@link Map} where the key is the name of the {@link Graph} and the value
is the {@link Graph} itself
+     */
+    public Map<String, Graph> getGraphs() {
+        return graphs;
+    }
+
+    /**
+     * Get a list of the {@link TraversalSource} instances and their binding names as defined
by Gremlin Server
+     * initialization scripts.
+     *
+     * @return a {@link Map} where the key is the name of the {@link TraversalSource} and
the value is the
+     *         {@link TraversalSource} itself
+     */
+    public Map<String, TraversalSource> getTraversalSources() {
+        return traversalSources;
+    }
+
+    /**
+     * Get the {@link Graph} and {@link TraversalSource} list as a set of bindings.
+     */
+    public Bindings getAsBindings() {
+        final Bindings bindings = new SimpleBindings();
+        graphs.forEach(bindings::put);
+        traversalSources.forEach(bindings::put);
+        return bindings;
+    }
+
+    /**
+     * Rollback transactions across all {@link Graph} objects.
+     */
+    public void rollbackAll() {
+        graphs.entrySet().forEach(e -> {
+            final Graph graph = e.getValue();
+            if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
+                graph.tx().rollback();
+        });
+    }
+
+    /**
+     * Selectively rollback transactions on the specified graphs or the graphs of traversal
sources.
+     */
+    public void rollback(final Set<String> graphSourceNamesToCloseTxOn) {
+        closeTx(graphSourceNamesToCloseTxOn, Transaction.Status.ROLLBACK);
+    }
+
+    /**
+     * Commit transactions across all {@link Graph} objects.
+     */
+    public void commitAll() {
+        graphs.entrySet().forEach(e -> {
+            final Graph graph = e.getValue();
+            if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
+                graph.tx().commit();
+        });
+    }
+
+    /**
+     * Selectively commit transactions on the specified graphs or the graphs of traversal
sources.
+     */
+    public void commit(final Set<String> graphSourceNamesToCloseTxOn) {
+        closeTx(graphSourceNamesToCloseTxOn, Transaction.Status.COMMIT);
+    }
+
+    /**
+     * Selectively close transactions on the specified graphs or the graphs of traversal
sources.
+     */
+    private void closeTx(final Set<String> graphSourceNamesToCloseTxOn, final Transaction.Status
tx) {
+        final Set<Graph> graphsToCloseTxOn = new HashSet<>();
+
+        // by the time this method has been called, it should be validated that the source/graph
is present.
+        // might be possible that it could have been removed dynamically, but that i'm not
sure how one would do
+        // that as of right now unless they were embedded in which case they'd need to know
what they were doing
+        // anyway
+        graphSourceNamesToCloseTxOn.forEach(r -> {
+            if (graphs.containsKey(r))
+                graphsToCloseTxOn.add(graphs.get(r));
+            else
+                graphsToCloseTxOn.add(traversalSources.get(r).getGraph());
+        });
+
+        graphsToCloseTxOn.forEach(graph -> {
+            if (graph.features().graph().supportsTransactions() && graph.tx().isOpen())
{
+                if (tx == Transaction.Status.COMMIT)
+                    graph.tx().commit();
+                else
+                    graph.tx().rollback();
+            }
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f2cfa04/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index 56e78fb..ea9e537 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@ -32,6 +32,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.Constructor;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -90,7 +91,7 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
              gremlinExecutorService,
              scheduledExecutorService,
              scheduleExecutorServiceClass,
-             new GraphManager(settings));
+             null);
     }
     /**
      * Create a new object from {@link Settings} where thread pools are externally assigned.
Note that if the
@@ -100,9 +101,28 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
      */
     public ServerGremlinExecutor(final Settings settings, final ExecutorService gremlinExecutorService,
                                  final T scheduledExecutorService, final Class<T> scheduleExecutorServiceClass,
-                                 final GraphManager graphManager) {
+                                 GraphManager graphManager) {
         this.settings = settings;
 
+        if (null == graphManager) {
+          try {
+            final Class<?> clazz = Class.forName(settings.graphManager);
+            final Constructor c = clazz.getConstructor(Settings.class);
+            graphManager = (GraphManager) c.newInstance(settings);
+          } catch (ClassNotFoundException e) {
+            logger.error("Could not find GraphManager implementation "
+                         + "defined by the 'graphManager' setting as: {}",
+                         settings.graphManager);
+            throw new RuntimeException(e);
+          } catch (Exception e) {
+            logger.error("Could not invoke constructor on class {} (defined by "
+                         + "the 'graphManager' setting) with one argument of "
+                         + "class Settings",
+                         settings.graphManager);
+            throw new RuntimeException(e);
+          }
+        }
+
         if (null == gremlinExecutorService) {
             final ThreadFactory threadFactoryGremlin = ThreadFactoryUtil.create("exec-%d");
             this.gremlinExecutorService = Executors.newFixedThreadPool(settings.gremlinPool,
threadFactoryGremlin);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f2cfa04/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GraphManagerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GraphManagerTest.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GraphManagerTest.java
deleted file mode 100644
index 7287f90..0000000
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GraphManagerTest.java
+++ /dev/null
@@ -1,62 +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.server;
-
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.junit.Test;
-
-import javax.script.Bindings;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class GraphManagerTest {
-
-    @Test
-    public void shouldReturnGraphs() {
-        final Settings settings = Settings.read(GraphManagerTest.class.getResourceAsStream("gremlin-server-integration.yaml"));
-        final GraphManager graphManager = new GraphManager(settings);
-        final Map<String, Graph> m = graphManager.getGraphs();
-
-        assertNotNull(m);
-        assertEquals(1, m.size());
-        assertThat(m.containsKey("graph"), is(true));
-        assertThat(m.get("graph"), instanceOf(TinkerGraph.class));
-    }
-
-    @Test
-    public void shouldGetAsBindings() {
-        final Settings settings = Settings.read(GraphManagerTest.class.getResourceAsStream("gremlin-server-integration.yaml"));
-        final GraphManager graphManager = new GraphManager(settings);
-        final Bindings bindings = graphManager.getAsBindings();
-
-        assertNotNull(bindings);
-        assertEquals(1, bindings.size());
-        assertThat(bindings.get("graph"), instanceOf(TinkerGraph.class));
-        assertThat(bindings.containsKey("graph"), is(true));
-    }
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1f2cfa04/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManagerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManagerTest.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManagerTest.java
new file mode 100644
index 0000000..2b72c62
--- /dev/null
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/BasicGraphManagerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.server.util;
+
+import org.apache.tinkerpop.gremlin.server.GraphManager;
+import org.apache.tinkerpop.gremlin.server.Settings;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.Test;
+
+import javax.script.Bindings;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class BasicGraphManagerTest {
+
+    @Test
+    public void shouldReturnGraphs() {
+        final Settings settings = Settings.read(BasicGraphManagerTest.class.getResourceAsStream("../gremlin-server-integration.yaml"));
+        final GraphManager graphManager = new BasicGraphManager(settings);
+        final Map<String, Graph> m = graphManager.getGraphs();
+
+        assertNotNull(m);
+        assertEquals(1, m.size());
+        assertThat(m.containsKey("graph"), is(true));
+        assertThat(m.get("graph"), instanceOf(TinkerGraph.class));
+    }
+
+    @Test
+    public void shouldGetAsBindings() {
+        final Settings settings = Settings.read(BasicGraphManagerTest.class.getResourceAsStream("../gremlin-server-integration.yaml"));
+        final GraphManager graphManager = new BasicGraphManager(settings);
+        final Bindings bindings = graphManager.getAsBindings();
+
+        assertNotNull(bindings);
+        assertEquals(1, bindings.size());
+        assertThat(bindings.get("graph"), instanceOf(TinkerGraph.class));
+        assertThat(bindings.containsKey("graph"), is(true));
+    }
+}


Mime
View raw message