You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dm...@apache.org on 2016/03/18 04:12:06 UTC
[2/2] incubator-tinkerpop git commit: Added mentions to notice. Added
tests and made a slight correction to serialization
Added mentions to notice. Added tests and made a slight correction to serialization
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/edb61f5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/edb61f5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/edb61f5e
Branch: refs/heads/TINKERPOP-732
Commit: edb61f5e356dc30fc75a318bbf41e887f6bd361b
Parents: c01f197
Author: Dylan Millikin <dm...@apache.org>
Authored: Thu Mar 17 23:11:30 2016 -0400
Committer: Dylan Millikin <dm...@apache.org>
Committed: Thu Mar 17 23:11:30 2016 -0400
----------------------------------------------------------------------
gremlin-console/src/main/static/NOTICE | 26 +++++++++++-
.../structure/io/graphson/GraphSONModule.java | 4 +-
.../io/graphson/GraphSONSerializers.java | 12 +++---
...raphSONMessageSerializerGremlinV1d0Test.java | 37 ++++++++++++++++-
.../ser/GraphSONMessageSerializerV1d0Test.java | 43 ++++++++++++++++++++
gremlin-server/src/main/static/NOTICE | 26 +++++++++++-
gremlin-shaded/pom.xml | 2 +-
.../gremlin/structure/SerializationTest.java | 23 ++++++++++-
8 files changed, 160 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-console/src/main/static/NOTICE
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/static/NOTICE b/gremlin-console/src/main/static/NOTICE
index b9fa6eb..0901755 100644
--- a/gremlin-console/src/main/static/NOTICE
+++ b/gremlin-console/src/main/static/NOTICE
@@ -56,4 +56,28 @@ Copyright (c) 2010, The JAVATUPLES team (http://www.javatuples.org)
------------------------------------------------------------------------
Netty
------------------------------------------------------------------------
-Copyright 2014 The Netty Project
\ No newline at end of file
+Copyright 2014 The Netty Project
+
+------------------------------------------------------------------------
+Jackson databind - shaded in gremlin-shaded to org.apache.tinkerpop.shaded.jackson
+------------------------------------------------------------------------
+# Jackson JSON processor
+
+Jackson is a high-performance, Free/Open Source JSON processing library.
+It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
+been in development since 2007.
+It is currently developed by a community of developers, as well as supported
+commercially by FasterXML.com.
+
+## Licensing
+
+Jackson core and extension components may be licensed under different licenses.
+To find the details that apply to this artifact see the accompanying LICENSE file.
+For more information, including possible other licensing options, contact
+FasterXML.com (http://fasterxml.com).
+
+## Credits
+
+A list of contributors may be found from CREDITS file, which is included
+in some artifacts (usually source distributions); but is always available
+from the source code management (SCM) system project uses.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index 075c73b..7cc6c91 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -78,9 +78,9 @@ abstract class GraphSONModule extends SimpleModule {
addSerializer(TraversalMetrics.class, new GraphSONSerializers.TraversalMetricsJacksonSerializer());
addSerializer(TraversalExplanation.class, new GraphSONSerializers.TraversalExplanationJacksonSerializer());
addSerializer(Path.class, new GraphSONSerializers.PathJacksonSerializer());
- addSerializer(Tree.class, new GraphSONSerializers.TreeJacksonSerializer());
addSerializer(StarGraphGraphSONSerializer.DirectionalStarGraph.class, new StarGraphGraphSONSerializer(normalize));
-
+ addSerializer(Tree.class, new GraphSONSerializers.TreeJacksonSerializer());
+
// java.util
addSerializer(Map.Entry.class, new JavaUtilSerializers.MapEntryJacksonSerializer());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializers.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializers.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializers.java
index 0712cd1..cf56218 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializers.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONSerializers.java
@@ -51,7 +51,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
-import org.apache.tinkerpop.gremlin.structure.T;
/**
* GraphSON serializers for graph-based objects such as vertices, edges, properties, and paths. These serializers
@@ -282,12 +281,13 @@ final class GraphSONSerializers {
private static void ser(final Tree tree, final JsonGenerator jsonGenerator, final TypeSerializer typeSerializer)
throws IOException {
jsonGenerator.writeStartObject(); // {
+ if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
- Set<Map.Entry<Element, Tree<T>>> set = tree.entrySet();
- for(Map.Entry<Element, Tree<T>> entry : set)
+ Set<Map.Entry<Element, Tree>> set = tree.entrySet();
+ for(Map.Entry<Element, Tree> entry : set)
{
- jsonGenerator.writeObjectFieldStart(entry.getKey().id().toString());
- if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
+ jsonGenerator.writeObjectFieldStart(entry.getKey().id().toString());
+ if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey());
jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue());
jsonGenerator.writeEndObject();
@@ -295,7 +295,7 @@ final class GraphSONSerializers {
jsonGenerator.writeEndObject();
}
}
-
+
/**
* Maps in the JVM can have {@link Object} as a key, but in JSON they must be a {@link String}.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0Test.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0Test.java
index de719c1..7ff6a7e 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0Test.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerGremlinV1d0Test.java
@@ -43,6 +43,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -254,6 +255,40 @@ public class GraphSONMessageSerializerGremlinV1d0Test {
assertEquals(new Integer(1000), deserializedMap.get("1"));
}
+ @Test
+ public void shouldSerializeToJsonTree() throws Exception {
+ final TinkerGraph graph = TinkerFactory.createClassic();
+ final GraphTraversalSource g = graph.traversal();
+ //final Iterable<Tree> iterable = IteratorUtils.list(g.V(1).out().properties("name").tree());
+ final Map t = g.V(1).out().properties("name").tree().next();
+
+ final ResponseMessage response = convert(t);
+ assertCommon(response);
+
+ final Map<String, Map<String, Map>> deserializedMap = (Map<String, Map<String, Map>>) response.getResult().getData();
+
+ assertEquals(1, deserializedMap.size());
+
+ //check the first object and it's properties
+ Map<String,Object> vertex = deserializedMap.get("1").get("key");
+ Map<String,List<Map>> vertexProperties = (Map<String, List<Map>>)vertex.get("properties");
+ assertEquals(1, (int)vertex.get("id"));
+ assertEquals("marko", vertexProperties.get("name").get(0).get("value"));
+
+ //check objects tree structure
+ //check Vertex property
+ Map<String, Map<String, Map>> subTreeMap = deserializedMap.get("1").get("value");
+ Map<String, Map<String, Map>> subTreeMap2 = subTreeMap.get("2").get("value");
+ Map<String, String> vertexPropertiesDeep = subTreeMap2.get("3").get("key");
+ assertEquals("vadas", vertexPropertiesDeep.get("value"));
+ assertEquals("name", vertexPropertiesDeep.get("label"));
+
+ // check subitem
+ Map<String,Object> vertex2 = subTreeMap.get("3").get("key");
+ Map<String,List<Map>> vertexProperties2 = (Map<String, List<Map>>)vertex2.get("properties");
+
+ assertEquals("lop", vertexProperties2.get("name").get(0).get("value"));
+ }
@Test
public void shouldSerializeFullResponseMessage() throws Exception {
@@ -287,7 +322,7 @@ public class GraphSONMessageSerializerGremlinV1d0Test {
assertEquals(ResponseStatusCode.SUCCESS.getValue(), deserialized.getStatus().getCode().getValue());
assertEquals("worked", deserialized.getStatus().getMessage());
}
-
+
private void assertCommon(final ResponseMessage response) {
assertEquals(requestId, response.getRequestId());
assertEquals(ResponseStatusCode.SUCCESS, response.getStatus().getCode());
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0Test.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0Test.java
index de4b4b6..e9e4f80 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0Test.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GraphSONMessageSerializerV1d0Test.java
@@ -57,6 +57,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
@@ -407,6 +408,48 @@ public class GraphSONMessageSerializerV1d0Test {
assertEquals(ResponseStatusCode.SUCCESS.getValue(), deserialized.getStatus().getCode().getValue());
assertEquals("worked", deserialized.getStatus().getMessage());
}
+
+ @Test
+ public void shouldSerializeToJsonTree() throws Exception {
+ final TinkerGraph graph = TinkerFactory.createClassic();
+ final GraphTraversalSource g = graph.traversal();
+ //final Iterable<Tree> iterable = IteratorUtils.list(g.V(1).out().properties("name").tree());
+ final Tree t = g.V(1).out().properties("name").tree().next();
+
+
+ final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(t).create());
+
+ final JsonNode json = mapper.readTree(results);
+
+ assertNotNull(json);
+ assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
+ final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);
+ assertNotNull(converted);
+
+ //check the first object and it's properties
+ assertEquals(1, converted.get("1").get("key").get("id").asInt());
+ assertEquals("marko", converted.get("1").get("key").get("properties").get("name").get(0).get("value").asText());
+
+ //check objects tree structure
+ //check Vertex property
+ assertEquals("vadas", converted.get("1")
+ .get("value")
+ .get("2")
+ .get("value")
+ .get("3").get("key").get("value").asText());
+ assertEquals("name", converted.get("1")
+ .get("value")
+ .get("2")
+ .get("value")
+ .get("3").get("key").get("label").asText());
+
+ // check subitem
+ assertEquals("lop", converted.get("1")
+ .get("value")
+ .get("3")
+ .get("key")
+ .get("properties").get("name").get(0).get("value").asText());
+ }
private class FunObject {
private String val;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-server/src/main/static/NOTICE
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/static/NOTICE b/gremlin-server/src/main/static/NOTICE
index a767d39..9055cf6 100644
--- a/gremlin-server/src/main/static/NOTICE
+++ b/gremlin-server/src/main/static/NOTICE
@@ -57,4 +57,28 @@ LongAdder), which was released with the following comments:
------------------------------------------------------------------------
Netty
------------------------------------------------------------------------
-Copyright 2014 The Netty Project
\ No newline at end of file
+Copyright 2014 The Netty Project
+
+------------------------------------------------------------------------
+Jackson databind - shaded in gremlin-shaded to org.apache.tinkerpop.shaded.jackson
+------------------------------------------------------------------------
+# Jackson JSON processor
+
+Jackson is a high-performance, Free/Open Source JSON processing library.
+It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
+been in development since 2007.
+It is currently developed by a community of developers, as well as supported
+commercially by FasterXML.com.
+
+## Licensing
+
+Jackson core and extension components may be licensed under different licenses.
+To find the details that apply to this artifact see the accompanying LICENSE file.
+For more information, including possible other licensing options, contact
+FasterXML.com (http://fasterxml.com).
+
+## Credits
+
+A list of contributors may be found from CREDITS file, which is included
+in some artifacts (usually source distributions); but is always available
+from the source code management (SCM) system project uses.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-shaded/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-shaded/pom.xml b/gremlin-shaded/pom.xml
index 56f7dd4..d3eeb55 100644
--- a/gremlin-shaded/pom.xml
+++ b/gremlin-shaded/pom.xml
@@ -50,7 +50,7 @@ limitations under the License.
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<!-- Update the shade plugin config whenever you change this version -->
- <version>2.7.0</version>
+ <version>2.7.2</version>
<optional>true</optional>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/edb61f5e/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
index 5fb8fb0..87afa7d 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/SerializationTest.java
@@ -47,6 +47,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*;
@@ -223,8 +224,28 @@ public class SerializationTest {
assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS));
assertEquals(before.getMetrics(0).getCounts(), after.getMetrics(0).getCounts());
}
- }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldSerializeTree() throws Exception {
+ final GryoIo gryoIo = graph.io(GryoIo.build());
+ final GryoWriter gryoWriter = gryoIo.writer().create();
+ final GryoReader gryoReader = gryoIo.reader().create();
+ final Tree before = g.V(1).out().properties("name").tree().next();
+
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ gryoWriter.writeObject(outputStream, before);
+
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ final Tree after = gryoReader.readObject(inputStream, Tree.class);
+ assertNotNull(after);
+ //Seeing as Tree implements Serializable the following assertions should be sufficent.
+ assertThat("Type does not match", after, instanceOf(Tree.class));
+ assertEquals("The objects differ", after, before);
+ }
+ }
+
public static class GraphSONTest extends AbstractGremlinTest {
private final TypeReference<HashMap<String, Object>> mapTypeReference = new TypeReference<HashMap<String, Object>>() {
};