diff --git a/gremlin-console/src/test/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovyshTest.groovy b/gremlin-console/src/test/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovyshTest.groovy index 01d17a5e0a..18cb75664a 100644 --- a/gremlin-console/src/test/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovyshTest.groovy +++ b/gremlin-console/src/test/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovyshTest.groovy @@ -18,9 +18,15 @@ */ package org.apache.tinkerpop.gremlin.console - import org.apache.tinkerpop.gremlin.console.jsr223.AbstractGremlinServerIntegrationTest +import org.apache.tinkerpop.gremlin.structure.io.Storage +import org.apache.tinkerpop.gremlin.util.TestSupport import org.codehaus.groovy.tools.shell.IO +import org.junit.Test + +import java.nio.file.Files + +import static org.junit.Assert.assertTrue; class GremlinGroovyshTest extends AbstractGremlinServerIntegrationTest { private IO testio @@ -37,6 +43,33 @@ class GremlinGroovyshTest extends AbstractGremlinServerIntegrationTest { shell = new GremlinGroovysh(new Mediator(null), testio) } + @Test + void shouldGetResultFromRemote() { + final File configFile = TestSupport.generateTempFileFromResource(AbstractGremlinServerIntegrationTest.class, "remote.yaml", "") + final File file = File.createTempFile("remote-graph", ".properties") + + try { + // create temporary config file + Files.deleteIfExists(file.toPath()) + Files.createFile(file.toPath()) + try (PrintStream out = new PrintStream(new FileOutputStream(file.toPath().toString()))) { + out.print("gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection\n") + out.print("gremlin.remote.driver.clusterFile=" + Storage.toPath(configFile)) + out.print("\ngremlin.remote.driver.sourceName=g\n") + } + + shell.execute("import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal") + shell.execute("g = traversal().with('" + Storage.toPath(file) + "')") + out.reset() + shell.execute("g.V().count().next()") + + // 6 vertices in modern graph + assertTrue(out.toString().endsWith("6\r\n")) + } finally { + Files.deleteIfExists(file.toPath()) + } + } + @Override void tearDown() { super.tearDown() diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/AbstractGremlinServerIntegrationTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/AbstractGremlinServerIntegrationTest.java index 1cf4a78a34..3077f5fa7a 100644 --- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/AbstractGremlinServerIntegrationTest.java +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/AbstractGremlinServerIntegrationTest.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.nio.file.Paths; +import java.util.Collections; /** * Starts and stops an instance for each executed test. @@ -48,8 +49,12 @@ public void setUp() throws Exception { final Settings settings = Settings.read(stream); final Settings overridenSettings = overrideSettings(settings); - String prop = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("tinkergraph-empty.properties").toURI()).toString(); + final String prop = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("tinkergraph-empty.properties").toURI()).toString(); overridenSettings.graphs.put("graph", prop); + final String script = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("generate.groovy").toURI()).toString(); + overridenSettings.scriptEngines.get("gremlin-groovy").plugins + .get("org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin") + .put("files", Collections.singletonList(script)); this.server = new GremlinServer(overridenSettings); diff --git a/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/generate.groovy b/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/generate.groovy new file mode 100644 index 0000000000..594402a53e --- /dev/null +++ b/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/generate.groovy @@ -0,0 +1,33 @@ +/* + * 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. + */ + +// an init script that returns a Map allows explicit setting of global bindings. +def globals = [:] + +// Generates the modern graph into an "empty" TinkerGraph via LifeCycleHook. +// Note that the name of the key in the "global" map is unimportant. +globals << [hook : [ + onStartUp: { ctx -> + ctx.logger.info("Loading 'modern' graph data.") + org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern(graph) + } +] as LifeCycleHook] + +// define the default TraversalSource to bind queries to - this one will be named "g". +globals << [g : traversal().withEmbedded(graph)] \ No newline at end of file diff --git a/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/gremlin-server-integration.yaml b/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/gremlin-server-integration.yaml index 7da361bd1d..58cee6de04 100644 --- a/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/gremlin-server-integration.yaml +++ b/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/gremlin-server-integration.yaml @@ -23,7 +23,8 @@ scriptEngines: { gremlin-groovy: { plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}}}} + org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}, + org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {}}}} serializers: - { className: org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4} # application/vnd.graphbinary-v4.0 metrics: { diff --git a/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/remote-graph.properties b/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/remote-graph.properties index d65ab33aaa..d592bd611e 100644 --- a/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/remote-graph.properties +++ b/gremlin-console/src/test/resources/org/apache/tinkerpop/gremlin/console/jsr223/remote-graph.properties @@ -31,5 +31,5 @@ ############################################################## gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection -gremlin.remote.driver.clusterFile=conf/remote.yaml +gremlin.remote.driver.clusterFile=remote.yaml gremlin.remote.driver.sourceName=g \ No newline at end of file diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/AnonymousTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/AnonymousTraversalSource.java index 11efd39881..403b7ed957 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/AnonymousTraversalSource.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/AnonymousTraversalSource.java @@ -134,7 +134,7 @@ public T with(final RemoteConnection remoteConnection) { */ public T with(final String configFile) throws Exception { final Configurations configs = new Configurations(); - return with(configs.properties((configFile))); + return with(configs.properties(configFile)); } /**