tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject incubator-tinkerpop git commit: TINKERPOP3-955 Registered HashMap$Node to GryoMapper.
Date Wed, 11 Nov 2015 16:44:45 GMT
Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP3-955 [created] 8b70c5cf8


TINKERPOP3-955 Registered HashMap$Node to GryoMapper.

Note that this class had to be registered via reflection as it is a private class of HashMap.
Added tests to validate that the change works with the code specified in the issue.


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

Branch: refs/heads/TINKERPOP3-955
Commit: 8b70c5cf81ac0fbd5246489c91ef864ae2247495
Parents: 49e2b35
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Nov 11 11:42:44 2015 -0500
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Nov 11 11:42:44 2015 -0500

----------------------------------------------------------------------
 .../gremlin/structure/io/gryo/GryoMapper.java   | 19 ++++++++++++-
 .../server/GremlinResultSetIntegrateTest.java   | 29 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8b70c5cf/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 5a0b516..1fec5c8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -174,6 +174,22 @@ public final class GryoMapper implements Mapper<Kryo> {
         private static final Class LINKED_HASH_MAP_ENTRY_CLASS = m.entrySet().iterator().next().getClass();
 
         /**
+         * The {@code HashMap$Node} class comes into serialization play when a {@code Map.entrySet()}
is
+         * serialized.
+         */
+        private static final Class HASH_MAP_NODE;
+
+        static {
+            // have to instantiate this via reflection because it is a private inner class
of HashMap
+            final String className = HashMap.class.getName() + "$Node";
+            try {
+                HASH_MAP_NODE = Class.forName(className);
+            } catch (Exception ex) {
+                throw new RuntimeException("Could not access " + className, ex);
+            }
+        }
+
+        /**
          * Note that the following are pre-registered boolean, Boolean, byte, Byte, char,
Character, double, Double,
          * int, Integer, float, Float, long, Long, short, Short, String, void.
          */
@@ -212,6 +228,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(EnumSet.class,
null, 46));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(HashMap.class,
null, 11));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(HashMap.Entry.class,
null, 16));
+            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(HASH_MAP_NODE,
null, 92));   // ***LAST ID**
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(KryoSerializable.class,
null, 36));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(LinkedHashMap.class,
null, 47));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(LinkedHashSet.class,
null, 71));
@@ -248,7 +265,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(B_LP_O_S_SE_SL_Traverser.class,
null, 87));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(O_OB_S_SE_SL_Traverser.class,
null, 89));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(LP_O_OB_S_SE_SL_Traverser.class,
null, 90));
-            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(LP_O_OB_P_S_SE_SL_TraverserGenerator.class,
null, 91)); // ***LAST ID**
+            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(LP_O_OB_P_S_SE_SL_TraverserGenerator.class,
null, 91));
 
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(TraverserSet.class,
null, 58));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Tree.class,
null, 61));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8b70c5cf/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
index 7315e71..1128d5a 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.server;
 
 import org.apache.tinkerpop.gremlin.driver.Client;
 import org.apache.tinkerpop.gremlin.driver.Cluster;
+import org.apache.tinkerpop.gremlin.driver.Result;
 import org.apache.tinkerpop.gremlin.driver.ResultSet;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
 import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -36,7 +37,12 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.IsInstanceOf.instanceOf;
 import static org.junit.Assert.assertEquals;
@@ -119,4 +125,27 @@ public class GremlinResultSetIntegrateTest extends AbstractGremlinServerIntegrat
         final Path p = results.all().get().get(0).getPath();
         assertThat(p, instanceOf(DetachedPath.class));
     }
+
+    @Test
+    public void shouldHandleMapIteratedResult() throws Exception {
+        final ResultSet results = client.submit("g.V().groupCount().by(bothE().count())");
+        final List<Result> resultList = results.all().get();
+        final Map m = resultList.get(0).get(HashMap.class);
+        assertEquals(2, m.size());
+        assertEquals(3l, m.get(1l));
+        assertEquals(3l, m.get(3l));
+    }
+
+    @Test
+    public void shouldHandleMapObjectResult() throws Exception {
+        final ResultSet results = client.submit("g.V().groupCount().by(bothE().count()).next()");
+        final List<Result> resultList = results.all().get();
+        assertEquals(2, resultList.size());
+        final Map.Entry firstEntry = resultList.get(0).get(HashMap.Entry.class);
+        final Map.Entry secondEntry = resultList.get(1).get(HashMap.Entry.class);
+        assertThat(firstEntry.getKey(), anyOf(is(3l), is(1l)));
+        assertThat(firstEntry.getValue(), is(3l));
+        assertThat(secondEntry.getKey(), anyOf(is(3l), is(1l)));
+        assertThat(secondEntry.getValue(), is(3l));
+    }
 }


Mime
View raw message