TINKERPOP-1414 Changed Gremlin Server and TinkerGraph to default GraphSON 2.0
This work is done as part of TINKERPOP-1565 which is related to GraphSON 2.0 changes. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fc9ce593 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fc9ce593 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fc9ce593 Branch: refs/heads/TINKERPOP-1565 Commit: fc9ce59338bd3cf4588a43d0e9ac139547ad19ab Parents: 612bcb3 Author: Stephen Mallette <sp...@genoprime.com> Authored: Wed Dec 7 10:37:04 2016 -0500 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Wed Jan 18 12:11:33 2017 -0500 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + docs/src/upgrade/release-3.3.x.asciidoc | 65 +++++- .../structure/io/graphson/GraphSONIo.java | 2 +- .../structure/io/graphson/GraphSONMapper.java | 4 +- gremlin-server/conf/gremlin-server-classic.yaml | 12 +- .../conf/gremlin-server-modern-py.yaml | 12 +- .../conf/gremlin-server-modern-readonly.yaml | 12 +- gremlin-server/conf/gremlin-server-modern.yaml | 12 +- gremlin-server/conf/gremlin-server-neo4j.yaml | 12 +- .../conf/gremlin-server-rest-modern.yaml | 6 +- .../conf/gremlin-server-rest-secure.yaml | 6 +- gremlin-server/conf/gremlin-server-secure.yaml | 12 +- gremlin-server/conf/gremlin-server-spark.yaml | 12 +- gremlin-server/conf/gremlin-server.yaml | 12 +- .../gremlin/server/AbstractChannelizer.java | 5 +- .../server/GremlinServerAuthIntegrateTest.java | 16 +- .../GremlinServerAuthOldIntegrateTest.java | 20 +- .../server/GremlinServerHttpIntegrateTest.java | 31 +-- .../server/GremlinServerIntegrateTest.java | 2 +- .../remote/gremlin-server-integration.yaml | 6 +- .../server/gremlin-server-integration.yaml | 6 +- .../gremlin/structure/SerializationTest.java | 229 ++++++++++++++++++- .../tinkerpop/gremlin/structure/io/IoTest.java | 143 +++++++++++- .../tinkergraph/structure/TinkerGraph.java | 2 +- 24 files changed, 521 insertions(+), 119 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 764c44d..112e7c5 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -29,6 +29,7 @@ TinkerPop 3.3.0 (Release Date: NOT OFFICIALLY RELEASED YET) * Added more specific typing to various `__` traversal steps. E.g. `<A,Vertex>out()` is `<Vertex,Vertex>out()`. * Updated Docker build scripts to include Python dependencies (NOTE: users should remove any previously generated TinkerPop Docker images). * Added "attachment requisite" `VertexProperty.element()` and `Property.element()` data in GraphSON serialization. +* GraphSON 2.0 is now the default serialization format in TinkerGraph and Gremlin Server. * Added `Vertex`, `Edge`, `VertexProperty`, and `Property` serializers to Gremlin-Python and exposed tests that use graph object arguments. * `Bytecode.getSourceInstructions()` and `Bytecode.getStepInstructions()` now returns `List<Instruction>` instead of `Iterable<Instruction>`. * Added various `TraversalStrategy` registrations with `GryoMapper`. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/docs/src/upgrade/release-3.3.x.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc index 9233d57..4e43077 100644 --- a/docs/src/upgrade/release-3.3.x.asciidoc +++ b/docs/src/upgrade/release-3.3.x.asciidoc @@ -32,6 +32,69 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.3.3/CHANGELOG.asc Upgrading for Users ~~~~~~~~~~~~~~~~~~~ +GraphSON 2.0 +^^^^^^^^^^^^ + +Both TinkerGraph and Gremlin Server have been defaulted to work with GraphSON 2.0. For TinkerGraph this means that +the following commands: + +[source,java] +---- +Graph graph = TinkerFactory.createModern(); +graph.io(IoCore.graphson()).writeGraph("tinkerpop-modern.json"); + +final Graph newGraph = TinkerGraph.open(); +newGraph.io(IoCore.graphson()).readGraph("tinkerpop-modern.json"); +---- + +will write and read GraphSON 2.0 format rather than 1.0. To use 1.0 format simply set the `version()` on the +appropriate builder methods: + +[source,java] +---- +Graph graph = TinkerFactory.createModern(); +GraphSONMapper mapper = graph.io(IoCore.graphson()).mapper().version(GraphSONVersion.V1_0).create() +try (OutputStream os = new FileOutputStream("tinkerpop-modern.json")) { + graph.io(IoCore.graphson()).writer().mapper(mapper).create().writeGraph(os, graph) +} + +final Graph newGraph = TinkerGraph.open(); +try (InputStream stream = new FileInputStream("tinkerpop-modern.json")) { + newGraph.io(IoCore.graphson()).reader().mapper(mapper).vertexIdKey("name").create().readGraph(stream, newGraph); +} +---- + +For Gremlin Server, this change means that the `application/json` mime type no longer returns GraphSON 1.0 without +type embedding. Instead, Gremlin Server will return GraphSON 2.0 with partial types enabled (i.e. which is equivalent +to `application/vnd.gremlin-v2.0+json`). The `serializers` section the sample Gremlin Server YAML files now typically +look like this: + +[source,yaml] +---- +serializers: + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json +---- + +It is possible to bring back the original configuration for `application/json` by changing the last entry as follows: + +[source,yaml] +---- +serializers: + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json +---- + +See: link:https://issues.apache.org/jira/browse/TINKERPOP-1414[TINKERPOP-1414] + GraphTraversal Has-Methods Re-Organized ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,4 +239,4 @@ If the old `GryoSerializer` model is desired, then the properties file should si spark.serializer=org.apache.tinkerpop.gremlin.spark.structure.io.gryo.GryoSerializer ``` -See: link:https://issues.apache.org/jira/browse/TINKERPOP-1389 \ No newline at end of file +See: link:https://issues.apache.org/jira/browse/TINKERPOP-1389 http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java index f56afb9..0c92e1c 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java @@ -101,7 +101,7 @@ public final class GraphSONIo implements Io<GraphSONReader.Builder, GraphSONWrit * Create a new builder using the default version of GraphSON. */ public static Io.Builder<GraphSONIo> build() { - return build(GraphSONVersion.V1_0); + return build(GraphSONVersion.V2_0); } /** http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java index 7e46c98..f82ebb7 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java @@ -181,7 +181,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> { private boolean normalize = false; private boolean embedTypes = false; private List<IoRegistry> registries = new ArrayList<>(); - private GraphSONVersion version = GraphSONVersion.V1_0; + private GraphSONVersion version = GraphSONVersion.V2_0; // GraphSON 2.0 should have types activated by default, otherwise use there's no point in using it instead of 1.0. private TypeInfo typeInfo = TypeInfo.PARTIAL_TYPES; @@ -198,7 +198,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> { } /** - * Set the version of GraphSON to use. The default is {@link GraphSONVersion#V1_0}. + * Set the version of GraphSON to use. The default is {@link GraphSONVersion#V2_0}. */ public Builder version(final GraphSONVersion version) { this.version = version; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-classic.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-classic.yaml b/gremlin-server/conf/gremlin-server-classic.yaml index ac78da0..d1cbbf3 100644 --- a/gremlin-server/conf/gremlin-server-classic.yaml +++ b/gremlin-server/conf/gremlin-server-classic.yaml @@ -28,12 +28,12 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/generate-classic.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json metrics: { slf4jReporter: {enabled: true, interval: 180000}} strictTransactionManagement: false http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-modern-py.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-modern-py.yaml b/gremlin-server/conf/gremlin-server-modern-py.yaml index e00eb1d..ff8228f 100644 --- a/gremlin-server/conf/gremlin-server-modern-py.yaml +++ b/gremlin-server/conf/gremlin-server-modern-py.yaml @@ -43,12 +43,12 @@ scriptEngines: { gremlin-python: {} } serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json metrics: { slf4jReporter: {enabled: true, interval: 180000}} strictTransactionManagement: false http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-modern-readonly.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-modern-readonly.yaml b/gremlin-server/conf/gremlin-server-modern-readonly.yaml index 379b358..18f7ca4 100644 --- a/gremlin-server/conf/gremlin-server-modern-readonly.yaml +++ b/gremlin-server/conf/gremlin-server-modern-readonly.yaml @@ -28,12 +28,12 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/generate-modern-readonly.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json metrics: { slf4jReporter: {enabled: true, interval: 180000}} strictTransactionManagement: false http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-modern.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-modern.yaml b/gremlin-server/conf/gremlin-server-modern.yaml index 4ac5587..b063868 100644 --- a/gremlin-server/conf/gremlin-server-modern.yaml +++ b/gremlin-server/conf/gremlin-server-modern.yaml @@ -28,12 +28,12 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/generate-modern.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json metrics: { slf4jReporter: {enabled: true, interval: 180000}} strictTransactionManagement: false http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-neo4j.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-neo4j.yaml b/gremlin-server/conf/gremlin-server-neo4j.yaml index 8d68c7f..6aac0f2 100644 --- a/gremlin-server/conf/gremlin-server-neo4j.yaml +++ b/gremlin-server/conf/gremlin-server-neo4j.yaml @@ -39,12 +39,12 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/empty-sample.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-rest-modern.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-rest-modern.yaml b/gremlin-server/conf/gremlin-server-rest-modern.yaml index 8c41ee7..1fa23f9 100644 --- a/gremlin-server/conf/gremlin-server-rest-modern.yaml +++ b/gremlin-server/conf/gremlin-server-rest-modern.yaml @@ -29,9 +29,9 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/generate-modern.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json metrics: { slf4jReporter: {enabled: true, interval: 180000}} strictTransactionManagement: false http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-rest-secure.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-rest-secure.yaml b/gremlin-server/conf/gremlin-server-rest-secure.yaml index 646a1e5..8ed8f41 100644 --- a/gremlin-server/conf/gremlin-server-rest-secure.yaml +++ b/gremlin-server/conf/gremlin-server-rest-secure.yaml @@ -42,9 +42,9 @@ scriptEngines: { "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider":[10000], "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider":["org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension"]}}}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-secure.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-secure.yaml b/gremlin-server/conf/gremlin-server-secure.yaml index 5b5e91e..14f7034 100644 --- a/gremlin-server/conf/gremlin-server-secure.yaml +++ b/gremlin-server/conf/gremlin-server-secure.yaml @@ -42,12 +42,12 @@ scriptEngines: { "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider":[10000], "org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider":["org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension"]}}}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server-spark.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server-spark.yaml b/gremlin-server/conf/gremlin-server-spark.yaml index d79185f..3c198f5 100644 --- a/gremlin-server/conf/gremlin-server-spark.yaml +++ b/gremlin-server/conf/gremlin-server-spark.yaml @@ -52,12 +52,12 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/spark.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/conf/gremlin-server.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/conf/gremlin-server.yaml b/gremlin-server/conf/gremlin-server.yaml index 8cf2947..d4e2849 100644 --- a/gremlin-server/conf/gremlin-server.yaml +++ b/gremlin-server/conf/gremlin-server.yaml @@ -29,12 +29,12 @@ scriptEngines: { staticImports: [java.lang.Math.PI], scripts: [scripts/empty-sample.groovy]}} serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} # application/vnd.gremlin-v2.0+json - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo-lite + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} # application/vnd.gremlin-v1.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v2.0+json + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} # application/json processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java index 57c6994..59238fc 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java @@ -24,9 +24,8 @@ import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.util.SelfSignedCertificate; import org.apache.tinkerpop.gremlin.driver.MessageSerializer; -import org.apache.tinkerpop.gremlin.driver.ser.AbstractGraphSONMessageSerializerV1d0; import org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV1d0; -import org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0; +import org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0; import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0; import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor; import org.apache.tinkerpop.gremlin.server.auth.Authenticator; @@ -72,7 +71,7 @@ public abstract class AbstractChannelizer extends ChannelInitializer<SocketChann new Settings.SerializerSettings(GryoMessageSerializerV1d0.class.getName(), new HashMap<String,Object>(){{ put(AbstractGryoMessageSerializerV1d0.TOKEN_SERIALIZE_RESULT_TO_STRING, true); }}), - new Settings.SerializerSettings(GraphSONMessageSerializerV1d0.class.getName(), Collections.emptyMap()) + new Settings.SerializerSettings(GraphSONMessageSerializerV2d0.class.getName(), Collections.emptyMap()) ); protected Settings settings; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java index 1c5188d..5d0f82e 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthIntegrateTest.java @@ -173,9 +173,9 @@ public class GremlinServerAuthIntegrateTest extends AbstractGremlinServerIntegra final Client client = cluster.connect(); try { - assertEquals(2, client.submit("1+1").all().get().get(0).getInt()); - assertEquals(3, client.submit("1+2").all().get().get(0).getInt()); - assertEquals(4, client.submit("1+3").all().get().get(0).getInt()); + assertEquals(3, client.submit("1+2").all().get().get(0).get(Map.class).get("@value")); + assertEquals(2, client.submit("1+1").all().get().get(0).get(Map.class).get("@value")); + assertEquals(4, client.submit("1+3").all().get().get(0).get(Map.class).get("@value")); } finally { cluster.close(); } @@ -203,12 +203,12 @@ public class GremlinServerAuthIntegrateTest extends AbstractGremlinServerIntegra final Client client = cluster.connect(name.getMethodName()); try { - Map vertex = (Map) client.submit("v=graph.addVertex(\"name\", \"stephen\")").all().get().get(0).getObject(); - Map<String, List<Map>> properties = (Map) vertex.get("properties"); + final Map vertex = (Map) client.submit("v=graph.addVertex(\"name\", \"stephen\")").all().get().get(0).getObject(); + final Map<String, List<Map>> properties = (Map) ((Map) vertex.get("@value")).get("properties"); assertEquals("stephen", properties.get("name").get(0).get("value")); final Map vpName = (Map)client.submit("v.property('name')").all().get().get(0).getObject(); - assertEquals("stephen", vpName.get("value")); + assertEquals("stephen", ((Map) vpName.get("@value")).get("value")); } finally { cluster.close(); } @@ -221,8 +221,8 @@ public class GremlinServerAuthIntegrateTest extends AbstractGremlinServerIntegra final Client client = cluster.connect(name.getMethodName()); try { - Map vertex = (Map) client.submit("v=graph.addVertex('name', 'stephen')").all().get().get(0).getObject(); - Map<String, List<Map>> properties = (Map) vertex.get("properties"); + final Map vertex = (Map) client.submit("v=graph.addVertex('name', 'stephen')").all().get().get(0).getObject(); + final Map<String, List<Map>> properties = (Map) vertex.get("properties"); assertEquals("stephen", properties.get("name").get(0).get("value")); final Map vpName = (Map)client.submit("v.property('name')").all().get().get(0).getObject(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java index f0e2104..c8312ae 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java @@ -179,9 +179,9 @@ public class GremlinServerAuthOldIntegrateTest extends AbstractGremlinServerInte final Client client = cluster.connect(); try { - assertEquals(2, client.submit("1+1").all().get().get(0).getInt()); - assertEquals(3, client.submit("1+2").all().get().get(0).getInt()); - assertEquals(4, client.submit("1+3").all().get().get(0).getInt()); + assertEquals(3, client.submit("1+2").all().get().get(0).get(Map.class).get("@value")); + assertEquals(2, client.submit("1+1").all().get().get(0).get(Map.class).get("@value")); + assertEquals(4, client.submit("1+3").all().get().get(0).get(Map.class).get("@value")); } finally { cluster.close(); } @@ -209,12 +209,12 @@ public class GremlinServerAuthOldIntegrateTest extends AbstractGremlinServerInte final Client client = cluster.connect(name.getMethodName()); try { - Map vertex = (Map) client.submit("v=graph.addVertex(\"name\", \"stephen\")").all().get().get(0).getObject(); - Map<String, List<Map>> properties = (Map) vertex.get("properties"); + final Map vertex = (Map) client.submit("v=graph.addVertex(\"name\", \"stephen\")").all().get().get(0).getObject(); + final Map<String, List<Map>> properties = (Map) ((Map) vertex.get("@value")).get("properties"); assertEquals("stephen", properties.get("name").get(0).get("value")); - + final Map vpName = (Map)client.submit("v.property('name')").all().get().get(0).getObject(); - assertEquals("stephen", vpName.get("value")); + assertEquals("stephen", ((Map) vpName.get("@value")).get("value")); } finally { cluster.close(); } @@ -227,10 +227,10 @@ public class GremlinServerAuthOldIntegrateTest extends AbstractGremlinServerInte final Client client = cluster.connect(name.getMethodName()); try { - Map vertex = (Map) client.submit("v=graph.addVertex('name', 'stephen')").all().get().get(0).getObject(); - Map<String, List<Map>> properties = (Map) vertex.get("properties"); + final Map vertex = (Map) client.submit("v=graph.addVertex('name', 'stephen')").all().get().get(0).getObject(); + final Map<String, List<Map>> properties = (Map) vertex.get("properties"); assertEquals("stephen", properties.get("name").get(0).get("value")); - + final Map vpName = (Map)client.submit("v.property('name')").all().get().get(0).getObject(); assertEquals("stephen", vpName.get("value")); } finally { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java index 78109e6..b2a1568 100644 --- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java +++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java @@ -18,6 +18,7 @@ */ package org.apache.tinkerpop.gremlin.server; +import org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0; import org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0; import org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator; import org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer; @@ -77,10 +78,10 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra deleteDirectory(new File("/tmp/neo4j")); settings.graphs.put("graph", "conf/neo4j-empty.properties"); break; - case "should200OnPOSTWithGraphSON2d0AcceptHeaderDefaultResultToJson": + case "should200OnPOSTWithGraphSON1d0AcceptHeaderDefaultResultToJson": settings.serializers.clear(); final Settings.SerializerSettings serializerSettings = new Settings.SerializerSettings(); - serializerSettings.className = GraphSONMessageSerializerV2d0.class.getName(); + serializerSettings.className = GraphSONMessageSerializerV1d0.class.getName(); settings.serializers.add(serializerSettings); break; case "should401OnGETWithNoAuthorizationHeader": @@ -297,7 +298,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(20, node.get("result").get("data").get(0).intValue()); + assertEquals(20, node.get("result").get("data").get(0).get("@value").intValue()); } } @@ -365,7 +366,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals("stephen", node.get("result").get("data").get(0).get("properties").get("name").get(0).get(GraphSONTokens.VALUE).asText()); + assertEquals("stephen", node.get("result").get("data").get(0).get("@value").get("properties").get("name").get(0).get(GraphSONTokens.VALUE).asText()); } } @@ -379,7 +380,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(20, node.get("result").get("data").get(0).intValue()); + assertEquals(20, node.get("result").get("data").get(0).get("@value").intValue()); } } @@ -449,7 +450,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(Instant.MAX, Instant.parse(node.get("result").get("data").get(0).asText())); + assertEquals(Instant.MAX, Instant.parse(node.get("result").get("data").get(0).get("@value").asText())); } } @@ -467,7 +468,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(1, node.get("result").get("data").get(0).intValue()); + assertEquals(1, node.get("result").get("data").get(0).get("@value").intValue()); } final HttpGet httpget = new HttpGet(TestClientFactory.createURLString("?gremlin=g.V().count()")); @@ -481,7 +482,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(1, node.get("result").get("data").get(0).intValue()); + assertEquals(1, node.get("result").get("data").get(0).get("@value").intValue()); } } } @@ -599,7 +600,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(20, node.get("result").get("data").get(0).intValue()); + assertEquals(20, node.get("result").get("data").get(0).get("@value").intValue()); } } @@ -615,7 +616,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(10, node.get("result").get("data").get(0).intValue()); + assertEquals(10, node.get("result").get("data").get(0).get("@value").intValue()); } } @@ -631,7 +632,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra assertEquals("application/json", response.getEntity().getContentType().getValue()); final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); - assertEquals(10.5d, node.get("result").get("data").get(0).doubleValue(), 0.0001); + assertEquals(10.5d, node.get("result").get("data").get(0).get("@value").doubleValue(), 0.0001); } } @@ -696,9 +697,9 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); assertEquals(true, node.get("result").get("data").isArray()); - assertEquals(1, node.get("result").get("data").get(0).intValue()); - assertEquals(2, node.get("result").get("data").get(1).intValue()); - assertEquals(3, node.get("result").get("data").get(2).intValue()); + assertEquals(1, node.get("result").get("data").get(0).get("@value").intValue()); + assertEquals(2, node.get("result").get("data").get(1).get("@value").intValue()); + assertEquals(3, node.get("result").get("data").get(2).get("@value").intValue()); } } @@ -715,7 +716,7 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra final String json = EntityUtils.toString(response.getEntity()); final JsonNode node = mapper.readTree(json); assertEquals(true, node.get("result").get("data").get(0).isObject()); - assertEquals(1, node.get("result").get("data").get(0).get("y").asInt()); + assertEquals(1, node.get("result").get("data").get(0).get("y").get("@value").asInt()); } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/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 1743e89..96cc132 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 @@ -675,7 +675,7 @@ public class GremlinServerIntegrateTest extends AbstractGremlinServerIntegration @Test public void shouldReceiveFailureOnBadGraphSONSerialization() throws Exception { - final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V1D0).create(); + final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V2D0).create(); final Client client = cluster.connect(); try { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/driver/remote/gremlin-server-integration.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/driver/remote/gremlin-server-integration.yaml b/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/driver/remote/gremlin-server-integration.yaml index a25c6b1..7d23fb9 100644 --- a/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/driver/remote/gremlin-server-integration.yaml +++ b/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/driver/remote/gremlin-server-integration.yaml @@ -35,9 +35,9 @@ serializers: - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph, custom: [groovy.json.JsonBuilder;org.apache.tinkerpop.gremlin.driver.ser.JsonBuilderGryoSerializer]}} - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph, custom: [groovy.json.JsonBuilder;org.apache.tinkerpop.gremlin.driver.ser.JsonBuilderGryoSerializer]}} - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true}} - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} metrics: { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/server/gremlin-server-integration.yaml ---------------------------------------------------------------------- diff --git a/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/server/gremlin-server-integration.yaml b/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/server/gremlin-server-integration.yaml index d0f7b32..a467111 100644 --- a/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/server/gremlin-server-integration.yaml +++ b/gremlin-server/src/test/resources/org/apache/tinkerpop/gremlin/server/gremlin-server-integration.yaml @@ -31,9 +31,9 @@ serializers: - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph, custom: [groovy.json.JsonBuilder;org.apache.tinkerpop.gremlin.driver.ser.JsonBuilderGryoSerializer]}} - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: { useMapperFromGraph: graph, custom: [groovy.json.JsonBuilder;org.apache.tinkerpop.gremlin.driver.ser.JsonBuilderGryoSerializer]}} - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true}} - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }} - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }} - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }} + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistry] }} + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { useMapperFromGraph: graph }} + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { useMapperFromGraph: graph }} processors: - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} metrics: { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fc9ce593/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 4dacf48..a112777 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 @@ -21,9 +21,11 @@ package org.apache.tinkerpop.gremlin.structure; import org.apache.tinkerpop.gremlin.AbstractGremlinTest; import org.apache.tinkerpop.gremlin.LoadGraphWith; import org.apache.tinkerpop.gremlin.process.traversal.Path; +import org.apache.tinkerpop.gremlin.process.traversal.util.Metrics; import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics; import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo; import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; +import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion; import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo; import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader; import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter; @@ -45,10 +47,12 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.*; /** @@ -245,7 +249,7 @@ public class SerializationTest { assertEquals("The objects differ", after, before); } } - + public static class GraphSONTest extends AbstractGremlinTest { private final TypeReference<HashMap<String, Object>> mapTypeReference = new TypeReference<HashMap<String, Object>>() { }; @@ -253,7 +257,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertex() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Vertex v = graph.vertices(convertToVertexId("marko")).next(); final String json = mapper.writeValueAsString(v); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); @@ -272,7 +276,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); @@ -286,7 +290,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); @@ -298,7 +302,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); @@ -311,7 +315,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); @@ -326,7 +330,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializePath() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Path p = g.V(convertToVertexId("marko")).as("a").outE().as("b").inV().as("c").path() .filter(t -> ((Vertex) t.get().objects().get(2)).value("name").equals("lop")).next(); final String json = mapper.writeValueAsString(p); @@ -354,8 +358,8 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTraversalMetrics() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); - final TraversalMetrics tm = (TraversalMetrics) g.V().both().profile().next(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); + final TraversalMetrics tm = g.V().both().profile().next(); final String json = mapper.writeValueAsString(tm); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); @@ -375,7 +379,7 @@ public class SerializationTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { - final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper(); + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Tree t = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final String json = mapper.writeValueAsString(t); @@ -426,4 +430,209 @@ public class SerializationTest { assertEquals(entry.getKey().toString(), branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.ID).toString()); } } + + public static class GraphSONV2d0Test extends AbstractGremlinTest { + private final TypeReference<HashMap<String, Object>> mapTypeReference = new TypeReference<HashMap<String, Object>>() { + }; + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + public void shouldSerializeVertex() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final Vertex v = graph.vertices(convertToVertexId("marko")).next(); + final String json = mapper.writeValueAsString(v); + final Vertex detached = mapper.readValue(json, Vertex.class); + + assertNotNull(detached); + assertEquals(v.label(), detached.label()); + assertEquals(v.id(), detached.id()); + assertEquals(v.value("name").toString(), detached.value("name")); + assertEquals((Integer) v.value("age"), detached.value("age")); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + public void shouldSerializeEdge() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); + final String json = mapper.writeValueAsString(e); + final Edge detached = mapper.readValue(json, Edge.class); + + assertNotNull(detached); + assertEquals(e.label(), detached.label()); + assertEquals(e.id(), detached.id()); + assertEquals((Double) e.value("weight"), detached.value("weight")); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + public void shouldSerializeProperty() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); + final String json = mapper.writeValueAsString(p); + final Property detached = mapper.readValue(json, Property.class); + + assertNotNull(detached); + assertEquals(p.key(), detached.key()); + assertEquals(p.value(), detached.value()); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + public void shouldSerializeVertexProperty() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); + final String json = mapper.writeValueAsString(vp); + final VertexProperty detached = mapper.readValue(json, VertexProperty.class); + + assertNotNull(detached); + assertEquals(vp.label(), detached.label()); + assertEquals(vp.id(), detached.id()); + assertEquals(vp.value(), detached.value()); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.CREW) + public void shouldSerializeVertexPropertyWithProperties() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); + final String json = mapper.writeValueAsString(vp); + final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); + + assertNotNull(detached); + assertEquals(vp.label(), detached.label()); + assertEquals(vp.id(), detached.id()); + assertEquals(vp.value(), detached.value()); + assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); + assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); + assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); + assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + public void shouldSerializePath() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final Path p = g.V(convertToVertexId("marko")).as("a").outE().as("b").inV().as("c").path() + .filter(t -> ((Vertex) t.get().objects().get(2)).value("name").equals("lop")).next(); + final String json = mapper.writeValueAsString(p); + final Path detached = mapper.readValue(json, Path.class); + + assertNotNull(detached); + assertEquals(p.labels().size(), detached.labels().size()); + assertEquals(p.labels().get(0).size(), detached.labels().get(0).size()); + assertEquals(p.labels().get(1).size(), detached.labels().get(1).size()); + assertEquals(p.labels().get(2).size(), detached.labels().get(2).size()); + assertTrue(p.labels().stream().flatMap(Collection::stream).allMatch(detached::hasLabel)); + + final Vertex vOut = p.get("a"); + final Vertex detachedVOut = detached.get("a"); + assertEquals(vOut.label(), detachedVOut.label()); + assertEquals(vOut.id(), detachedVOut.id()); + + // TODO: dunno GraphSON seems to return properties - will make this more consistent here + // this is a SimpleTraverser so no properties are present in detachment + //assertFalse(detachedVOut.properties().hasNext()); + + final Edge e = p.get("b"); + final Edge detachedE = detached.get("b"); + assertEquals(e.label(), detachedE.label()); + assertEquals(e.id(), detachedE.id()); + + // TODO: dunno GraphSON seems to return properties - will make this more consistent here + // this is a SimpleTraverser so no properties are present in detachment + //assertFalse(detachedE.properties().hasNext()); + + final Vertex vIn = p.get("c"); + final Vertex detachedVIn = detached.get("c"); + assertEquals(vIn.label(), detachedVIn.label()); + assertEquals(vIn.id(), detachedVIn.id()); + + // TODO: dunno GraphSON seems to return properties - will make this more consistent here + // this is a SimpleTraverser so no properties are present in detachment + //assertFalse(detachedVIn.properties().hasNext()); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + public void shouldSerializeTraversalMetrics() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final TraversalMetrics before = g.V().both().profile().next(); + final String json = mapper.writeValueAsString(before); + final TraversalMetrics after = mapper.readValue(json, TraversalMetrics.class); + + assertNotNull(after); + assertEquals(before.getMetrics().size(), after.getMetrics().size()); + assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS)); + assertEquals(before.getMetrics().size(), after.getMetrics().size()); + + before.getMetrics().forEach(b -> { + final Optional<? extends Metrics> mFromA = after.getMetrics().stream().filter(a -> b.getId().equals(a.getId())).findFirst(); + if (mFromA.isPresent()) { + final Metrics m = mFromA.get(); + assertEquals(b.getAnnotations(), m.getAnnotations()); + assertEquals(b.getCounts(), m.getCounts()); + assertEquals(b.getName(), m.getName()); + assertEquals(b.getDuration(TimeUnit.MILLISECONDS), m.getDuration(TimeUnit.MILLISECONDS)); + } else { + fail("Metrics were not present after deserialization"); + } + }); + } + + @Test + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) + @org.junit.Ignore("TINKERPOP-1509") + public void shouldSerializeTree() throws Exception { + final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().version(GraphSONVersion.V2_0).create().createMapper(); + final Tree t = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); + final String json = mapper.writeValueAsString(t); + + final HashMap<String, Object> m = (HashMap<String, Object>) mapper.readValue(json, mapTypeReference); + + // Check Structure + assertEquals(1, m.size()); + assertTrue(m.containsKey(convertToVertexId("marko").toString())); + + // Check Structure n+1 + final HashMap<String, Object> branch = (HashMap<String, Object>) m.get(convertToVertexId("marko").toString()); + assertEquals(2, branch.size()); + assertTrue(branch.containsKey(GraphSONTokens.KEY)); + assertTrue(branch.containsKey(GraphSONTokens.VALUE)); + + //Check n+1 key (traversed element) + final HashMap<String, Object> branchKey = (HashMap<String, Object>) branch.get(GraphSONTokens.KEY); + assertTrue(branchKey.containsKey(GraphSONTokens.ID)); + assertTrue(branchKey.containsKey(GraphSONTokens.LABEL)); + assertTrue(branchKey.containsKey(GraphSONTokens.TYPE)); + assertTrue(branchKey.containsKey(GraphSONTokens.PROPERTIES)); + assertEquals(convertToVertexId("marko").toString(), branchKey.get(GraphSONTokens.ID).toString()); + assertEquals("person", branchKey.get(GraphSONTokens.LABEL)); + assertEquals("vertex", branchKey.get(GraphSONTokens.TYPE)); + final HashMap<String, List<HashMap<String, Object>>> branchKeyProps = (HashMap<String, List<HashMap<String, Object>>>) branchKey.get(GraphSONTokens.PROPERTIES); + assertEquals("marko", branchKeyProps.get("name").get(0).get("value")); + assertEquals(29, branchKeyProps.get("age").get(0).get("value")); + + //Check n+1 value (traversed element) + final HashMap<String, Object> branchValue = (HashMap<String, Object>) branch.get(GraphSONTokens.VALUE); + assertEquals(3, branchValue.size()); + assertTrue(branchValue.containsKey(convertToVertexId("vadas").toString())); + assertTrue(branchValue.containsKey(convertToVertexId("lop").toString())); + assertTrue(branchValue.containsKey(convertToVertexId("josh").toString())); + + // Check that vp[] functioned properly + final HashMap<String, HashMap<String, Object>> branch2 = (HashMap<String, HashMap<String, Object>>) branchValue.get(convertToVertexId("vadas").toString()); + assertTrue(branch2.containsKey(GraphSONTokens.KEY)); + assertTrue(branch2.containsKey(GraphSONTokens.VALUE)); + + final Map.Entry entry = branch2.get(GraphSONTokens.VALUE).entrySet().iterator().next(); + final HashMap<String, HashMap<String, Object>> branch2Prop = (HashMap<String, HashMap<String, Object>>) entry.getValue(); + assertTrue(branch2Prop.get(GraphSONTokens.KEY).containsKey(GraphSONTokens.ID)); + assertTrue(branch2Prop.get(GraphSONTokens.KEY).containsKey(GraphSONTokens.VALUE)); + assertTrue(branch2Prop.get(GraphSONTokens.KEY).containsKey(GraphSONTokens.LABEL)); + assertEquals("name", branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.LABEL)); + assertEquals("vadas", branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.VALUE)); + assertEquals(entry.getKey().toString(), branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.ID).toString()); + } + } }