Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1457 [created] 6b03f6172


Fixed Lambda serialization in bytecode for java/groovy.

Standard tests using lambdas are ignored which is why we didn't catch this in 
the process tests. I added a single test to GremlinServerIntegrationTest to 
just validate that lambdas could be sent, so we at least have a basic smoke 
test for that functionality.


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

Branch: refs/heads/TINKERPOP-1457
Commit: 6b03f61723837809c61951a516d5a8207d8d18f1
Parents: f8092a1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Sep 20 16:24:34 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Sep 20 16:27:50 2016 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../io/graphson/GraphSONTypeSerializer.java     |  3 +++
 .../structure/io/gryo/GryoSerializers.java      |  7 ++++-
 .../AbstractGremlinServerIntegrationTest.java   |  2 +-
 .../server/GremlinServerIntegrateTest.java      | 27 ++++++++++++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b03f617/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 394cc33..a1b405f 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,7 @@ TinkerPop 3.2.3 (Release Date: NOT OFFICIALLY RELEASED YET)
 
 * Fixed a bug in Gremlin-Python `P` where predicates reversed the order of the 
predicates.
 * Added tests to `DedupTest` for the `dedup(Scope, String...)` overload.
+* Fixed a bug in serialization of `Lambda` instances in GraphSON, which 
prevented their use in remote traversals.
 * Fixed a naming bug in Gremlin-Python where `P._and` and `P._or` should be 
`P.and_` and `P.or_`. (*breaking*)
 * `where()` predicate-based steps now support `by()`-modulation.
 * `TraversalRing` returns a `null` if it does not contain traversals 
(previously `IdentityTraversal`).

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b03f617/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializer.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializer.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializer.java
index d1a70af..6198168 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializer.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTypeSerializer.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Property;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
 import org.apache.tinkerpop.shaded.jackson.annotation.JsonTypeInfo;
 import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
 import org.apache.tinkerpop.shaded.jackson.databind.BeanProperty;
@@ -198,6 +199,8 @@ public class GraphSONTypeSerializer extends TypeSerializer {
             return InetAddress.class;
         } else if (Traverser.class.isAssignableFrom(c)) {
             return Traverser.class;
+        } else if (Lambda.class.isAssignableFrom(c)) {
+            return Lambda.class;
         }
         return c;
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b03f617/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
index f543446..945af87 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
@@ -27,6 +27,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
@@ -125,7 +126,11 @@ public final class GryoSerializers {
     }
 
     public final static class BytecodeSerializer implements 
SerializerShim<Bytecode> {
-        private static final GraphSONMapper mapper = 
GraphSONMapper.build().version(GraphSONVersion.V2_0).create();
+        private static final GraphSONMapper mapper = GraphSONMapper.build()
+                .version(GraphSONVersion.V2_0)
+                .addCustomModule(GraphSONXModuleV2d0.build().create(false))
+                .create();
+
         @Override
         public <O extends OutputShim> void write(final KryoShim<?, O> kryo, 
final O output, final Bytecode bytecode) {
             try {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b03f617/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/AbstractGremlinServerIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/AbstractGremlinServerIntegrationTest.java
 
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/AbstractGremlinServerIntegrationTest.java
index ba47218..12fadb6 100644
--- 
a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/AbstractGremlinServerIntegrationTest.java
+++ 
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/AbstractGremlinServerIntegrationTest.java
@@ -37,7 +37,7 @@ import static org.junit.Assume.assumeThat;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public abstract class AbstractGremlinServerIntegrationTest {
-    private GremlinServer server;
+    protected GremlinServer server;
     private final static String epollOption = "gremlin.server.epoll";
     private static final boolean GREMLIN_SERVER_EPOLL = 
"true".equalsIgnoreCase(System.getProperty(epollOption));
     private static final Logger logger = 
LoggerFactory.getLogger(AbstractGremlinServerIntegrationTest.class);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6b03f617/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
 
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
index e1d4d89..5a36acf 100644
--- 
a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
+++ 
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerIntegrateTest.java
@@ -25,6 +25,8 @@ import io.netty.handler.ssl.SslContextBuilder;
 import io.netty.handler.ssl.SslProvider;
 import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
 import io.netty.handler.ssl.util.SelfSignedCertificate;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.log4j.Logger;
 import org.apache.tinkerpop.gremlin.driver.Client;
@@ -35,6 +37,7 @@ import org.apache.tinkerpop.gremlin.driver.Tokens;
 import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
 import org.apache.tinkerpop.gremlin.driver.ser.Serializers;
 import org.apache.tinkerpop.gremlin.driver.simple.NioClient;
 import org.apache.tinkerpop.gremlin.driver.simple.SimpleClient;
@@ -45,11 +48,16 @@ import 
org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustom
 import 
org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider;
 import 
org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension;
 import 
org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider;
+import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
+import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.server.channel.NioChannelizer;
 import org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
 import org.apache.tinkerpop.gremlin.util.Log4jRecordingAppender;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
 import org.hamcrest.CoreMatchers;
 import org.junit.After;
 import org.junit.Before;
@@ -67,9 +75,11 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
+import static 
org.apache.tinkerpop.gremlin.process.traversal.TraversalSource.GREMLIN_REMOTE_CONNECTION_CLASS;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -801,4 +811,21 @@ public class GremlinServerIntegrateTest extends 
AbstractGremlinServerIntegration
             assertEquals("jason", v.value("name"));
         }
     }
+
+    @Test
+    public void shouldSupportLambdasUsingWithRemote() throws Exception {
+        final Supplier<Graph> graphGetter = () -> 
server.getServerGremlinExecutor().getGraphManager().getGraphs().get("graph");
+        final Configuration conf = new BaseConfiguration() {{
+            setProperty(Graph.GRAPH, RemoteGraph.class.getName());
+            setProperty(GREMLIN_REMOTE_CONNECTION_CLASS, 
DriverRemoteConnection.class.getName());
+            
setProperty(DriverRemoteConnection.GREMLIN_REMOTE_DRIVER_SOURCENAME, "g");
+            setProperty("hidden.for.testing.only", graphGetter);
+        }};
+
+        final Graph graph = EmptyGraph.instance();
+        final GraphTraversalSource g = graph.traversal().withRemote(conf);
+        g.addV("person").property("age", 20).iterate();
+        g.addV("person").property("age", 10).iterate();
+        assertEquals(50L, 
g.V().hasLabel("person").map(Lambda.function("it.get().value('age') + 
10")).sum().next());
+    }
 }

Reply via email to