You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by co...@apache.org on 2023/11/14 23:39:51 UTC
(tinkerpop) branch 3.7-dev updated: TINKERPOP-3013 Add handling for missing property in remote console (#2341)
This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/3.7-dev by this push:
new 5af507fe56 TINKERPOP-3013 Add handling for missing property in remote console (#2341)
5af507fe56 is described below
commit 5af507fe5659c3b0ffb66722e7ff1e7f88d7783c
Author: kenhuuu <10...@users.noreply.github.com>
AuthorDate: Tue Nov 14 15:39:46 2023 -0800
TINKERPOP-3013 Add handling for missing property in remote console (#2341)
---
.../gremlin/console/GremlinGroovysh.groovy | 6 +-
.../gremlin/console/GremlinGroovyshTest.groovy | 161 +++++++++++++++++++++
.../AbstractGremlinServerIntegrationTest.java | 6 +-
3 files changed, 171 insertions(+), 2 deletions(-)
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
index 2ba5388864..f5a65e652d 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovysh.groovy
@@ -123,6 +123,8 @@ class GremlinGroovysh extends Groovysh {
break
}
throw t
+ } catch (MissingPropertyException mpe) {
+ // Ignore any local missing properties since it doesn't affect remote execution.
}
} else {
// Evaluate Buffer wrapped with code storing bounded vars
@@ -135,6 +137,8 @@ class GremlinGroovysh extends Groovysh {
break
}
throw t
+ } catch (MissingPropertyException mpe) {
+ // Ignore any local missing properties since it doesn't affect remote execution.
}
}
@@ -195,7 +199,7 @@ try {$COLLECTED_BOUND_VARS_MAP_VARNAME[\"$varname\"] = $varname;
} else {
buff = [importsSpec] + ['true'] + current
}
- setLastResult(result = interp.evaluate(buff))
+ interp.evaluate(buff)
if (variableBlocks) {
def boundVarValues = (Map<String, Object>) interp.context.getVariable(COLLECTED_BOUND_VARS_MAP_VARNAME)
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
new file mode 100644
index 0000000000..4ecb5f562a
--- /dev/null
+++ b/gremlin-console/src/test/groovy/org/apache/tinkerpop/gremlin/console/GremlinGroovyshTest.groovy
@@ -0,0 +1,161 @@
+/*
+ * 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.console
+
+import org.apache.tinkerpop.gremlin.console.commands.RemoteCommand
+import org.apache.tinkerpop.gremlin.console.jsr223.AbstractGremlinServerIntegrationTest
+import org.apache.tinkerpop.gremlin.console.jsr223.DriverRemoteAcceptor
+import org.apache.tinkerpop.gremlin.console.jsr223.MockGroovyGremlinShellEnvironment
+import org.codehaus.groovy.tools.shell.IO
+import org.junit.Test
+
+import java.nio.file.Paths
+
+class GremlinGroovyshTest extends AbstractGremlinServerIntegrationTest {
+ private IO testio
+ private ByteArrayOutputStream out
+ private ByteArrayOutputStream err
+ private GremlinGroovysh shell
+
+ @Override
+ void setUp() {
+ super.setUp()
+ out = new ByteArrayOutputStream()
+ err = new ByteArrayOutputStream()
+ testio = new IO(new ByteArrayInputStream(), out, err)
+ shell = new GremlinGroovysh(new Mediator(null), testio)
+ }
+
+ @Override
+ void tearDown() {
+ super.tearDown()
+ shell.execute(":purge preferences") // for test cases where persistent preferences (interpreterMode) are set.
+ }
+
+ @Test
+ void shouldEnableRemoteConsole() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+
+ assert (false == shell.mediator.localEvaluation)
+ assert out.toString().startsWith("All scripts will now be sent to")
+ }
+
+ @Test
+ void shouldGetSimpleResultFromRemoteConsole() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ out.reset()
+ shell.execute("1+1")
+
+ assert ("2" == out.toString())
+ }
+
+ @Test
+ void shouldGetGremlinResultFromRemoteConsole() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ out.reset()
+ shell.execute("g.V().count()")
+
+ assert ("0" == out.toString())
+ }
+
+ @Test
+ void shouldGetMultilineResultFromRemoteConsole() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ out.reset()
+ shell.execute("if (true) {")
+ shell.execute("g.V().count() }")
+
+ assert ("0" == out.toString())
+ }
+
+ @Test
+ void shouldNotSubmitIncompleteLinesFromRemoteConsole() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ shell.execute("if (0 == g.V().count()) {")
+
+ assert (0 != shell.buffers.current().size())
+ }
+
+ @Test
+ void shouldGetGremlinResultFromRemoteConsoleInInterpreterMode() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ shell.execute(":set interpreterMode")
+ out.reset()
+ shell.execute("g.V().count()")
+
+ assert ("0" == out.toString())
+ }
+
+ @Test
+ void shouldGetMultilineResultFromRemoteConsoleInInterpreterMode() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ shell.execute(":set interpreterMode")
+ out.reset()
+ shell.execute("if (true) {")
+ shell.execute("g.V().count() }")
+
+ assert ("0" == out.toString())
+ }
+
+ @Test
+ void shouldOnlyExecuteOnceRemoteConsoleInInterpreterMode() {
+ setupRemote(shell)
+ shell.execute(":remote console")
+ shell.execute(":set interpreterMode")
+ out.reset()
+ shell.execute("a = 1")
+
+ assert "1" == out.toString()
+ }
+
+ private def setupRemote(GremlinGroovysh shell) {
+ shell.setResultHook(handleResult)
+ shell.register(new RemoteCommand(shell, shell.mediator))
+ shell.mediator.addRemote(new DriverRemoteAcceptor(new MockGroovyGremlinShellEnvironment(shell)))
+ shell.mediator.currentRemote().connect([Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("remote.yaml").toURI()).toString()])
+
+ server.getServerGremlinExecutor().getGremlinExecutor().getScriptEngineManager().put(
+ "g",
+ server.getServerGremlinExecutor().getGraphManager().getGraph("graph").traversal())
+ }
+
+ private def handleResult = { result ->
+ if (result instanceof Iterator) {
+ Iterator resultItr = (Iterator) result
+
+ while (resultItr.hasNext()) {
+ testio.out.print(resultItr.next())
+ testio.out.flush()
+ }
+ } else if (result instanceof Number) {
+ testio.out.print((Number) result)
+ testio.out.flush()
+ } else if (result instanceof String) {
+ testio.out.print((String) result)
+ testio.out.flush()
+ }
+ }
+}
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 1bf9193dee..1cf4a78a34 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
@@ -24,6 +24,7 @@ import org.junit.After;
import org.junit.Before;
import java.io.InputStream;
+import java.nio.file.Paths;
/**
* Starts and stops an instance for each executed test.
@@ -31,7 +32,7 @@ import java.io.InputStream;
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public abstract class AbstractGremlinServerIntegrationTest {
- private GremlinServer server;
+ protected GremlinServer server;
public Settings overrideSettings(final Settings settings) {
return settings;
@@ -47,6 +48,9 @@ public abstract class AbstractGremlinServerIntegrationTest {
final Settings settings = Settings.read(stream);
final Settings overridenSettings = overrideSettings(settings);
+ String prop = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("tinkergraph-empty.properties").toURI()).toString();
+ overridenSettings.graphs.put("graph", prop);
+
this.server = new GremlinServer(overridenSettings);
server.start().join();