Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1278 dec5caf05 -> 26b8556f6
Add a shortcut method to getting ScriptEngine from SingleGremlinScriptEngineManager. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/46958f2e Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/46958f2e Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/46958f2e Branch: refs/heads/TINKERPOP-1278 Commit: 46958f2e66486c2171c97849f25e5ce9909e514e Parents: dec5caf Author: Stephen Mallette <sp...@genoprime.com> Authored: Tue Jul 12 12:39:39 2016 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Tue Jul 12 12:39:39 2016 -0400 ---------------------------------------------------------------------- .../jsr223/SingleGremlinScriptEngineManager.java | 10 ++++++++++ .../CachedGremlinScriptEngineManagerTest.java | 19 ++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46958f2e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/SingleGremlinScriptEngineManager.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/SingleGremlinScriptEngineManager.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/SingleGremlinScriptEngineManager.java index be8fb87..e18ec37 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/SingleGremlinScriptEngineManager.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/SingleGremlinScriptEngineManager.java @@ -19,6 +19,8 @@ package org.apache.tinkerpop.gremlin.jsr223; /** + * Provides static access to a {@link CachedGremlinScriptEngineManager} instance. + * * @author Stephen Mallette (http://stephen.genoprime.com) */ public class SingleGremlinScriptEngineManager { @@ -29,4 +31,12 @@ public class SingleGremlinScriptEngineManager { public static GremlinScriptEngineManager getInstance(){ return cached; } + + /** + * Delegates calls to the {@link CachedGremlinScriptEngineManager} instance ensuring that the same instance + * is returned for each {@code ScriptEngine} requested. + */ + public static GremlinScriptEngine get(final String scriptEngineName) { + return cached.getEngineByName(scriptEngineName); + } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/46958f2e/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CachedGremlinScriptEngineManagerTest.java ---------------------------------------------------------------------- diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CachedGremlinScriptEngineManagerTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CachedGremlinScriptEngineManagerTest.java index e32cf85..5dbeffd 100644 --- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CachedGremlinScriptEngineManagerTest.java +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/jsr223/CachedGremlinScriptEngineManagerTest.java @@ -20,8 +20,12 @@ package org.apache.tinkerpop.gremlin.jsr223; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.IntStream; + import static org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineSuite.ENGINE_TO_TEST; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertEquals; /** * @author Stephen Mallette (http://stephen.genoprime.com) @@ -31,10 +35,15 @@ public class CachedGremlinScriptEngineManagerTest { @Test public void shouldBeSameInstance() { - final GremlinScriptEngine engineFirst = manager.getEngineByName(ENGINE_TO_TEST); - final GremlinScriptEngine engineSecond = manager.getEngineByName(ENGINE_TO_TEST); + final Set<GremlinScriptEngine> scriptEngines = new HashSet<>(); + IntStream.range(0,100).forEach(i -> scriptEngines.add(manager.getEngineByName(ENGINE_TO_TEST))); + assertEquals(1, scriptEngines.size()); + } - assertSame(engineFirst, engineSecond); - assertSame(engineSecond, engineFirst); + @Test + public void shouldBeSameInstanceInSingleManager() { + final Set<GremlinScriptEngine> scriptEngines = new HashSet<>(); + IntStream.range(0,100).forEach(i -> scriptEngines.add(SingleGremlinScriptEngineManager.get(ENGINE_TO_TEST))); + assertEquals(1, scriptEngines.size()); } }