You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/10/04 12:17:00 UTC
[01/12] tinkerpop git commit: optmizes collection copy with
Collections addAll [Forced Update!]
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-2044 ebfda524a -> b510613b1 (forced update)
optmizes collection copy with Collections addAll
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/0e34073d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0e34073d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0e34073d
Branch: refs/heads/TINKERPOP-2044
Commit: 0e34073d8a756a52eda571bd9ddac0b94b42d54a
Parents: ca3a343
Author: Otavio Santana <ot...@gmail.com>
Authored: Wed Aug 22 16:45:19 2018 -0300
Committer: Otavio Santana <ot...@gmail.com>
Committed: Wed Aug 22 16:54:16 2018 -0300
----------------------------------------------------------------------
.../traversal/dsl/graph/GraphTraversal.java | 17 +++++------------
.../step/sideEffect/SideEffectCapStep.java | 4 +---
2 files changed, 6 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e34073d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 1dccead..5ba7823 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -149,6 +149,7 @@ import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -1484,16 +1485,12 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
else {
final List<Object> ids = new ArrayList<>();
if (id instanceof Object[]) {
- for (final Object i : (Object[]) id) {
- ids.add(i);
- }
+ Collections.addAll(ids, (Object[]) id);
} else
ids.add(id);
for (final Object i : otherIds) {
if (i.getClass().isArray()) {
- for (final Object ii : (Object[]) i) {
- ids.add(ii);
- }
+ Collections.addAll(ids, (Object[]) i);
} else
ids.add(i);
}
@@ -1559,16 +1556,12 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
else {
final List<Object> values = new ArrayList<>();
if (value instanceof Object[]) {
- for (final Object v : (Object[]) value) {
- values.add(v);
- }
+ Collections.addAll(values, (Object[]) value);
} else
values.add(value);
for (final Object v : otherValues) {
if (v instanceof Object[]) {
- for (final Object vv : (Object[]) v) {
- values.add(vv);
- }
+ Collections.addAll(values, (Object[]) v);
} else
values.add(v);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e34073d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
index 5ac5b27..337dbe4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectCapStep.java
@@ -46,9 +46,7 @@ public final class SideEffectCapStep<S, E> extends SupplyingBarrierStep<S, E> {
super(traversal);
this.sideEffectKeys = new ArrayList<>(1 + sideEffectKeys.length);
this.sideEffectKeys.add(sideEffectKey);
- for (final String key : sideEffectKeys) {
- this.sideEffectKeys.add(key);
- }
+ Collections.addAll(this.sideEffectKeys, sideEffectKeys);
}
@Override
[09/12] tinkerpop git commit: Merge branch 'pr-920' into tp32
Posted by sp...@apache.org.
Merge branch 'pr-920' into tp32
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/76c9aba9
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/76c9aba9
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/76c9aba9
Branch: refs/heads/TINKERPOP-2044
Commit: 76c9aba94f0f5c464fe4be975809c7dce9c7b92b
Parents: e7af98b b34bf4d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Oct 3 06:12:43 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Oct 3 06:12:43 2018 -0400
----------------------------------------------------------------------
.../traversal/dsl/graph/GraphTraversal.java | 48 ++++++++++++--------
.../step/sideEffect/SideEffectCapStep.java | 4 +-
2 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
[07/12] tinkerpop git commit: Asciidoc puts an extra space on
the-traversal line 162: g.addV('person').iterate() <9> - CTR
Posted by sp...@apache.org.
Asciidoc puts an extra space on the-traversal line 162: g.addV('person').iterate() <9> - CTR
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e7af98bf
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e7af98bf
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e7af98bf
Branch: refs/heads/TINKERPOP-2044
Commit: e7af98bf848df812750d6844d6af156a7eaaca27
Parents: d0659bd
Author: Robert Dale <ro...@gmail.com>
Authored: Tue Oct 2 06:00:09 2018 -0400
Committer: Robert Dale <ro...@gmail.com>
Committed: Tue Oct 2 06:00:09 2018 -0400
----------------------------------------------------------------------
docs/postprocessor/processor.awk | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e7af98bf/docs/postprocessor/processor.awk
----------------------------------------------------------------------
diff --git a/docs/postprocessor/processor.awk b/docs/postprocessor/processor.awk
index 18ada47..fbeadcc 100644
--- a/docs/postprocessor/processor.awk
+++ b/docs/postprocessor/processor.awk
@@ -42,7 +42,7 @@ BEGIN {
/<span class="comment">/ {
if (firstMatch || !isHeader) {
- print gensub(/<span class="comment">\/\/<\/span>(<b class="conum">)\(([0-9]+)\)(<\/b>)/,
+ print gensub(/<span class="comment">\/\/<\/span>[ ]*(<b class="conum">)\(([0-9]+)\)(<\/b>)/,
"<span class=\"invisible\">//</span>\\1\\2\\3<span class=\"invisible\">\\\\<\/span>", "g")
}
}
[02/12] tinkerpop git commit: fixes traversal
Posted by sp...@apache.org.
fixes traversal
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b34bf4da
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b34bf4da
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b34bf4da
Branch: refs/heads/TINKERPOP-2044
Commit: b34bf4da9bf4829d6474ccdb9397a30b705bd01d
Parents: 0e34073
Author: Otavio Santana <ot...@gmail.com>
Authored: Tue Sep 25 15:57:52 2018 -0300
Committer: Otavio Santana <ot...@gmail.com>
Committed: Tue Sep 25 15:57:52 2018 -0300
----------------------------------------------------------------------
.../traversal/dsl/graph/GraphTraversal.java | 37 ++++++++++++++------
1 file changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b34bf4da/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 5ba7823..ba09a7c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -1480,22 +1480,39 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.2.2
*/
public default GraphTraversal<S, E> hasId(final Object id, final Object... otherIds) {
- if (id instanceof P)
+ if (id instanceof P) {
return this.hasId((P) id);
+ }
else {
- final List<Object> ids = new ArrayList<>();
+ Object[] ids;
if (id instanceof Object[]) {
- Collections.addAll(ids, (Object[]) id);
- } else
- ids.add(id);
+ ids = (Object[]) id;
+ } else {
+ ids = new Object[] {id};
+ }
+ int size = ids.length;
+ int capacity = size;
for (final Object i : otherIds) {
if (i.getClass().isArray()) {
- Collections.addAll(ids, (Object[]) i);
- } else
- ids.add(i);
+ final Object[] tmp = (Object[]) i;
+ int newLength = size + tmp.length;
+ if (capacity < newLength) {
+ ids = Arrays.copyOf(ids, capacity = size + tmp.length);
+ }
+ System.arraycopy(tmp, 0, ids, size, tmp.length);
+ size = newLength;
+ } else {
+ if (capacity == size) {
+ ids = Arrays.copyOf(ids, capacity = size * 2);
+ }
+ ids[size++] = i;
+ }
+ }
+ if (capacity > size) {
+ ids = Arrays.copyOf(ids, size);
}
- this.asAdmin().getBytecode().addStep(Symbols.hasId, ids.toArray());
- return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.id.getAccessor(), ids.size() == 1 ? P.eq(ids.get(0)) : P.within(ids)));
+ this.asAdmin().getBytecode().addStep(Symbols.hasId, ids);
+ return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.id.getAccessor(), ids.length == 1 ? P.eq(ids[0]) : P.within(ids)));
}
}
[04/12] tinkerpop git commit: TINKERPOP-2040 Hooked up Customizer for
TypeTranslator
Posted by sp...@apache.org.
TINKERPOP-2040 Hooked up Customizer for TypeTranslator
Enables the Groovy GremlinScriptEngine to use custom TypeTranslators
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e5c2e9cd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e5c2e9cd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e5c2e9cd
Branch: refs/heads/TINKERPOP-2044
Commit: e5c2e9cdc18751e755a21add02a75261c169cf32
Parents: 67e2ee8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Sep 25 17:29:49 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 1 16:18:28 2018 -0400
----------------------------------------------------------------------
.../gremlin/jsr223/TranslatorCustomizer.java | 38 ++++++++++++++++++++
.../groovy/jsr223/GroovyTranslatorTest.java | 23 +++++++++++-
.../jsr223/GremlinGroovyScriptEngine.java | 15 ++++++--
.../gremlin/groovy/jsr223/GroovyTranslator.java | 8 ++---
4 files changed, 76 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5c2e9cd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/TranslatorCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/TranslatorCustomizer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/TranslatorCustomizer.java
new file mode 100644
index 0000000..4468255
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/TranslatorCustomizer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.jsr223;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Translator;
+
+/**
+ * Provides a way to customize and override {@link Bytecode} to script translation. Not all {@link GremlinScriptEngine}
+ * will support this capability as translation is optional.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public interface TranslatorCustomizer extends Customizer {
+
+ /**
+ * Construct a {@link Translator.ScriptTranslator.TypeTranslator} that will be used by a
+ * {@link Translator.ScriptTranslator} instance within the {@link GremlinScriptEngine} to translate
+ * {@link Bytecode} to a script.
+ */
+ public Translator.ScriptTranslator.TypeTranslator createTypeTranslator();
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5c2e9cd/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index c224642..1622d3d 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@ -22,6 +22,7 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.jsr223.TranslatorCustomizer;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
@@ -59,9 +60,11 @@ import java.util.List;
import java.util.UUID;
import java.util.function.Function;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
@@ -224,7 +227,7 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
}
@Test
- public void shouldIncludeCustomTypeTranslationForSomethingSilly() {
+ public void shouldIncludeCustomTypeTranslationForSomethingSilly() throws Exception {
final SillyClass notSillyEnough = SillyClass.from("not silly enough", 100);
final GraphTraversalSource g = graph.traversal();
@@ -241,6 +244,15 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
translate(g.inject(notSillyEnough).asAdmin().getBytecode());
assertEquals(String.format("g.inject(org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest.SillyClass.from('%s', (int) %s))", notSillyEnough.getX(), notSillyEnough.getY()), scriptGood);
assertThatScriptOk(scriptGood, "g", g);
+
+ final GremlinGroovyScriptEngine customEngine = new GremlinGroovyScriptEngine(new SillyClassTranslatorCustomizer());
+ final Bindings b = new SimpleBindings();
+ b.put("g", g);
+ final Traversal t = customEngine.eval(g.inject(notSillyEnough).asAdmin().getBytecode(), b, "g");
+ final SillyClass sc = (SillyClass) t.next();
+ assertEquals(notSillyEnough.getX(), sc.getX());
+ assertEquals(notSillyEnough.getY(), sc.getY());
+ assertThat(t.hasNext(), is(false));
}
@Test
@@ -344,4 +356,13 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
}
}
+ public static class SillyClassTranslatorCustomizer implements TranslatorCustomizer {
+
+ @Override
+ public Translator.ScriptTranslator.TypeTranslator createTypeTranslator() {
+ return x -> x instanceof SillyClass ?
+ new Translator.ScriptTranslator.Handled(String.format("org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest.SillyClass.from('%s', (int) %s)",
+ ((SillyClass) x).getX(), ((SillyClass) x).getY())) : x;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5c2e9cd/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 381dd88..b96b8b9 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -30,7 +30,6 @@ import groovy.lang.MissingMethodException;
import groovy.lang.MissingPropertyException;
import groovy.lang.Script;
import groovy.lang.Tuple;
-import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
@@ -49,7 +48,9 @@ import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptContext;
import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineFactory;
import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.TranslatorCustomizer;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Translator;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.codehaus.groovy.ast.ClassHelper;
@@ -241,6 +242,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
private final Set<Artifact> artifactsToUse = new HashSet<>();
private final boolean interpreterModeEnabled;
private final long expectedCompilationTime;
+ private final Translator.ScriptTranslator.TypeTranslator typeTranslator;
/**
* Creates a new instance using the {@link DefaultImportCustomizerProvider}.
@@ -287,6 +289,12 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
interpreterModeEnabled = groovyCustomizers.stream()
.anyMatch(p -> p.getClass().equals(InterpreterModeGroovyCustomizer.class));
+ final Optional<TranslatorCustomizer> translatorCustomizer = listOfCustomizers.stream().
+ filter(p -> p instanceof TranslatorCustomizer).
+ map(p -> (TranslatorCustomizer) p).findFirst();
+ typeTranslator = translatorCustomizer.isPresent() ? translatorCustomizer.get().createTypeTranslator() :
+ Translator.ScriptTranslator.TypeTranslator.identity();
+
// not using the old provider model so set that to empty list so that when createClassLoader is called
// it knows to use groovyCustomizers instead
customizerProviders = Collections.emptyList();
@@ -330,6 +338,9 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
groovyCustomizers = Collections.emptyList();
importGroovyCustomizer = null;
+ // TypeTranslator can only be set by a Customizer - use this old deprecated stuff and you're outta luck
+ typeTranslator = Translator.ScriptTranslator.TypeTranslator.identity();
+
createClassLoader();
}
@@ -464,7 +475,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
inner.putAll(bytecode.getBindings());
inner.put(HIDDEN_G, b);
- return (Traversal.Admin) this.eval(GroovyTranslator.of(HIDDEN_G).translate(bytecode), inner);
+ return (Traversal.Admin) this.eval(GroovyTranslator.of(HIDDEN_G, typeTranslator).translate(bytecode), inner);
}
/**
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5c2e9cd/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
index 9cd7791..949fcac 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
@@ -22,9 +22,7 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223;
import groovy.json.StringEscapeUtils;
import org.apache.commons.configuration.ConfigurationConverter;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
-import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.P;
-import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Translator;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
@@ -34,8 +32,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent
import org.apache.tinkerpop.gremlin.process.traversal.strategy.TraversalStrategyProxy;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
-import org.apache.tinkerpop.gremlin.structure.Column;
-import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -52,10 +48,12 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
-import java.util.function.UnaryOperator;
/**
+ * Converts bytecode to a Groovy string of Gremlin.
+ *
* @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
*/
public final class GroovyTranslator implements Translator.ScriptTranslator {
[05/12] tinkerpop git commit: TINKERPOP-2040 Provide improved type
handling for GroovyTranslator
Posted by sp...@apache.org.
TINKERPOP-2040 Provide improved type handling for GroovyTranslator
Refactored testing and added support for UUID, Date, Timestamp as well as a method to override standard type handling.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/774371dc
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/774371dc
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/774371dc
Branch: refs/heads/TINKERPOP-2044
Commit: 774371dc38d2d73be142eaa69c958226ac660892
Parents: 0403156
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Sep 20 11:53:07 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 1 16:18:28 2018 -0400
----------------------------------------------------------------------
.../gremlin/process/traversal/Translator.java | 34 ++++
.../groovy/jsr223/GroovyTranslatorTest.java | 162 +++++++++++++++----
.../gremlin/groovy/jsr223/GroovyTranslator.java | 32 +++-
3 files changed, 195 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/774371dc/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Translator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Translator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Translator.java
index 7e97fb3..0346092 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Translator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Translator.java
@@ -19,6 +19,8 @@
package org.apache.tinkerpop.gremlin.process.traversal;
+import java.util.function.UnaryOperator;
+
/**
* A Translator will translate {@link Bytecode} into another representation. That representation may be a
* Java instance via {@link StepTranslator} or a String script in some language via {@link ScriptTranslator}.
@@ -55,10 +57,42 @@ public interface Translator<S, T> {
///
+ /**
+ * Translates bytecode to a string representation.
+ */
public interface ScriptTranslator extends Translator<String, String> {
+ /**
+ * Provides a way to customize and override the standard translation process. A {@link ScriptTranslator}
+ * implementation can choose to expose a way to accept a {@code TypeTranslator} which will convert an incoming
+ * object to a different form which will then be normally processed or can return a {@link Handled} object
+ * with the already translated script.
+ */
+ public interface TypeTranslator extends UnaryOperator<Object> {
+ public static TypeTranslator identity() {
+ return t -> t;
+ }
+ }
+
+ /**
+ * Contains a completed type translation from the {@link TypeTranslator}.
+ */
+ public class Handled {
+ private final String translation;
+
+ public Handled(final String translation) {
+ this.translation = translation;
+ }
+
+ public String getTranslation() {
+ return translation;
+ }
+ }
}
+ /**
+ * Translates bytecode to actual steps.
+ */
public interface StepTranslator<S extends TraversalSource, T extends Traversal.Admin<?, ?>> extends Translator<S, T> {
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/774371dc/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index 942f1a5..686c7bd 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@ -22,6 +22,7 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.traversal.Translator;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
@@ -32,47 +33,56 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.Transl
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
import org.apache.tinkerpop.gremlin.util.function.Lambda;
import org.junit.Test;
import javax.script.Bindings;
+import javax.script.ScriptException;
import javax.script.SimpleBindings;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.UUID;
import java.util.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class GroovyTranslatorTest extends AbstractGremlinTest {
+ private static final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
+
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldHandleStrategies() throws Exception {
- GraphTraversalSource g = graph.traversal();
- g = g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
+ final GraphTraversalSource g = graph.traversal().withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
}})));
final Bindings bindings = new SimpleBindings();
bindings.put("g", g);
- Traversal.Admin<Vertex, Object> traversal = new GremlinGroovyScriptEngine().eval(g.V().values("name").asAdmin().getBytecode(), bindings, "g");
+ Traversal.Admin<Vertex, Object> traversal = engine.eval(g.V().values("name").asAdmin().getBytecode(), bindings, "g");
assertEquals("marko", traversal.next());
assertFalse(traversal.hasNext());
//
- traversal = new GremlinGroovyScriptEngine().eval(g.withoutStrategies(SubgraphStrategy.class).V().count().asAdmin().getBytecode(), bindings, "g");
+ traversal = engine.eval(g.withoutStrategies(SubgraphStrategy.class).V().count().asAdmin().getBytecode(), bindings, "g");
assertEquals(new Long(6), traversal.next());
assertFalse(traversal.hasNext());
//
- traversal = new GremlinGroovyScriptEngine().eval(g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
+ traversal = engine.eval(g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
}})), ReadOnlyStrategy.instance()).V().values("name").asAdmin().getBytecode(), bindings, "g");
assertEquals("marko", traversal.next());
@@ -81,10 +91,10 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
- public void shouldSupportStringSupplierLambdas() throws Exception {
+ public void shouldSupportStringSupplierLambdas() {
GraphTraversalSource g = graph.traversal();
g = g.withStrategies(new TranslationStrategy(g, GroovyTranslator.of("g")));
- GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1)
+ final GraphTraversal.Admin<Vertex, Integer> t = g.withSideEffect("lengthSum", 0).withSack(1)
.V()
.filter(Lambda.predicate("it.get().label().equals('person')"))
.flatMap(Lambda.function("it.get().vertices(Direction.OUT)"))
@@ -130,25 +140,77 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
".order().by({a,b -> a <=> b})" +
".sack({ a,b -> a + b })",
script);
+ assertThatScriptOk(script, "g", g);
}
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldHandleMaps() {
- final GraphTraversalSource g = graph.traversal();
final String script = GroovyTranslator.of("g").translate(g.V().id().is(new LinkedHashMap<Object,Object>() {{
put(3, "32");
put(Arrays.asList(1, 2, 3.1d), 4);
}}).asAdmin().getBytecode());
assertEquals("g.V().id().is([((int) 3):(\"32\"),([(int) 1, (int) 2, 3.1d]):((int) 4)])", script);
+ assertThatScriptOk(script, "g", g);
}
@Test
public void shouldHandleEmptyMaps() {
final Function identity = new Lambda.OneArgLambda("it.get()", "gremlin-groovy");
- final GraphTraversalSource g = graph.traversal();
final String script = GroovyTranslator.of("g").translate(g.inject(Collections.emptyMap()).map(identity).asAdmin().getBytecode());
assertEquals("g.inject([]).map({it.get()})", script);
+ assertThatScriptOk(script, "g", g);
+ }
+
+ @Test
+ public void shouldHandleDate() {
+ final Calendar c = Calendar.getInstance();
+ c.set(1975, Calendar.SEPTEMBER, 7);
+ final Date d = c.getTime();
+ assertTranslation(String.format("new java.util.Date(%s)", d.getTime()), d);
+ }
+
+ @Test
+ public void shouldHandleTimestamp() {
+ final Calendar c = Calendar.getInstance();
+ c.set(1975, Calendar.SEPTEMBER, 7);
+ final Timestamp t = new Timestamp(c.getTime().getTime());
+ assertTranslation(String.format("new java.sql.Timestamp(%s)", t.getTime()), t);
+ }
+
+ @Test
+ public void shouldHandleUuid() {
+ final UUID uuid = UUID.fromString("ffffffff-fd49-1e4b-0000-00000d4b8a1d");
+ assertTranslation(String.format("java.util.UUID.fromString('%s')", uuid), uuid);
+ }
+
+ @Test
+ public void shouldOverrideDefaultTypeTranslationWithSomethingBonkers() {
+ final String thingToSuffixAllStringsWith = "-why-would-anyone-do-this";
+ final String script = GroovyTranslator.of("g", x -> x instanceof String ? x + thingToSuffixAllStringsWith : x).
+ translate(g.inject("yyy", "xxx").asAdmin().getBytecode());
+ assertEquals(String.format("g.inject(\"yyy%s\",\"xxx%s\")", thingToSuffixAllStringsWith, thingToSuffixAllStringsWith), script);
+ assertThatScriptOk(script, "g", g);
+ }
+
+ @Test
+ public void shouldIncludeCustomTypeTranslationForSomethingSilly() {
+ final SillyClass notSillyEnough = SillyClass.from("not silly enough", 100);
+ final GraphTraversalSource g = graph.traversal();
+
+ // without type translation we get uglinesss
+ final String scriptBad = GroovyTranslator.of("g").
+ translate(g.inject(notSillyEnough).asAdmin().getBytecode());
+ assertEquals(String.format("g.inject(%s)", "not silly enough:100"), scriptBad);
+
+ // with type translation we get valid gremlin
+ final String scriptGood = GroovyTranslator.of("g",
+ x -> x instanceof SillyClass ?
+ new Translator.ScriptTranslator.Handled(String.format("org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest.SillyClass.from('%s', (int) %s)",
+ ((SillyClass) x).getX(), ((SillyClass) x).getY())) : x).
+ translate(g.inject(notSillyEnough).asAdmin().getBytecode());
+ assertEquals(String.format("g.inject(org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslatorTest.SillyClass.from('%s', (int) %s))", notSillyEnough.getX(), notSillyEnough.getY()), scriptGood);
+ assertThatScriptOk(scriptGood, "g", g);
}
@Test
@@ -158,20 +220,8 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
@Test
public void shouldEscapeStrings() {
- final GraphTraversalSource g = graph.traversal();
- final String script = GroovyTranslator.of("g").translate(g.addV("customer")
- .property("customer_id", 501L)
- .property("name", "Foo\u0020Bar")
- .property("age", 25)
- .property("special", "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?")
- .asAdmin().getBytecode());
-
- assertEquals("g.addV(\"customer\")" +
- ".property(\"customer_id\",501L)" +
- ".property(\"name\",\"Foo Bar\")" +
- ".property(\"age\",(int) 25)" +
- ".property(\"special\",\"\"\"`~!@#\\$%^&*()-_=+[{]}\\\\|;:'\\\",<.>/?\"\"\")",
- script);
+ assertTranslation("501L,\"Foo Bar\",(int) 25,\"\"\"`~!@#\\$%^&*()-_=+[{]}\\\\|;:'\\\",<.>/?\"\"\"",
+ 501L, "Foo\u0020Bar", 25, "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?");
}
@Test
@@ -181,33 +231,87 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
final Object id1 = "customer:10:foo\u0020bar\u0020\u0024100#90"; // customer:10:foo bar $100#90
final Vertex vertex1 = DetachedVertex.build().setLabel("customer").setId(id1)
.create();
- final String script1 = GroovyTranslator.of("g").translate(g.V(vertex1).asAdmin().getBytecode());
- assertEquals("g.V(new org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex(" +
+ final String script1 = GroovyTranslator.of("g").translate(g.inject(vertex1).asAdmin().getBytecode());
+ assertEquals("g.inject(new org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex(" +
"\"customer:10:foo bar \\$100#90\"," +
"\"customer\", Collections.emptyMap()))",
script1);
+ assertThatScriptOk(script1, "g", g);
final Object id2 = "user:20:foo\\u0020bar\\u005c\\u0022mr\\u005c\\u0022\\u00241000#50"; // user:20:foo\u0020bar\u005c\u0022mr\u005c\u0022\u00241000#50
final Vertex vertex2 = DetachedVertex.build().setLabel("user").setId(id2)
.create();
- final String script2 = GroovyTranslator.of("g").translate(g.V(vertex2).asAdmin().getBytecode());
- assertEquals("g.V(new org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex(" +
+ final String script2 = GroovyTranslator.of("g").translate(g.inject(vertex2).asAdmin().getBytecode());
+ assertEquals("g.inject(new org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex(" +
"\"user:20:foo\\\\u0020bar\\\\u005c\\\\u0022mr\\\\u005c\\\\u0022\\\\u00241000#50\"," +
"\"user\", Collections.emptyMap()))",
script2);
+ assertThatScriptOk(script2, "g", g);
final Object id3 = "knows:30:foo\u0020bar\u0020\u0024100:\\u0020\\u0024500#70";
final Edge edge = DetachedEdge.build().setLabel("knows").setId(id3)
.setOutV((DetachedVertex) vertex1)
.setInV((DetachedVertex) vertex2)
.create();
- final String script3 = GroovyTranslator.of("g").translate(g.E(edge).asAdmin().getBytecode());
- assertEquals("g.E(new org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge(" +
+ final String script3 = GroovyTranslator.of("g").translate(g.inject(edge).asAdmin().getBytecode());
+ assertEquals("g.inject(new org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge(" +
"\"knows:30:foo bar \\$100:\\\\u0020\\\\u0024500#70\"," +
"\"knows\",Collections.emptyMap()," +
"\"customer:10:foo bar \\$100#90\",\"customer\"," +
"\"user:20:foo\\\\u0020bar\\\\u005c\\\\u0022mr\\\\u005c\\\\u0022\\\\u00241000#50\",\"user\"))",
script3);
+ assertThatScriptOk(script3, "g", g);
+ }
+
+ public static Object eval(final String s, final Object... args) throws ScriptException {
+ return engine.eval(s, new SimpleBindings(ElementHelper.asMap(args)));
+ }
+
+ public static Object eval(final String s, final Bindings b) throws ScriptException {
+ return engine.eval(s, b);
+ }
+
+ private void assertTranslation(final String expectedTranslation, final Object... objs) {
+ final String script = GroovyTranslator.of("g").translate(g.inject(objs).asAdmin().getBytecode());
+ assertEquals(String.format("g.inject(%s)", expectedTranslation), script);
+ assertThatScriptOk(script, "g", g);
+ }
+
+ private void assertThatScriptOk(final String s, final Object... args) {
+ try {
+ assertNotNull(eval(s, args));
+ } catch (ScriptException se) {
+ se.printStackTrace();
+ fail("Script should have eval'd");
+ }
+ }
+
+ public static class SillyClass {
+
+ private final String x;
+ private final int y;
+
+ private SillyClass(final String x, final int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public static SillyClass from(final String x, final int y) {
+ return new SillyClass(x, y);
+ }
+
+ public String getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ @Override
+ public String toString() {
+ return x + ":" + String.valueOf(y);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/774371dc/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
index 0452e0b..1d122c6 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
@@ -39,11 +39,16 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.function.Lambda;
+import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.UUID;
+import java.util.function.UnaryOperator;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -53,13 +58,19 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
private static final boolean IS_TESTING = Boolean.valueOf(System.getProperty("is.testing", "false"));
private final String traversalSource;
+ private final TypeTranslator typeTranslator;
- private GroovyTranslator(final String traversalSource) {
+ private GroovyTranslator(final String traversalSource, final TypeTranslator typeTranslator) {
this.traversalSource = traversalSource;
+ this.typeTranslator = typeTranslator;
}
public static final GroovyTranslator of(final String traversalSource) {
- return new GroovyTranslator(traversalSource);
+ return of(traversalSource, TypeTranslator.identity());
+ }
+
+ public static final GroovyTranslator of(final String traversalSource, final TypeTranslator typeTranslator) {
+ return new GroovyTranslator(traversalSource, Optional.ofNullable(typeTranslator).orElse(TypeTranslator.identity()));
}
///////
@@ -108,8 +119,15 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
return traversalScript.toString();
}
- private String convertToString(final Object object) {
- if (object instanceof Bytecode.Binding)
+ private String convertToString(final Object o) {
+ // a TypeTranslator that returns Handled means that the typetranslator figure out how to convert the
+ // object to a string and it should be used as-is, otherwise it gets passed down the line through the normal
+ // process
+ final Object object = typeTranslator.apply(o);
+
+ if (object instanceof Handled)
+ return ((Handled) object).getTranslation();
+ else if (object instanceof Bytecode.Binding)
return ((Bytecode.Binding) object).variable();
else if (object instanceof Bytecode)
return this.internalTranslate("__", (Bytecode) object);
@@ -155,6 +173,12 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
return "(int) " + object;
else if (object instanceof Class)
return ((Class) object).getCanonicalName();
+ else if (object instanceof Timestamp)
+ return "new java.sql.Timestamp(" + ((Timestamp) object).getTime() + ")";
+ else if (object instanceof Date)
+ return "new java.util.Date(" + ((Date) object).getTime() + ")";
+ else if (object instanceof UUID)
+ return "java.util.UUID.fromString('" + object.toString() + "')";
else if (object instanceof P)
return convertPToString((P) object, new StringBuilder()).toString();
else if (object instanceof SackFunctions.Barrier)
[12/12] tinkerpop git commit: TINKERPOP-2044 Configurable traversal
to validate host connectivity.
Posted by sp...@apache.org.
TINKERPOP-2044 Configurable traversal to validate host connectivity.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b510613b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b510613b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b510613b
Branch: refs/heads/TINKERPOP-2044
Commit: b510613b10962a3e8d95c3e590b5f58297227d0e
Parents: 88d6f77
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Sep 28 15:54:30 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Oct 4 08:16:44 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../src/reference/gremlin-applications.asciidoc | 1 +
.../tinkerpop/gremlin/driver/Cluster.java | 30 ++++++++++++++++++--
.../gremlin/driver/ConnectionPool.java | 3 +-
.../tinkerpop/gremlin/driver/Settings.java | 15 +++++++---
.../tinkerpop/gremlin/driver/SettingsTest.java | 8 ++++--
.../server/GremlinDriverIntegrateTest.java | 27 +++++++++++++++++-
7 files changed, 74 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index c4523d8..f3340cc 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -39,6 +39,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Added synchronized `Map` to Gryo 1.0 registrations.
* Added `Triple` to Gryo 1.0 registrations.
* Improved escaping of special characters in strings passed to the `GroovyTranslator`.
+* Added `Cluster` configuration option to set a custom validation script to use to test server connectivity in the Java driver.
* Improved ability of `GroovyTranslator` to handle more types supported by GraphSON.
* Improved ability of `GroovyTranslator` to handle custom types.
* Added better internal processing of `Column` in `by(Function)`.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 1cd9964..5607667 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -750,6 +750,7 @@ The following table describes the various configuration options for the Gremlin
|connectionPool.sslSkipCertValidation |Configures the `TrustManager` to trust all certs without any validation. Should not be used in production.|false
|connectionPool.trustStore |File location for a SSL Certificate Chain to use when SSL is enabled. If this value is not provided and SSL is enabled, the default `TrustManager` will be used. |_none_
|connectionPool.trustStorePassword |The password of the `trustStore` if it is password-protected |_none_
+|connectionPool.validationRequest |A script that is used to test server connectivity. A good script to use is one that evaluates quickly and returns no data. The default simply returns an empty string, but if a graph is required by a particular provider, a good traversal might be `g.inject()`. |_''_
|hosts |The list of hosts that the driver will connect to. |localhost
|jaasEntry |Sets the `AuthProperties.Property.JAAS_ENTRY` properties for authentication to Gremlin Server. |_none_
|nioPoolSize |Size of the pool for handling request/response operations. |available processors
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
index 9adaaa1..c090584 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
@@ -25,11 +25,16 @@ import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.driver.ser.Serializers;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,10 +65,10 @@ import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
@@ -204,7 +209,8 @@ public final class Cluster {
.maxSimultaneousUsagePerConnection(settings.connectionPool.maxSimultaneousUsagePerConnection)
.minSimultaneousUsagePerConnection(settings.connectionPool.minSimultaneousUsagePerConnection)
.maxConnectionPoolSize(settings.connectionPool.maxSize)
- .minConnectionPoolSize(settings.connectionPool.minSize);
+ .minConnectionPoolSize(settings.connectionPool.minSize)
+ .validationRequest(settings.connectionPool.validationRequest);
if (settings.username != null && settings.password != null)
builder.credentials(settings.username, settings.password);
@@ -465,6 +471,10 @@ public final class Cluster {
return manager.authProps;
}
+ RequestMessage.Builder validationRequest() {
+ return manager.validationRequest.get();
+ }
+
SslContext createSSLContext() throws Exception {
// if the context is provided then just use that and ignore the other settings
if (manager.sslContextOptional.isPresent())
@@ -575,6 +585,7 @@ public final class Cluster {
private String trustStore = null;
private String trustStorePassword = null;
private String keyStoreType = null;
+ private String validationRequest = "''";
private List<String> sslEnabledProtocols = new ArrayList<>();
private List<String> sslCipherSuites = new ArrayList<>();
private boolean sslSkipCertValidation = false;
@@ -889,6 +900,17 @@ public final class Cluster {
}
/**
+ * Specify a valid Gremlin script that can be used to test remote operations. This script should be designed
+ * to return quickly with the least amount of overhead possible. By default, the script sends an empty string.
+ * If the graph does not support that sort of script because it requires all scripts to include a reference
+ * to a graph then a good option might be {@code g.inject()}.
+ */
+ public Builder validationRequest(final String script) {
+ validationRequest = script;
+ return this;
+ }
+
+ /**
* Time in milliseconds to wait before attempting to reconnect to a dead host after it has been marked dead.
*
* @deprecated As of release 3.2.3, the value of the initial delay is now the same as the {@link #reconnectInterval}.
@@ -1020,6 +1042,7 @@ public final class Cluster {
private final LoadBalancingStrategy loadBalancingStrategy;
private final AuthProperties authProps;
private final Optional<SslContext> sslContextOptional;
+ private final Supplier<RequestMessage.Builder> validationRequest;
private final ScheduledThreadPoolExecutor executor;
@@ -1066,6 +1089,7 @@ public final class Cluster {
connectionPoolSettings.sslSkipCertValidation = builder.sslSkipCertValidation;
connectionPoolSettings.keepAliveInterval = builder.keepAliveInterval;
connectionPoolSettings.channelizer = builder.channelizer;
+ connectionPoolSettings.validationRequest = builder.validationRequest;
sslContextOptional = Optional.ofNullable(builder.sslContext);
@@ -1079,6 +1103,8 @@ public final class Cluster {
this.executor = new ScheduledThreadPoolExecutor(builder.workerPoolSize,
new BasicThreadFactory.Builder().namingPattern("gremlin-driver-worker-%d").build());
this.executor.setRemoveOnCancelPolicy(true);
+
+ validationRequest = () -> RequestMessage.build(Tokens.OPS_EVAL).add(Tokens.ARGS_GREMLIN, builder.validationRequest);
}
private void validateBuilder(final Builder builder) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
index 8d63e13..39ded33 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
@@ -387,7 +387,6 @@ final class ConnectionPool {
// let the load-balancer know that the host is acting poorly
this.cluster.loadBalancingStrategy().onUnavailable(host);
-
}
/**
@@ -400,7 +399,7 @@ final class ConnectionPool {
Connection connection = null;
try {
connection = borrowConnection(cluster.connectionPoolSettings().maxWaitForConnection, TimeUnit.MILLISECONDS);
- final RequestMessage ping = RequestMessage.build(Tokens.OPS_EVAL).add(Tokens.ARGS_GREMLIN, "''").create();
+ final RequestMessage ping = client.buildMessage(cluster.validationRequest()).create();
final CompletableFuture<ResultSet> f = new CompletableFuture<>();
connection.write(ping, f);
f.get().all().get();
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
index fedd337..c2ae045 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
@@ -243,6 +243,8 @@ final class Settings {
if (connectionPoolConf.containsKey("keepAliveInterval"))
cpSettings.keepAliveInterval = connectionPoolConf.getLong("keepAliveInterval");
+ if (connectionPoolConf.containsKey("validationRequest"))
+ cpSettings.validationRequest = connectionPoolConf.getString("validationRequest");
settings.connectionPool = cpSettings;
}
@@ -258,28 +260,28 @@ final class Settings {
/**
* The trusted certificate in PEM format.
- * @deprecated As of release 3.2.10, replaced by {@link trustStore}
+ * @deprecated As of release 3.2.10, replaced by {@link #trustStore}
*/
@Deprecated
public String trustCertChainFile = null;
/**
* The X.509 certificate chain file in PEM format.
- * @deprecated As of release 3.2.10, replaced by {@link keyStore}
+ * @deprecated As of release 3.2.10, replaced by {@link #keyStore}
*/
@Deprecated
public String keyCertChainFile = null;
/**
* The PKCS#8 private key file in PEM format.
- * @deprecated As of release 3.2.10, replaced by {@link keyStore}
+ * @deprecated As of release 3.2.10, replaced by {@link #keyStore}
*/
@Deprecated
public String keyFile = null;
/**
* The password of the {@link #keyFile}, or {@code null} if it's not password-protected.
- * @deprecated As of release 3.2.10, replaced by {@link keyStorePassword}
+ * @deprecated As of release 3.2.10, replaced by {@link #keyStorePassword}
*/
@Deprecated
public String keyPassword = null;
@@ -420,6 +422,11 @@ final class Settings {
public String channelizer = Channelizer.WebSocketChannelizer.class.getName();
/**
+ * A valid Gremlin script that can be used to test remote operations.
+ */
+ public String validationRequest = "''";
+
+ /**
* @deprecated as of 3.1.1-incubating, and not replaced as this property was never implemented internally
* as the way to establish sessions
*/
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/SettingsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/SettingsTest.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/SettingsTest.java
index 56e0ec8..63c4308 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/SettingsTest.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/SettingsTest.java
@@ -18,7 +18,9 @@
*/
package org.apache.tinkerpop.gremlin.driver;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
@@ -69,6 +71,7 @@ public class SettingsTest {
conf.setProperty("connectionPool.reconnectInitialDelay", 1000);
conf.setProperty("connectionPool.resultIterationBatchSize", 1100);
conf.setProperty("connectionPool.channelizer", "channelizer0");
+ conf.setProperty("connectionPool.validationRequest", "g.inject()");
final Settings settings = Settings.from(conf);
@@ -82,7 +85,7 @@ public class SettingsTest {
assertEquals(Arrays.asList("255.0.0.1", "255.0.0.2", "255.0.0.3"), settings.hosts);
assertEquals("my.serializers.MySerializer", settings.serializer.className);
assertEquals("thing", settings.serializer.config.get("any"));
- assertEquals(true, settings.connectionPool.enableSsl);
+ assertThat(settings.connectionPool.enableSsl, is(true));
assertEquals("X.509", settings.connectionPool.keyCertChainFile);
assertEquals("PKCS#8", settings.connectionPool.keyFile);
assertEquals("password1", settings.connectionPool.keyPassword);
@@ -94,7 +97,7 @@ public class SettingsTest {
assertEquals("password3", settings.connectionPool.trustStorePassword);
assertEquals(Arrays.asList("TLSv1.1","TLSv1.2"), settings.connectionPool.sslEnabledProtocols);
assertEquals(Arrays.asList("TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"), settings.connectionPool.sslCipherSuites);
- assertEquals(true, settings.connectionPool.sslSkipCertValidation);
+ assertThat(settings.connectionPool.sslSkipCertValidation, is(true));
assertEquals(100, settings.connectionPool.minSize);
assertEquals(200, settings.connectionPool.maxSize);
assertEquals(300, settings.connectionPool.minSimultaneousUsagePerConnection);
@@ -107,5 +110,6 @@ public class SettingsTest {
assertEquals(1000, settings.connectionPool.reconnectInitialDelay);
assertEquals(1100, settings.connectionPool.resultIterationBatchSize);
assertEquals("channelizer0", settings.connectionPool.channelizer);
+ assertEquals("g.inject()", settings.connectionPool.validationRequest);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b510613b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index c5ff608..1f759d0 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -285,7 +285,7 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
}
@Test
- public void shouldEventuallySucceedOnSameServer() throws Exception {
+ public void shouldEventuallySucceedOnSameServerWithDefault() throws Exception {
stopServer();
final Cluster cluster = TestClientFactory.open();
@@ -310,6 +310,31 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
}
@Test
+ public void shouldEventuallySucceedOnSameServerWithScript() throws Exception {
+ stopServer();
+
+ final Cluster cluster = TestClientFactory.build().validationRequest("g.inject()").create();
+ final Client client = cluster.connect();
+
+ try {
+ client.submit("1+1").all().join().get(0).getInt();
+ fail("Should not have gone through because the server is not running");
+ } catch (Exception i) {
+ final Throwable root = ExceptionUtils.getRootCause(i);
+ assertThat(root, instanceOf(TimeoutException.class));
+ }
+
+ startServer();
+
+ // default reconnect time is 1 second so wait some extra time to be sure it has time to try to bring it
+ // back to life
+ TimeUnit.SECONDS.sleep(3);
+ assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
+
+ cluster.close();
+ }
+
+ @Test
public void shouldEventuallySucceedWithRoundRobin() throws Exception {
final String noGremlinServer = "74.125.225.19";
final Cluster cluster = TestClientFactory.build().addContactPoint(noGremlinServer).create();
[10/12] tinkerpop git commit: Merge branch 'tp32' of
https://git-wip-us.apache.org/repos/asf/tinkerpop into tp32
Posted by sp...@apache.org.
Merge branch 'tp32' of https://git-wip-us.apache.org/repos/asf/tinkerpop into tp32
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fcbce509
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fcbce509
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fcbce509
Branch: refs/heads/TINKERPOP-2044
Commit: fcbce509fc2957bae74ef585875dd872322a9b21
Parents: b440742 76c9aba
Author: Florian Hockmann <fh...@florian-hockmann.de>
Authored: Wed Oct 3 12:33:23 2018 +0200
Committer: Florian Hockmann <fh...@florian-hockmann.de>
Committed: Wed Oct 3 12:33:23 2018 +0200
----------------------------------------------------------------------
.../traversal/dsl/graph/GraphTraversal.java | 48 ++++++++++++--------
.../step/sideEffect/SideEffectCapStep.java | 4 +-
2 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
[11/12] tinkerpop git commit: Merge branch 'TINKERPOP-2040' into tp32
Posted by sp...@apache.org.
Merge branch 'TINKERPOP-2040' into tp32
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/88d6f778
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/88d6f778
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/88d6f778
Branch: refs/heads/TINKERPOP-2044
Commit: 88d6f778694e6c65ddde6fdcc18948327e01914a
Parents: fcbce50 92c74c3
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Oct 3 15:28:58 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Oct 3 15:28:58 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 +
.../gremlin/jsr223/TranslatorCustomizer.java | 38 ++++
.../gremlin/process/traversal/Translator.java | 34 +++
.../groovy/jsr223/GroovyTranslatorTest.java | 213 ++++++++++++++++---
.../jsr223/GremlinGroovyScriptEngine.java | 15 +-
.../gremlin/groovy/jsr223/GroovyTranslator.java | 34 ++-
6 files changed, 301 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/88d6f778/CHANGELOG.asciidoc
----------------------------------------------------------------------
[06/12] tinkerpop git commit: TINKERPOP-2040 Added more tests to
cover more GraphSON types
Posted by sp...@apache.org.
TINKERPOP-2040 Added more tests to cover more GraphSON types
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/67e2ee85
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/67e2ee85
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/67e2ee85
Branch: refs/heads/TINKERPOP-2044
Commit: 67e2ee85dd8048ca21a72889cf8a0218f2add081
Parents: 774371d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Sep 25 13:46:38 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 1 16:18:28 2018 -0400
----------------------------------------------------------------------
.../groovy/jsr223/GroovyTranslatorTest.java | 30 ++++++++++++++++++++
.../gremlin/groovy/jsr223/GroovyTranslator.java | 4 +++
2 files changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/67e2ee85/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index 686c7bd..c224642 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@ -22,6 +22,9 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.Translator;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
@@ -31,6 +34,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
@@ -185,6 +190,31 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
}
@Test
+ public void shouldHandleColumn() {
+ assertTranslation("Column.keys", Column.keys);
+ }
+
+ @Test
+ public void shouldHandleDirection() {
+ assertTranslation("Direction.BOTH", Direction.BOTH);
+ }
+
+ @Test
+ public void shouldHandleOrder() {
+ assertTranslation("Order.decr", Order.decr);
+ }
+
+ @Test
+ public void shouldHandlePop() {
+ assertTranslation("Pop.last", Pop.last);
+ }
+
+ @Test
+ public void shouldHandleScope() {
+ assertTranslation("Scope.local", Scope.local);
+ }
+
+ @Test
public void shouldOverrideDefaultTypeTranslationWithSomethingBonkers() {
final String thingToSuffixAllStringsWith = "-why-would-anyone-do-this";
final String script = GroovyTranslator.of("g", x -> x instanceof String ? x + thingToSuffixAllStringsWith : x).
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/67e2ee85/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
index 1d122c6..9cd7791 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
@@ -22,7 +22,9 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223;
import groovy.json.StringEscapeUtils;
import org.apache.commons.configuration.ConfigurationConverter;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Translator;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
@@ -32,6 +34,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent
import org.apache.tinkerpop.gremlin.process.traversal.strategy.TraversalStrategyProxy;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Vertex;
[08/12] tinkerpop git commit: Expose WebSocket configuration
TINKERPOP-2015
Posted by sp...@apache.org.
Expose WebSocket configuration TINKERPOP-2015
Users can now provide a delegate to the Gremlin.Net driver that will be
used to configure WebSocket connections.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b4407423
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b4407423
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b4407423
Branch: refs/heads/TINKERPOP-2044
Commit: b440742393135fdd88d4af18b09ade5f5011133e
Parents: e7af98b
Author: Florian Hockmann <fh...@florian-hockmann.de>
Authored: Sun Sep 9 14:49:03 2018 +0200
Committer: Florian Hockmann <fh...@florian-hockmann.de>
Committed: Wed Oct 3 12:08:14 2018 +0200
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../src/Gremlin.Net/Driver/Connection.cs | 6 +++--
.../src/Gremlin.Net/Driver/ConnectionFactory.cs | 8 +++++--
.../src/Gremlin.Net/Driver/GremlinClient.cs | 9 +++++--
.../Gremlin.Net/Driver/WebSocketConnection.cs | 9 +++++--
.../Driver/GremlinClientTests.cs | 25 ++++++++++++++++++++
6 files changed, 50 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index e93c1c9..36a34f2 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Removed conflicting non-indy groovy core dependency
* Bumped jython-standalone 2.7.1
+* Added a delegate to the Gremlin.Net driver that can be used to configure the WebSocket connection.
* SSL security enhancements
* Added Gremlin version to Gremlin Server startup logging output.
* Fixed problem with Gremlin Server sometimes returning an additional message after a failure.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
index dbbd375..f63e20b 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -23,6 +23,7 @@
using System;
using System.Collections.Generic;
+using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
using Gremlin.Net.Driver.Messages;
@@ -38,18 +39,19 @@ namespace Gremlin.Net.Driver
private readonly GraphSONWriter _graphSONWriter;
private readonly JsonMessageSerializer _messageSerializer = new JsonMessageSerializer();
private readonly Uri _uri;
- private readonly WebSocketConnection _webSocketConnection = new WebSocketConnection();
+ private readonly WebSocketConnection _webSocketConnection;
private readonly string _username;
private readonly string _password;
public Connection(Uri uri, string username, string password, GraphSONReader graphSONReader,
- GraphSONWriter graphSONWriter)
+ GraphSONWriter graphSONWriter, Action<ClientWebSocketOptions> webSocketConfiguration)
{
_uri = uri;
_username = username;
_password = password;
_graphSONReader = graphSONReader;
_graphSONWriter = graphSONWriter;
+ _webSocketConnection = new WebSocketConnection(webSocketConfiguration);
}
public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage requestMessage)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
index 0041a67..8b14ed9 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionFactory.cs
@@ -21,6 +21,8 @@
#endregion
+using System;
+using System.Net.WebSockets;
using Gremlin.Net.Structure.IO.GraphSON;
namespace Gremlin.Net.Driver
@@ -29,20 +31,22 @@ namespace Gremlin.Net.Driver
{
private readonly GraphSONReader _graphSONReader;
private readonly GraphSONWriter _graphSONWriter;
+ private readonly Action<ClientWebSocketOptions> _webSocketConfiguration;
private readonly GremlinServer _gremlinServer;
public ConnectionFactory(GremlinServer gremlinServer, GraphSONReader graphSONReader,
- GraphSONWriter graphSONWriter)
+ GraphSONWriter graphSONWriter, Action<ClientWebSocketOptions> webSocketConfiguration)
{
_gremlinServer = gremlinServer;
_graphSONReader = graphSONReader;
_graphSONWriter = graphSONWriter;
+ _webSocketConfiguration = webSocketConfiguration;
}
public Connection CreateConnection()
{
return new Connection(_gremlinServer.Uri, _gremlinServer.Username, _gremlinServer.Password, _graphSONReader,
- _graphSONWriter);
+ _graphSONWriter, _webSocketConfiguration);
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
index 46dd8a6..a5cb46c 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs
@@ -23,6 +23,7 @@
using System;
using System.Collections.Generic;
+using System.Net.WebSockets;
using System.Threading.Tasks;
using Gremlin.Net.Driver.Messages;
using Gremlin.Net.Structure.IO.GraphSON;
@@ -42,12 +43,16 @@ namespace Gremlin.Net.Driver
/// <param name="gremlinServer">The <see cref="GremlinServer" /> the requests should be sent to.</param>
/// <param name="graphSONReader">A <see cref="GraphSONReader" /> instance to read received GraphSON data.</param>
/// <param name="graphSONWriter">a <see cref="GraphSONWriter" /> instance to write GraphSON data.</param>
+ /// <param name="webSocketConfiguration">
+ /// A delegate that will be invoked with the <see cref="ClientWebSocketOptions" />
+ /// object used to configure WebSocket connections.
+ /// </param>
public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader = null,
- GraphSONWriter graphSONWriter = null)
+ GraphSONWriter graphSONWriter = null, Action<ClientWebSocketOptions> webSocketConfiguration = null)
{
var reader = graphSONReader ?? new GraphSONReader();
var writer = graphSONWriter ?? new GraphSONWriter();
- var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer);
+ var connectionFactory = new ConnectionFactory(gremlinServer, reader, writer, webSocketConfiguration);
_connectionPool = new ConnectionPool(connectionFactory);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
index b5a4cc8..aefa32a 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs
@@ -33,11 +33,16 @@ namespace Gremlin.Net.Driver
{
private const int ReceiveBufferSize = 1024;
private const WebSocketMessageType MessageType = WebSocketMessageType.Binary;
- private ClientWebSocket _client;
+ private readonly ClientWebSocket _client;
- public async Task ConnectAsync(Uri uri)
+ public WebSocketConnection(Action<ClientWebSocketOptions> webSocketConfiguration)
{
_client = new ClientWebSocket();
+ webSocketConfiguration?.Invoke(_client.Options);
+ }
+
+ public async Task ConnectAsync(Uri uri)
+ {
await _client.ConnectAsync(uri, CancellationToken.None).ConfigureAwait(false);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b4407423/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
index 351b83d..9a421d5 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Driver/GremlinClientTests.cs
@@ -23,6 +23,7 @@
using System;
using System.Collections.Generic;
+using System.Net.WebSockets;
using System.Threading.Tasks;
using Gremlin.Net.Driver;
using Gremlin.Net.Driver.Exceptions;
@@ -208,5 +209,29 @@ namespace Gremlin.Net.IntegrationTest.Driver
Assert.Equal(a + b, response);
}
}
+
+ [Fact]
+ public async Task ShouldConfigureWebSocketOptionsAsSpecified()
+ {
+ var gremlinServer = new GremlinServer(TestHost, TestPort);
+ ClientWebSocketOptions optionsSet = null;
+ var expectedKeepAliveInterval = TimeSpan.FromMilliseconds(11);
+ var webSocketConfiguration =
+ new Action<ClientWebSocketOptions>(options =>
+ {
+ options.UseDefaultCredentials = false;
+ options.KeepAliveInterval = expectedKeepAliveInterval;
+ optionsSet = options;
+ });
+ using (var gremlinClient = new GremlinClient(gremlinServer, webSocketConfiguration: webSocketConfiguration))
+ {
+ // send dummy message to create at least one connection
+ await gremlinClient.SubmitAsync(_requestMessageProvider.GetDummyMessage());
+
+ Assert.NotNull(optionsSet);
+ Assert.False(optionsSet.UseDefaultCredentials);
+ Assert.Equal(expectedKeepAliveInterval, optionsSet.KeepAliveInterval);
+ }
+ }
}
}
\ No newline at end of file
[03/12] tinkerpop git commit: TINKERPOP-2040 Updated changelog
Posted by sp...@apache.org.
TINKERPOP-2040 Updated changelog
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/92c74c3d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/92c74c3d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/92c74c3d
Branch: refs/heads/TINKERPOP-2044
Commit: 92c74c3d7ffc25b234187ef2459f8d3d529ac8db
Parents: e5c2e9c
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Oct 1 09:12:30 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 1 16:18:28 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/92c74c3d/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6d9770f..9160d09 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -37,6 +37,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Added synchronized `Map` to Gryo 1.0 registrations.
* Added `Triple` to Gryo 1.0 registrations.
* Improved escaping of special characters in strings passed to the `GroovyTranslator`.
+* Improved ability of `GroovyTranslator` to handle more types supported by GraphSON.
+* Improved ability of `GroovyTranslator` to handle custom types.
* Added better internal processing of `Column` in `by(Function)`.
* Added `hasNext()` support on `Traversal` for `gremlin-python`.
* Added support for additional extended types in Gremlin.Net with `decimal`, `TimeSpan`, `BigInteger`, `byte`, `byte[]`, `char` and `short`.