You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/07/10 19:29:11 UTC
[06/14] tinkerpop git commit: TINKERPOP-1698 Fixed up a bunch of
tests with Gryo V3
TINKERPOP-1698 Fixed up a bunch of tests with Gryo V3
Basically had to default everything to work on V3. Might need to change up some tests to validate V1 specifically still.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cfcdd26e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cfcdd26e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cfcdd26e
Branch: refs/heads/master
Commit: cfcdd26edfb44cc2ac4bd56b51d1b367fdd27440
Parents: dc9a87b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jun 26 09:03:13 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 10 14:14:02 2017 -0400
----------------------------------------------------------------------
.../src/test/resources/gremlin-server.yaml | 1 +
.../io/gryo/GryoClassResolverV1d0.java | 2 +-
.../io/gryo/GryoClassResolverV3d0.java | 2 +-
.../gremlin/structure/io/gryo/GryoMapper.java | 2 +-
.../gremlin/structure/io/gryo/GryoPool.java | 2 +-
.../structure/io/gryo/GryoSerializersV3d0.java | 32 +-
.../gremlin/structure/io/gryo/GryoVersion.java | 10 +-
.../structure/io/gryo/GryoMapperTest.java | 49 +-
.../tinkerpop/gremlin/driver/Cluster.java | 2 +-
.../tinkerpop/gremlin/driver/Settings.java | 4 +-
.../gremlin/driver/ser/Serializers.java | 3 +
.../gremlin/driver/simple/NioClient.java | 4 +-
.../gremlin/driver/simple/WebSocketClient.java | 5 +-
.../ser/GryoBaseMessageSerializerTest.java | 617 +++++++++++++++++++
.../ser/GryoBaseMessageSerializerV1d0Test.java | 613 ------------------
.../server/GremlinDriverIntegrateTest.java | 4 +-
.../server/GremlinResultSetIntegrateTest.java | 8 +-
.../remote/gremlin-server-integration.yaml | 1 +
.../server/gremlin-server-integration.yaml | 1 +
.../gremlin/structure/SerializationTest.java | 3 +-
.../gremlin/structure/io/IoCustomTest.java | 10 +-
.../io/gryo/GryoCompatibilityTest.java | 4 +-
.../structure/io/gryo/GryoRegistrator.java | 3 +-
.../jsr223/TinkerGraphGremlinPlugin.java | 2 +
.../TinkerGraphGryoSerializerV2d0Test.java | 2 +-
.../TinkerGraphGryoSerializerV3d0Test.java | 80 +++
.../tinkergraph/structure/TinkerGraphTest.java | 5 +-
27 files changed, 795 insertions(+), 676 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml
index ffe4d07..c0e4e3c 100644
--- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml
+++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml
@@ -30,6 +30,7 @@ scriptEngines: {
org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/generate-modern.groovy]}}}}
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0] }} # application/vnd.gremlin-v1.0+gryo
+ - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0], custom: [groovy.json.JsonBuilder;org.apache.tinkerpop.gremlin.driver.ser.JsonBuilderGryoSerializer]}}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd
metrics: {
slf4jReporter: {enabled: true, interval: 180000}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV1d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV1d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV1d0.java
index 12a9bfb..82531b0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV1d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV1d0.java
@@ -57,7 +57,7 @@ public class GryoClassResolverV1d0 extends AbstractGryoClassResolver {
type = Edge.class;
else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz))
type = VertexProperty.class;
- else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
+ else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && !ReferenceVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
type = Property.class;
else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz))
type = Path.class;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV3d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV3d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV3d0.java
index 9b0f726..99a7c4a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV3d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolverV3d0.java
@@ -59,7 +59,7 @@ public class GryoClassResolverV3d0 extends AbstractGryoClassResolver {
type = Edge.class;
else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz))
type = VertexProperty.class;
- else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
+ else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && !ReferenceVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
type = Property.class;
else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz))
type = Path.class;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 2db34b4..ca4764d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -138,7 +138,7 @@ public final class GryoMapper implements Mapper<Kryo> {
*/
public static class Builder implements Mapper.Builder<Builder> {
- private GryoVersion version = GryoVersion.V1_0;
+ private GryoVersion version = GryoVersion.V3_0;
/**
* Note that the following are pre-registered boolean, Boolean, byte, Byte, char, Character, double, Double,
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
index 4e3ab13..485ac98 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
@@ -207,7 +207,7 @@ public final class GryoPool {
* @return the new pool
*/
public GryoPool create() {
- final GryoMapper.Builder mapper = GryoMapper.build();
+ final GryoMapper.Builder mapper = GryoMapper.build().version(GryoVersion.V1_0);
final GryoPool gryoPool = new GryoPool();
if (null != this.ioRegistries)
this.ioRegistries.forEach(mapper::addRegistry);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
index 580bc86..fe53ce5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
@@ -127,12 +127,16 @@ public final class GryoSerializersV3d0 {
output.writeString(vp.label());
kryo.writeClassAndObject(output, vp.value());
- final List<Property> metaProperties = IteratorUtils.asList(vp.properties());
- output.writeInt(metaProperties.size());
- metaProperties.forEach(p -> {
- output.writeString(p.key());
- kryo.writeClassAndObject(output, p.value());
- });
+ if (vp instanceof DetachedVertexProperty || (vertex.graph().features().vertex().supportsMetaProperties())) {
+ final List<Property> metaProperties = IteratorUtils.asList(vp.properties());
+ output.writeInt(metaProperties.size());
+ metaProperties.forEach(p -> {
+ output.writeString(p.key());
+ kryo.writeClassAndObject(output, p.value());
+ });
+ } else {
+ output.writeInt(0);
+ }
});
}
@@ -192,12 +196,16 @@ public final class GryoSerializersV3d0 {
kryo.writeClassAndObject(output, vertexProperty.element().id());
output.writeString(vertexProperty.element().label());
- final List<Property> metaProperties = IteratorUtils.asList(vertexProperty.properties());
- output.writeInt(metaProperties.size());
- metaProperties.forEach(p -> {
- output.writeString(p.key());
- kryo.writeClassAndObject(output, p.value());
- });
+ if (vertexProperty instanceof DetachedVertexProperty || (vertexProperty.graph().features().vertex().supportsMetaProperties())) {
+ final List<Property> metaProperties = IteratorUtils.asList(vertexProperty.properties());
+ output.writeInt(metaProperties.size());
+ metaProperties.forEach(p -> {
+ output.writeString(p.key());
+ kryo.writeClassAndObject(output, p.value());
+ });
+ } else {
+ output.writeInt(0);
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
index e06f5b3..aca1638 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
@@ -268,11 +268,11 @@ public enum GryoVersion {
add(GryoTypeReg.of(InetAddress.class, 162, new UtilSerializers.InetAddressSerializer()));
add(GryoTypeReg.of(ByteBuffer.class, 163, new UtilSerializers.ByteBufferSerializer()));
-// add(GryoTypeReg.of(ReferenceEdge.class, 81));
-// add(GryoTypeReg.of(ReferenceVertexProperty.class, 82));
-// add(GryoTypeReg.of(ReferenceProperty.class, 83));
-// add(GryoTypeReg.of(ReferenceVertex.class, 84));
-// add(GryoTypeReg.of(ReferencePath.class, 85));
+ add(GryoTypeReg.of(ReferenceEdge.class, 81));
+ add(GryoTypeReg.of(ReferenceVertexProperty.class, 82));
+ add(GryoTypeReg.of(ReferenceProperty.class, 83));
+ add(GryoTypeReg.of(ReferenceVertex.class, 84));
+ add(GryoTypeReg.of(ReferencePath.class, 85));
add(GryoTypeReg.of(StarGraph.class, 86, new StarGraphSerializer(Direction.BOTH, new GraphFilter())));
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
index 12e99b3..fcb040a 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
@@ -35,6 +35,8 @@ import org.apache.tinkerpop.shaded.kryo.Serializer;
import org.apache.tinkerpop.shaded.kryo.io.Input;
import org.apache.tinkerpop.shaded.kryo.io.Output;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -75,10 +77,21 @@ import static org.junit.Assert.fail;
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
+@RunWith(Parameterized.class)
public class GryoMapperTest {
- private final GryoMapper sharedMapper = GryoMapper.build().create();
- private final Kryo sharedKryo = sharedMapper.createMapper();
+ @Parameterized.Parameters
+ public static Iterable<Object[]> data() {
+ return Arrays.asList(new Object[][]{
+ {"1_0", (Supplier<GryoMapper.Builder>) () -> GryoMapper.build().version(GryoVersion.V1_0)},
+ {"3_0", (Supplier<GryoMapper.Builder>) () -> GryoMapper.build().version(GryoVersion.V3_0)}});
+ }
+
+ @Parameterized.Parameter
+ public String name;
+
+ @Parameterized.Parameter(value = 1)
+ public Supplier<GryoMapper.Builder> builder;
@Test
public void shouldMakeNewInstance() {
@@ -88,7 +101,7 @@ public class GryoMapperTest {
@Test
public void shouldSerializeDeserialize() throws Exception {
- final GryoMapper mapper = GryoMapper.build().create();
+ final GryoMapper mapper = builder.get().create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -116,7 +129,7 @@ public class GryoMapperTest {
@Test
public void shouldSerializeWithCustomClassResolverToDetachedVertex() throws Exception {
final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier();
- final GryoMapper mapper = GryoMapper.build().classResolver(classResolver).create();
+ final GryoMapper mapper = builder.get().classResolver(classResolver).create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -124,7 +137,7 @@ public class GryoMapperTest {
kryo.writeClassAndObject(out, x);
- final GryoMapper mapperWithoutKnowledgeOfIox = GryoMapper.build().create();
+ final GryoMapper mapperWithoutKnowledgeOfIox = builder.get().create();
final Kryo kryoWithoutKnowledgeOfIox = mapperWithoutKnowledgeOfIox.createMapper();
try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
final Input input = new Input(inputStream);
@@ -137,7 +150,7 @@ public class GryoMapperTest {
@Test
public void shouldSerializeWithCustomClassResolverToHashMap() throws Exception {
final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier();
- final GryoMapper mapper = GryoMapper.build().classResolver(classResolver).create();
+ final GryoMapper mapper = builder.get().classResolver(classResolver).create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -145,7 +158,7 @@ public class GryoMapperTest {
kryo.writeClassAndObject(out, y);
- final GryoMapper mapperWithoutKnowledgeOfIoy = GryoMapper.build().create();
+ final GryoMapper mapperWithoutKnowledgeOfIoy = builder.get().create();
final Kryo kryoWithoutKnowledgeOfIox = mapperWithoutKnowledgeOfIoy.createMapper();
try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
final Input input = new Input(inputStream);
@@ -157,7 +170,7 @@ public class GryoMapperTest {
@Test
public void shouldSerializeWithoutRegistration() throws Exception {
- final GryoMapper mapper = GryoMapper.build().registrationRequired(false).create();
+ final GryoMapper mapper = builder.get().registrationRequired(false).create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -178,8 +191,7 @@ public class GryoMapperTest {
@Test
public void shouldRegisterMultipleIoRegistryToSerialize() throws Exception {
- final GryoMapper mapper = GryoMapper.build()
- .addRegistry(IoXIoRegistry.InstanceBased.instance())
+ final GryoMapper mapper = builder.get().addRegistry(IoXIoRegistry.InstanceBased.instance())
.addRegistry(IoYIoRegistry.InstanceBased.instance()).create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
@@ -201,8 +213,7 @@ public class GryoMapperTest {
@Test
public void shouldExpectReadFailureAsIoRegistryOrderIsNotRespected() throws Exception {
- final GryoMapper mapperWrite = GryoMapper.build()
- .addRegistry(IoXIoRegistry.InstanceBased.instance())
+ final GryoMapper mapperWrite = builder.get().addRegistry(IoXIoRegistry.InstanceBased.instance())
.addRegistry(IoYIoRegistry.InstanceBased.instance()).create();
final GryoMapper mapperRead = GryoMapper.build()
@@ -232,8 +243,7 @@ public class GryoMapperTest {
@Test
public void shouldOverrideExistingSerializer() throws Exception {
- final GryoMapper mapper = GryoMapper.build()
- .addCustom(Duration.class, new OverrideDurationSerializer()).create();
+ final GryoMapper mapper = builder.get().addCustom(Duration.class, new OverrideDurationSerializer()).create();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -368,14 +378,15 @@ public class GryoMapperTest {
}
public <T> T serializeDeserialize(final Object o, final Class<T> clazz) throws Exception {
+ final Kryo kryo = builder.get().create().createMapper();
try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
- sharedKryo.writeObject(out, o);
+ kryo.writeObject(out, o);
out.flush();
try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray())) {
final Input input = new Input(inputStream);
- return sharedKryo.readObject(input, clazz);
+ return kryo.readObject(input, clazz);
}
}
}
@@ -383,7 +394,7 @@ public class GryoMapperTest {
/**
* Creates new {@link CustomClassResolver} when requested.
*/
- public static class CustomClassResolverSupplier implements Supplier<ClassResolver> {
+ private static class CustomClassResolverSupplier implements Supplier<ClassResolver> {
@Override
public ClassResolver get() {
return new CustomClassResolver();
@@ -397,7 +408,7 @@ public class GryoMapperTest {
* TinkerPop which then removes the requirement for providers to expose serializers on the client side for user
* consumption.
*/
- public static class CustomClassResolver extends GryoClassResolverV1d0 {
+ private static class CustomClassResolver extends GryoClassResolverV1d0 {
private IoXIoRegistry.IoXToVertexSerializer ioXToVertexSerializer = new IoXIoRegistry.IoXToVertexSerializer();
private IoYIoRegistry.IoYToHashMapSerializer ioYToHashMapSerializer = new IoYIoRegistry.IoYToHashMapSerializer();
@@ -414,7 +425,7 @@ public class GryoMapperTest {
}
}
- final static class OverrideDurationSerializer extends Serializer<Duration>
+ private final static class OverrideDurationSerializer extends Serializer<Duration>
{
@Override
public void write(final Kryo kryo, final Output output, final Duration duration)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
index fa59b22..87b79ee 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Cluster.java
@@ -469,7 +469,7 @@ public final class Cluster {
public final static class Builder {
private List<InetAddress> addresses = new ArrayList<>();
private int port = 8182;
- private MessageSerializer serializer = Serializers.GRYO_V1D0.simpleInstance();
+ private MessageSerializer serializer = Serializers.GRYO_V3D0.simpleInstance();
private int nioPoolSize = Runtime.getRuntime().availableProcessors();
private int workerPoolSize = Runtime.getRuntime().availableProcessors() * 2;
private int minConnectionPoolSize = ConnectionPool.MIN_POOL_SIZE;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
index 03374cc..f3fb430 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Settings.java
@@ -18,8 +18,8 @@
*/
package org.apache.tinkerpop.gremlin.driver;
-import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
@@ -324,7 +324,7 @@ final class Settings {
* The fully qualified class name of the {@link MessageSerializer} that will be used to communicate with the
* server. Note that the serializer configured on the client should be supported by the server configuration.
*/
- public String className = GryoMessageSerializerV1d0.class.getCanonicalName();
+ public String className = GryoMessageSerializerV3d0.class.getCanonicalName();
/**
* The configuration for the specified serializer with the {@link #className}.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/Serializers.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/Serializers.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/Serializers.java
index 69e8287..e64fc8b 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/Serializers.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/Serializers.java
@@ -34,6 +34,7 @@ public enum Serializers {
GRAPHSON_V2D0(SerTokens.MIME_GRAPHSON_V2D0),
GRAPHSON_V3D0(SerTokens.MIME_GRAPHSON_V3D0),
GRYO_V1D0(SerTokens.MIME_GRYO_V1D0),
+ GRYO_V3D0(SerTokens.MIME_GRYO_V3D0),
GRYO_LITE_V1D0(SerTokens.MIME_GRYO_LITE_V1D0);
private String value;
@@ -72,6 +73,8 @@ public enum Serializers {
return new GraphSONMessageSerializerV3d0();
case SerTokens.MIME_GRYO_V1D0:
return new GryoMessageSerializerV1d0();
+ case SerTokens.MIME_GRYO_V3D0:
+ return new GryoMessageSerializerV3d0();
case SerTokens.MIME_GRYO_LITE_V1D0:
return new GryoLiteMessageSerializerV1d0();
default:
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/NioClient.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/NioClient.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/NioClient.java
index a135761..cda5043 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/NioClient.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/NioClient.java
@@ -24,13 +24,13 @@ import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
import org.apache.tinkerpop.gremlin.driver.handler.NioGremlinRequestEncoder;
import org.apache.tinkerpop.gremlin.driver.handler.NioGremlinResponseDecoder;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
-import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
+import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0;
import java.io.IOException;
import java.net.URI;
@@ -53,7 +53,7 @@ public class NioClient extends AbstractClient {
b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
try {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final MessageSerializer serializer = new GryoMessageSerializerV3d0();
b.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
index 0148ac9..cc7dd8f 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/simple/WebSocketClient.java
@@ -26,18 +26,17 @@ import org.apache.tinkerpop.gremlin.driver.handler.WebSocketClientHandler;
import org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder;
import org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinResponseDecoder;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
-import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
-import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
+import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0;
import java.io.IOException;
import java.net.URI;
@@ -69,7 +68,7 @@ public class WebSocketClient extends AbstractClient {
new WebSocketClientHandler(
WebSocketClientHandshakerFactory.newHandshaker(
uri, WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, 65536));
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final MessageSerializer serializer = new GryoMessageSerializerV3d0();
b.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerTest.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerTest.java
new file mode 100644
index 0000000..fff95dd
--- /dev/null
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerTest.java
@@ -0,0 +1,617 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.driver.ser;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.buffer.UnpooledByteBufAllocator;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
+import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
+import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
+import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoClassResolverV1d0;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.apache.tinkerpop.shaded.kryo.ClassResolver;
+import org.apache.tinkerpop.shaded.kryo.Kryo;
+import org.apache.tinkerpop.shaded.kryo.KryoException;
+import org.apache.tinkerpop.shaded.kryo.Registration;
+import org.apache.tinkerpop.shaded.kryo.Serializer;
+import org.apache.tinkerpop.shaded.kryo.io.Input;
+import org.apache.tinkerpop.shaded.kryo.io.Output;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Supplier;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@RunWith(Parameterized.class)
+public class GryoBaseMessageSerializerTest {
+ @Parameterized.Parameters(name = "expect({0})")
+ public static Iterable<Object[]> data() {
+ final GryoMessageSerializerV1d0 v1d0Text = new GryoMessageSerializerV1d0();
+ v1d0Text.configure(config, null);
+
+ final GryoMessageSerializerV1d0 v1d0LiteText = new GryoMessageSerializerV1d0();
+ v1d0LiteText.configure(config, null);
+
+ final GryoMessageSerializerV3d0 v3d0Text = new GryoMessageSerializerV3d0();
+ v3d0Text.configure(config, null);
+
+ return Arrays.asList(new Object[][]{
+ {"V1d0", new GryoMessageSerializerV1d0(), v1d0Text},
+ {"V1d0Lite", new GryoLiteMessageSerializerV1d0(), v1d0LiteText },
+ {"V3d0", new GryoMessageSerializerV3d0(), v3d0Text}});
+ }
+
+ @Parameterized.Parameter(value = 0)
+ public String name;
+
+ @Parameterized.Parameter(value = 1)
+ public MessageSerializer binarySerializer;
+
+ @Parameterized.Parameter(value = 2)
+ public MessageSerializer textSerializer;
+
+ private static final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_SERIALIZE_RESULT_TO_STRING, true);
+ }};
+
+ private UUID requestId = UUID.fromString("6457272A-4018-4538-B9AE-08DD5DDC0AA1");
+ private ResponseMessage.Builder responseMessageBuilder = ResponseMessage.build(requestId);
+ private static ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
+
+ @Test
+ public void shouldConfigureIoRegistry() throws Exception {
+ final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_IO_REGISTRIES, Arrays.asList(ColorIoRegistry.class.getName()));
+ }};
+
+ serializer.configure(config, null);
+
+ final ResponseMessage toSerialize = ResponseMessage.build(requestId).result(Color.RED).create();
+ final ByteBuf bb = serializer.serializeResponseAsBinary(toSerialize, allocator);
+ final ResponseMessage deserialized = serializer.deserializeResponse(bb);
+
+ assertCommon(deserialized);
+ assertEquals(Color.RED, deserialized.getResult().getData());
+ }
+
+ @Test
+ public void shouldConfigureIoRegistryInstance() throws Exception {
+ final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_IO_REGISTRIES, Arrays.asList(ColorIoRegistryInstance.class.getName()));
+ }};
+
+ serializer.configure(config, null);
+
+ final ResponseMessage toSerialize = ResponseMessage.build(requestId).result(Color.RED).create();
+ final ByteBuf bb = serializer.serializeResponseAsBinary(toSerialize, allocator);
+ final ResponseMessage deserialized = serializer.deserializeResponse(bb);
+
+ assertCommon(deserialized);
+ assertEquals(Color.RED, deserialized.getResult().getData());
+ }
+
+ @Test
+ public void shouldConfigureIoRegistryGetInstance() throws Exception {
+ final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_IO_REGISTRIES, Arrays.asList(ColorIoRegistryGetInstance.class.getName()));
+ }};
+
+ serializer.configure(config, null);
+
+ final ResponseMessage toSerialize = ResponseMessage.build(requestId).result(Color.RED).create();
+ final ByteBuf bb = serializer.serializeResponseAsBinary(toSerialize, allocator);
+ final ResponseMessage deserialized = serializer.deserializeResponse(bb);
+
+ assertCommon(deserialized);
+ assertEquals(Color.RED, deserialized.getResult().getData());
+ }
+
+ @Test
+ public void shouldConfigureCustomClassResolver() {
+ final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_CLASS_RESOLVER_SUPPLIER, ErrorOnlyClassResolverSupplier.class.getName());
+ }};
+
+ serializer.configure(config, null);
+
+ try {
+ serializer.serializeResponseAsBinary(responseMessageBuilder.create(), allocator);
+ fail("Should fail because the ClassResolver used here always generates an error");
+ } catch (Exception ex) {
+ assertEquals("java.lang.RuntimeException: Registration is not allowed with this ClassResolver - it is not a good implementation", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void shouldConfigureCustomClassResolverFromInstance() {
+ final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_CLASS_RESOLVER_SUPPLIER, ErrorOnlyClassResolverSupplierAsInstance.class.getName());
+ }};
+
+ serializer.configure(config, null);
+
+ try {
+ serializer.serializeResponseAsBinary(responseMessageBuilder.create(), allocator);
+ fail("Should fail because the ClassResolver used here always generates an error");
+ } catch (Exception ex) {
+ assertEquals("java.lang.RuntimeException: Registration is not allowed with this ClassResolver - it is not a good implementation", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void shouldConfigureCustomClassResolverFromGetInstance() {
+ final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> config = new HashMap<String, Object>() {{
+ put(GryoMessageSerializerV1d0.TOKEN_CLASS_RESOLVER_SUPPLIER, ErrorOnlyClassResolverSupplierAsGetInstance.class.getName());
+ }};
+
+ serializer.configure(config, null);
+
+ try {
+ serializer.serializeResponseAsBinary(responseMessageBuilder.create(), allocator);
+ fail("Should fail because the ClassResolver used here always generates an error");
+ } catch (Exception ex) {
+ assertEquals("java.lang.RuntimeException: Registration is not allowed with this ClassResolver - it is not a good implementation", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void shouldSerializeIterable() throws Exception {
+ final ArrayList<Integer> list = new ArrayList<>();
+ list.add(1);
+ list.add(100);
+
+ final ResponseMessage response = convertBinary(list);
+ assertCommon(response);
+
+ final java.util.List<Integer> deserializedFunList = (java.util.List<Integer>) response.getResult().getData();
+ assertEquals(2, deserializedFunList.size());
+ assertEquals(new Integer(1), deserializedFunList.get(0));
+ assertEquals(new Integer(100), deserializedFunList.get(1));
+ }
+
+ @Test
+ public void shouldSerializeIterableToString() throws Exception {
+ final ArrayList<Integer> list = new ArrayList<>();
+ list.add(1);
+ list.add(100);
+
+ final ResponseMessage response = convertText(list);
+ assertCommon(response);
+
+ final java.util.List deserializedFunList = (java.util.List) response.getResult().getData();
+ assertEquals(2, deserializedFunList.size());
+ assertEquals("1", deserializedFunList.get(0));
+ assertEquals("100", deserializedFunList.get(1));
+ }
+
+ @Test
+ public void shouldSerializeIterableToStringWithNull() throws Exception {
+ final ArrayList<Integer> list = new ArrayList<>();
+ list.add(1);
+ list.add(null);
+ list.add(100);
+
+ final ResponseMessage response = convertText(list);
+ assertCommon(response);
+
+ final java.util.List deserializedFunList = (java.util.List) response.getResult().getData();
+ assertEquals(3, deserializedFunList.size());
+ assertEquals("1", deserializedFunList.get(0).toString());
+ assertEquals("null", deserializedFunList.get(1).toString());
+ assertEquals("100", deserializedFunList.get(2).toString());
+ }
+
+ @Test
+ public void shouldSerializeIterableWithNull() throws Exception {
+ final ArrayList<Integer> list = new ArrayList<>();
+ list.add(1);
+ list.add(null);
+ list.add(100);
+
+ final ResponseMessage response = convertBinary(list);
+ assertCommon(response);
+
+ final java.util.List<Integer> deserializedFunList = (java.util.List<Integer>) response.getResult().getData();
+ assertEquals(3, deserializedFunList.size());
+ assertEquals(new Integer(1), deserializedFunList.get(0));
+ assertNull(deserializedFunList.get(1));
+ assertEquals(new Integer(100), deserializedFunList.get(2));
+ }
+
+ @Test
+ public void shouldSerializeMap() throws Exception {
+ final Map<String, Object> map = new HashMap<>();
+ final Map<String, String> innerMap = new HashMap<>();
+ innerMap.put("a", "b");
+
+ map.put("x", 1);
+ map.put("y", "some");
+ map.put("z", innerMap);
+
+ final ResponseMessage response = convertBinary(map);
+ assertCommon(response);
+
+ final Map<String, Object> deserializedMap = (Map<String, Object>) response.getResult().getData();
+ assertEquals(3, deserializedMap.size());
+ assertEquals(1, deserializedMap.get("x"));
+ assertEquals("some", deserializedMap.get("y"));
+
+ final Map<String, String> deserializedInnerMap = (Map<String, String>) deserializedMap.get("z");
+ assertEquals(1, deserializedInnerMap.size());
+ assertEquals("b", deserializedInnerMap.get("a"));
+ }
+
+ @Test
+ public void shouldSerializeMapEntry() throws Exception {
+ final Graph graph = TinkerGraph.open();
+ final Vertex v1 = graph.addVertex();
+ final Date d = new Date();
+
+ final Map<Object, Object> map = new HashMap<>();
+ map.put("x", 1);
+ map.put(v1, 100);
+ map.put(d, "test");
+
+ final ResponseMessage response = convertBinary(IteratorUtils.asList(map.entrySet()));
+ assertCommon(response);
+
+ final java.util.List<Map.Entry<Object, Object>> deserializedEntries = (java.util.List<Map.Entry<Object, Object>>) response.getResult().getData();
+ assertEquals(3, deserializedEntries.size());
+ deserializedEntries.forEach(e -> {
+ if (e.getKey().equals("x"))
+ assertEquals(1, e.getValue());
+ else if (e.getKey().equals(v1))
+ assertEquals(100, e.getValue());
+ else if (e.getKey().equals(d))
+ assertEquals("test", e.getValue());
+ else
+ fail("Map entries contains a key that is not part of what was serialized");
+ });
+ }
+
+ @Test
+ public void shouldSerializeTree() throws Exception {
+ final Graph g = TinkerFactory.createModern();
+ final Tree t = g.traversal().V().out().out().tree().by("name").next();
+
+ final ResponseMessage response = convertBinary(t);
+ assertCommon(response);
+
+ final Tree deserialized = (Tree) response.getResult().getData();
+ assertEquals(t, deserialized);
+
+ assertThat(deserialized.containsKey("marko"), is(true));
+ assertEquals(1, deserialized.size());
+
+ final Tree markoChildren = (Tree) deserialized.get("marko");
+ assertThat(markoChildren.containsKey("josh"), is(true));
+ assertEquals(1, markoChildren.size());
+
+ final Tree joshChildren = (Tree) markoChildren.get("josh");
+ assertThat(joshChildren.containsKey("lop"), is(true));
+ assertThat(joshChildren.containsKey("ripple"), is(true));
+ assertEquals(2, joshChildren.size());
+ }
+
+ @Test
+ public void shouldSerializeFullResponseMessage() throws Exception {
+ final UUID id = UUID.randomUUID();
+
+ final Map<String, Object> metaData = new HashMap<>();
+ metaData.put("test", "this");
+ metaData.put("one", 1);
+
+ final Map<String, Object> attributes = new HashMap<>();
+ attributes.put("test", "that");
+ attributes.put("two", 2);
+
+ final ResponseMessage response = ResponseMessage.build(id)
+ .responseMetaData(metaData)
+ .code(ResponseStatusCode.SUCCESS)
+ .result("some-result")
+ .statusAttributes(attributes)
+ .statusMessage("worked")
+ .create();
+
+ final ByteBuf bb = binarySerializer.serializeResponseAsBinary(response, allocator);
+ final ResponseMessage deserialized = binarySerializer.deserializeResponse(bb);
+
+ assertEquals(id, deserialized.getRequestId());
+ assertEquals("this", deserialized.getResult().getMeta().get("test"));
+ assertEquals(1, deserialized.getResult().getMeta().get("one"));
+ assertEquals("some-result", deserialized.getResult().getData());
+ assertEquals("that", deserialized.getStatus().getAttributes().get("test"));
+ assertEquals(2, deserialized.getStatus().getAttributes().get("two"));
+ assertEquals(ResponseStatusCode.SUCCESS.getValue(), deserialized.getStatus().getCode().getValue());
+ assertEquals("worked", deserialized.getStatus().getMessage());
+ }
+
+ @Test
+ public void shouldHaveTooSmallBufferToSerializeResponseMessage() throws Exception {
+ final UUID id = UUID.randomUUID();
+
+ final Map<String, Object> metaData = new HashMap<>();
+ metaData.put("test", "this");
+ metaData.put("one", 1);
+
+ final Map<String, Object> attributes = new HashMap<>();
+ attributes.put("test", "that");
+ attributes.put("two", 2);
+
+ final ResponseMessage response = ResponseMessage.build(id)
+ .responseMetaData(metaData)
+ .code(ResponseStatusCode.SUCCESS)
+ .result("some-result")
+ .statusAttributes(attributes)
+ .statusMessage("worked")
+ .create();
+
+ final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
+ put("bufferSize", 1);
+ }};
+ binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
+
+ try {
+ binarySerializerWithSmallBuffer.serializeResponseAsBinary(response, allocator);
+ fail("Should have a buffer size that is too small");
+ } catch (Exception ex) {
+ final Throwable root = ExceptionUtils.getRootCause(ex);
+ assertThat(root, instanceOf(KryoException.class));
+ }
+ }
+
+ @Test
+ public void shouldReturnAllBytesInResponse() throws Exception {
+ final UUID id = UUID.randomUUID();
+
+ final Map<String, Object> metaData = new HashMap<>();
+ metaData.put("test", "this");
+ metaData.put("one", 1);
+
+ final Map<String, Object> attributes = new HashMap<>();
+ attributes.put("test", "that");
+ attributes.put("two", 2);
+
+ final ResponseMessage response = ResponseMessage.build(id)
+ .responseMetaData(metaData)
+ .code(ResponseStatusCode.SUCCESS)
+ .result("some-result")
+ .statusAttributes(attributes)
+ .statusMessage("worked")
+ .create();
+
+ final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
+ // set to bufferSize < total message size but still greater than any individual object requires
+ put("bufferSize", 50);
+ }};
+ binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
+
+ final ByteBuf buf = binarySerializerWithSmallBuffer.serializeResponseAsBinary(response, allocator);
+ assertTrue(buf.isReadable());
+ assertEquals(82, buf.readableBytes());
+ }
+
+ @Test
+ public void shouldSerializeFullRequestMessage() throws Exception {
+ final UUID id = UUID.randomUUID();
+
+ final RequestMessage request = RequestMessage.build("try")
+ .overrideRequestId(id)
+ .processor("pro")
+ .addArg("test", "this")
+ .create();
+ final ByteBuf bb = binarySerializer.serializeRequestAsBinary(request, allocator);
+ final int mimeLen = bb.readByte();
+ bb.readBytes(new byte[mimeLen]);
+ final RequestMessage deserialized = binarySerializer.deserializeRequest(bb);
+
+ assertEquals(id, deserialized.getRequestId());
+ assertEquals("pro", deserialized.getProcessor());
+ assertEquals("try", deserialized.getOp());
+ assertEquals("this", deserialized.getArgs().get("test"));
+ }
+
+ @Test
+ public void shouldHaveTooSmallBufferToSerializeRequestMessage() throws Exception {
+ final UUID id = UUID.randomUUID();
+
+ final RequestMessage request = RequestMessage.build("try")
+ .overrideRequestId(id)
+ .processor("pro")
+ .addArg("test", "this")
+ .create();
+
+ final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
+ put("bufferSize", 1);
+ }};
+ binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
+
+ try {
+ binarySerializerWithSmallBuffer.serializeRequestAsBinary(request, allocator);
+ fail("Should have a buffer size that is too small");
+ } catch (Exception ex) {
+ final Throwable root = ExceptionUtils.getRootCause(ex);
+ assertThat(root, instanceOf(KryoException.class));
+ }
+ }
+
+ @Test
+ public void shouldReturnAllBytesInRequest() throws Exception {
+ final UUID id = UUID.randomUUID();
+
+ final RequestMessage request = RequestMessage.build("try")
+ .overrideRequestId(id)
+ .processor("pro")
+ .addArg("test", "this")
+ .create();
+
+ final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
+ final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
+ // set to bufferSize < total message size but still greater than any individual object requires
+ put("bufferSize", 50);
+ }};
+ binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
+
+ ByteBuf buf = binarySerializerWithSmallBuffer.serializeRequestAsBinary(request, allocator);
+ assertTrue(buf.isReadable());
+ assertEquals(71, buf.readableBytes());
+ }
+
+ private void assertCommon(final ResponseMessage response) {
+ assertEquals(requestId, response.getRequestId());
+ assertEquals(ResponseStatusCode.SUCCESS, response.getStatus().getCode());
+ }
+
+ private ResponseMessage convertBinary(final Object toSerialize) throws SerializationException {
+ final ByteBuf bb = binarySerializer.serializeResponseAsBinary(responseMessageBuilder.result(toSerialize).create(), allocator);
+ return binarySerializer.deserializeResponse(bb);
+ }
+
+ private ResponseMessage convertText(final Object toSerialize) throws SerializationException {
+ final ByteBuf bb = textSerializer.serializeResponseAsBinary(responseMessageBuilder.result(toSerialize).create(), allocator);
+ return textSerializer.deserializeResponse(bb);
+ }
+
+ public static class ErrorOnlyClassResolverSupplierAsInstance implements Supplier<ClassResolver> {
+
+ private static final ErrorOnlyClassResolverSupplierAsInstance instance = new ErrorOnlyClassResolverSupplierAsInstance();
+
+ private ErrorOnlyClassResolverSupplierAsInstance() {}
+
+ public static ErrorOnlyClassResolverSupplierAsInstance instance() {
+ return instance;
+ }
+
+ @Override
+ public ClassResolver get() {
+ return new ErrorOnlyClassResolver();
+ }
+ }
+
+ public static class ErrorOnlyClassResolverSupplierAsGetInstance implements Supplier<ClassResolver> {
+
+ private static final ErrorOnlyClassResolverSupplierAsInstance instance = new ErrorOnlyClassResolverSupplierAsInstance();
+
+ private ErrorOnlyClassResolverSupplierAsGetInstance() {}
+
+ public static ErrorOnlyClassResolverSupplierAsInstance getInstance() {
+ return instance;
+ }
+
+ @Override
+ public ClassResolver get() {
+ return new ErrorOnlyClassResolver();
+ }
+ }
+
+ public static class ErrorOnlyClassResolverSupplier implements Supplier<ClassResolver> {
+ @Override
+ public ClassResolver get() {
+ return new ErrorOnlyClassResolver();
+ }
+ }
+
+ public static class ErrorOnlyClassResolver extends GryoClassResolverV1d0 {
+ @Override
+ public Registration getRegistration(Class clazz) {
+ throw new RuntimeException("Registration is not allowed with this ClassResolver - it is not a good implementation");
+ }
+ }
+
+ public static class ColorIoRegistry extends AbstractIoRegistry {
+ public ColorIoRegistry() {
+ register(GryoIo.class, Color.class, new ColorSerializer());
+ }
+ }
+
+ public static class ColorIoRegistryInstance extends AbstractIoRegistry {
+
+ private static final ColorIoRegistry instance = new ColorIoRegistry();
+
+ private ColorIoRegistryInstance() {
+ register(GryoIo.class, Color.class, new ColorSerializer());
+ }
+
+ public static ColorIoRegistry instance() {
+ return instance;
+ }
+ }
+
+ public static class ColorIoRegistryGetInstance extends AbstractIoRegistry {
+
+ private static final ColorIoRegistry instance = new ColorIoRegistry();
+
+ private ColorIoRegistryGetInstance() {
+ register(GryoIo.class, Color.class, new ColorSerializer());
+ }
+
+ public static ColorIoRegistry getInstance() {
+ return instance;
+ }
+ }
+
+ public static class ColorSerializer extends Serializer<Color> {
+ @Override
+ public void write(final Kryo kryo, final Output output, final Color color) {
+ output.write(color.equals(Color.RED) ? 1 : 0);
+ }
+
+ @Override
+ public Color read(final Kryo kryo, final Input input, final Class<Color> aClass) {
+ return input.read() == 1 ? Color.RED : Color.BLACK;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerV1d0Test.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerV1d0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerV1d0Test.java
deleted file mode 100644
index 92627eb..0000000
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoBaseMessageSerializerV1d0Test.java
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.driver.ser;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufAllocator;
-import io.netty.buffer.UnpooledByteBufAllocator;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
-import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
-import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
-import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoClassResolverV1d0;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.apache.tinkerpop.shaded.kryo.ClassResolver;
-import org.apache.tinkerpop.shaded.kryo.Kryo;
-import org.apache.tinkerpop.shaded.kryo.KryoException;
-import org.apache.tinkerpop.shaded.kryo.Registration;
-import org.apache.tinkerpop.shaded.kryo.Serializer;
-import org.apache.tinkerpop.shaded.kryo.io.Input;
-import org.apache.tinkerpop.shaded.kryo.io.Output;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.function.Supplier;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-@RunWith(Parameterized.class)
-public class GryoBaseMessageSerializerV1d0Test {
- @Parameterized.Parameters(name = "expect({0})")
- public static Iterable<Object[]> data() {
- final GryoMessageSerializerV1d0 v1d0Text = new GryoMessageSerializerV1d0();
- v1d0Text.configure(config, null);
-
- final GryoMessageSerializerV1d0 v1d0LiteText = new GryoMessageSerializerV1d0();
- v1d0LiteText.configure(config, null);
-
- return Arrays.asList(new Object[][]{
- {"V1d0", new GryoMessageSerializerV1d0(), v1d0Text},
- {"V1d0Lite", new GryoLiteMessageSerializerV1d0(), v1d0LiteText }});
- }
-
- @Parameterized.Parameter(value = 0)
- public String name;
-
- @Parameterized.Parameter(value = 1)
- public MessageSerializer binarySerializer;
-
- @Parameterized.Parameter(value = 2)
- public MessageSerializer textSerializer;
-
- private static final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_SERIALIZE_RESULT_TO_STRING, true);
- }};
-
- private UUID requestId = UUID.fromString("6457272A-4018-4538-B9AE-08DD5DDC0AA1");
- private ResponseMessage.Builder responseMessageBuilder = ResponseMessage.build(requestId);
- private static ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
-
- @Test
- public void shouldConfigureIoRegistry() throws Exception {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
- final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_IO_REGISTRIES, Arrays.asList(ColorIoRegistry.class.getName()));
- }};
-
- serializer.configure(config, null);
-
- final ResponseMessage toSerialize = ResponseMessage.build(requestId).result(Color.RED).create();
- final ByteBuf bb = serializer.serializeResponseAsBinary(toSerialize, allocator);
- final ResponseMessage deserialized = serializer.deserializeResponse(bb);
-
- assertCommon(deserialized);
- assertEquals(Color.RED, deserialized.getResult().getData());
- }
-
- @Test
- public void shouldConfigureIoRegistryInstance() throws Exception {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
- final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_IO_REGISTRIES, Arrays.asList(ColorIoRegistryInstance.class.getName()));
- }};
-
- serializer.configure(config, null);
-
- final ResponseMessage toSerialize = ResponseMessage.build(requestId).result(Color.RED).create();
- final ByteBuf bb = serializer.serializeResponseAsBinary(toSerialize, allocator);
- final ResponseMessage deserialized = serializer.deserializeResponse(bb);
-
- assertCommon(deserialized);
- assertEquals(Color.RED, deserialized.getResult().getData());
- }
-
- @Test
- public void shouldConfigureIoRegistryGetInstance() throws Exception {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
- final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_IO_REGISTRIES, Arrays.asList(ColorIoRegistryGetInstance.class.getName()));
- }};
-
- serializer.configure(config, null);
-
- final ResponseMessage toSerialize = ResponseMessage.build(requestId).result(Color.RED).create();
- final ByteBuf bb = serializer.serializeResponseAsBinary(toSerialize, allocator);
- final ResponseMessage deserialized = serializer.deserializeResponse(bb);
-
- assertCommon(deserialized);
- assertEquals(Color.RED, deserialized.getResult().getData());
- }
-
- @Test
- public void shouldConfigureCustomClassResolver() {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
- final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_CLASS_RESOLVER_SUPPLIER, ErrorOnlyClassResolverSupplier.class.getName());
- }};
-
- serializer.configure(config, null);
-
- try {
- serializer.serializeResponseAsBinary(responseMessageBuilder.create(), allocator);
- fail("Should fail because the ClassResolver used here always generates an error");
- } catch (Exception ex) {
- assertEquals("java.lang.RuntimeException: Registration is not allowed with this ClassResolver - it is not a good implementation", ex.getMessage());
- }
- }
-
- @Test
- public void shouldConfigureCustomClassResolverFromInstance() {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
- final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_CLASS_RESOLVER_SUPPLIER, ErrorOnlyClassResolverSupplierAsInstance.class.getName());
- }};
-
- serializer.configure(config, null);
-
- try {
- serializer.serializeResponseAsBinary(responseMessageBuilder.create(), allocator);
- fail("Should fail because the ClassResolver used here always generates an error");
- } catch (Exception ex) {
- assertEquals("java.lang.RuntimeException: Registration is not allowed with this ClassResolver - it is not a good implementation", ex.getMessage());
- }
- }
-
- @Test
- public void shouldConfigureCustomClassResolverFromGetInstance() {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
- final Map<String, Object> config = new HashMap<String, Object>() {{
- put(GryoMessageSerializerV1d0.TOKEN_CLASS_RESOLVER_SUPPLIER, ErrorOnlyClassResolverSupplierAsGetInstance.class.getName());
- }};
-
- serializer.configure(config, null);
-
- try {
- serializer.serializeResponseAsBinary(responseMessageBuilder.create(), allocator);
- fail("Should fail because the ClassResolver used here always generates an error");
- } catch (Exception ex) {
- assertEquals("java.lang.RuntimeException: Registration is not allowed with this ClassResolver - it is not a good implementation", ex.getMessage());
- }
- }
-
- @Test
- public void shouldSerializeIterable() throws Exception {
- final ArrayList<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(100);
-
- final ResponseMessage response = convertBinary(list);
- assertCommon(response);
-
- final java.util.List<Integer> deserializedFunList = (java.util.List<Integer>) response.getResult().getData();
- assertEquals(2, deserializedFunList.size());
- assertEquals(new Integer(1), deserializedFunList.get(0));
- assertEquals(new Integer(100), deserializedFunList.get(1));
- }
-
- @Test
- public void shouldSerializeIterableToString() throws Exception {
- final ArrayList<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(100);
-
- final ResponseMessage response = convertText(list);
- assertCommon(response);
-
- final java.util.List deserializedFunList = (java.util.List) response.getResult().getData();
- assertEquals(2, deserializedFunList.size());
- assertEquals("1", deserializedFunList.get(0));
- assertEquals("100", deserializedFunList.get(1));
- }
-
- @Test
- public void shouldSerializeIterableToStringWithNull() throws Exception {
- final ArrayList<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(null);
- list.add(100);
-
- final ResponseMessage response = convertText(list);
- assertCommon(response);
-
- final java.util.List deserializedFunList = (java.util.List) response.getResult().getData();
- assertEquals(3, deserializedFunList.size());
- assertEquals("1", deserializedFunList.get(0).toString());
- assertEquals("null", deserializedFunList.get(1).toString());
- assertEquals("100", deserializedFunList.get(2).toString());
- }
-
- @Test
- public void shouldSerializeIterableWithNull() throws Exception {
- final ArrayList<Integer> list = new ArrayList<>();
- list.add(1);
- list.add(null);
- list.add(100);
-
- final ResponseMessage response = convertBinary(list);
- assertCommon(response);
-
- final java.util.List<Integer> deserializedFunList = (java.util.List<Integer>) response.getResult().getData();
- assertEquals(3, deserializedFunList.size());
- assertEquals(new Integer(1), deserializedFunList.get(0));
- assertNull(deserializedFunList.get(1));
- assertEquals(new Integer(100), deserializedFunList.get(2));
- }
-
- @Test
- public void shouldSerializeMap() throws Exception {
- final Map<String, Object> map = new HashMap<>();
- final Map<String, String> innerMap = new HashMap<>();
- innerMap.put("a", "b");
-
- map.put("x", 1);
- map.put("y", "some");
- map.put("z", innerMap);
-
- final ResponseMessage response = convertBinary(map);
- assertCommon(response);
-
- final Map<String, Object> deserializedMap = (Map<String, Object>) response.getResult().getData();
- assertEquals(3, deserializedMap.size());
- assertEquals(1, deserializedMap.get("x"));
- assertEquals("some", deserializedMap.get("y"));
-
- final Map<String, String> deserializedInnerMap = (Map<String, String>) deserializedMap.get("z");
- assertEquals(1, deserializedInnerMap.size());
- assertEquals("b", deserializedInnerMap.get("a"));
- }
-
- @Test
- public void shouldSerializeMapEntry() throws Exception {
- final Graph graph = TinkerGraph.open();
- final Vertex v1 = graph.addVertex();
- final Date d = new Date();
-
- final Map<Object, Object> map = new HashMap<>();
- map.put("x", 1);
- map.put(v1, 100);
- map.put(d, "test");
-
- final ResponseMessage response = convertBinary(IteratorUtils.asList(map.entrySet()));
- assertCommon(response);
-
- final java.util.List<Map.Entry<Object, Object>> deserializedEntries = (java.util.List<Map.Entry<Object, Object>>) response.getResult().getData();
- assertEquals(3, deserializedEntries.size());
- deserializedEntries.forEach(e -> {
- if (e.getKey().equals("x"))
- assertEquals(1, e.getValue());
- else if (e.getKey().equals(v1))
- assertEquals(100, e.getValue());
- else if (e.getKey().equals(d))
- assertEquals("test", e.getValue());
- else
- fail("Map entries contains a key that is not part of what was serialized");
- });
- }
-
- @Test
- public void shouldSerializeTree() throws Exception {
- final Graph g = TinkerFactory.createModern();
- final Tree t = g.traversal().V().out().out().tree().by("name").next();
-
- final ResponseMessage response = convertBinary(t);
- assertCommon(response);
-
- final Tree deserialized = (Tree) response.getResult().getData();
- assertEquals(t, deserialized);
-
- assertThat(deserialized.containsKey("marko"), is(true));
- assertEquals(1, deserialized.size());
-
- final Tree markoChildren = (Tree) deserialized.get("marko");
- assertThat(markoChildren.containsKey("josh"), is(true));
- assertEquals(1, markoChildren.size());
-
- final Tree joshChildren = (Tree) markoChildren.get("josh");
- assertThat(joshChildren.containsKey("lop"), is(true));
- assertThat(joshChildren.containsKey("ripple"), is(true));
- assertEquals(2, joshChildren.size());
- }
-
- @Test
- public void shouldSerializeFullResponseMessage() throws Exception {
- final UUID id = UUID.randomUUID();
-
- final Map<String, Object> metaData = new HashMap<>();
- metaData.put("test", "this");
- metaData.put("one", 1);
-
- final Map<String, Object> attributes = new HashMap<>();
- attributes.put("test", "that");
- attributes.put("two", 2);
-
- final ResponseMessage response = ResponseMessage.build(id)
- .responseMetaData(metaData)
- .code(ResponseStatusCode.SUCCESS)
- .result("some-result")
- .statusAttributes(attributes)
- .statusMessage("worked")
- .create();
-
- final ByteBuf bb = binarySerializer.serializeResponseAsBinary(response, allocator);
- final ResponseMessage deserialized = binarySerializer.deserializeResponse(bb);
-
- assertEquals(id, deserialized.getRequestId());
- assertEquals("this", deserialized.getResult().getMeta().get("test"));
- assertEquals(1, deserialized.getResult().getMeta().get("one"));
- assertEquals("some-result", deserialized.getResult().getData());
- assertEquals("that", deserialized.getStatus().getAttributes().get("test"));
- assertEquals(2, deserialized.getStatus().getAttributes().get("two"));
- assertEquals(ResponseStatusCode.SUCCESS.getValue(), deserialized.getStatus().getCode().getValue());
- assertEquals("worked", deserialized.getStatus().getMessage());
- }
-
- @Test
- public void shouldHaveTooSmallBufferToSerializeResponseMessage() throws Exception {
- final UUID id = UUID.randomUUID();
-
- final Map<String, Object> metaData = new HashMap<>();
- metaData.put("test", "this");
- metaData.put("one", 1);
-
- final Map<String, Object> attributes = new HashMap<>();
- attributes.put("test", "that");
- attributes.put("two", 2);
-
- final ResponseMessage response = ResponseMessage.build(id)
- .responseMetaData(metaData)
- .code(ResponseStatusCode.SUCCESS)
- .result("some-result")
- .statusAttributes(attributes)
- .statusMessage("worked")
- .create();
-
- final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
- final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
- put("bufferSize", 1);
- }};
- binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
-
- try {
- binarySerializerWithSmallBuffer.serializeResponseAsBinary(response, allocator);
- fail("Should have a buffer size that is too small");
- } catch (Exception ex) {
- final Throwable root = ExceptionUtils.getRootCause(ex);
- assertThat(root, instanceOf(KryoException.class));
- }
- }
-
- @Test
- public void shouldReturnAllBytesInResponse() throws Exception {
- final UUID id = UUID.randomUUID();
-
- final Map<String, Object> metaData = new HashMap<>();
- metaData.put("test", "this");
- metaData.put("one", 1);
-
- final Map<String, Object> attributes = new HashMap<>();
- attributes.put("test", "that");
- attributes.put("two", 2);
-
- final ResponseMessage response = ResponseMessage.build(id)
- .responseMetaData(metaData)
- .code(ResponseStatusCode.SUCCESS)
- .result("some-result")
- .statusAttributes(attributes)
- .statusMessage("worked")
- .create();
-
- final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
- final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
- // set to bufferSize < total message size but still greater than any individual object requires
- put("bufferSize", 50);
- }};
- binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
-
- final ByteBuf buf = binarySerializerWithSmallBuffer.serializeResponseAsBinary(response, allocator);
- assertTrue(buf.isReadable());
- assertEquals(82, buf.readableBytes());
- }
-
- @Test
- public void shouldSerializeFullRequestMessage() throws Exception {
- final UUID id = UUID.randomUUID();
-
- final RequestMessage request = RequestMessage.build("try")
- .overrideRequestId(id)
- .processor("pro")
- .addArg("test", "this")
- .create();
- final ByteBuf bb = binarySerializer.serializeRequestAsBinary(request, allocator);
- final int mimeLen = bb.readByte();
- bb.readBytes(new byte[mimeLen]);
- final RequestMessage deserialized = binarySerializer.deserializeRequest(bb);
-
- assertEquals(id, deserialized.getRequestId());
- assertEquals("pro", deserialized.getProcessor());
- assertEquals("try", deserialized.getOp());
- assertEquals("this", deserialized.getArgs().get("test"));
- }
-
- @Test
- public void shouldHaveTooSmallBufferToSerializeRequestMessage() throws Exception {
- final UUID id = UUID.randomUUID();
-
- final RequestMessage request = RequestMessage.build("try")
- .overrideRequestId(id)
- .processor("pro")
- .addArg("test", "this")
- .create();
-
- final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
- final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
- put("bufferSize", 1);
- }};
- binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
-
- try {
- binarySerializerWithSmallBuffer.serializeRequestAsBinary(request, allocator);
- fail("Should have a buffer size that is too small");
- } catch (Exception ex) {
- final Throwable root = ExceptionUtils.getRootCause(ex);
- assertThat(root, instanceOf(KryoException.class));
- }
- }
-
- @Test
- public void shouldReturnAllBytesInRequest() throws Exception {
- final UUID id = UUID.randomUUID();
-
- final RequestMessage request = RequestMessage.build("try")
- .overrideRequestId(id)
- .processor("pro")
- .addArg("test", "this")
- .create();
-
- final MessageSerializer binarySerializerWithSmallBuffer = new GryoMessageSerializerV1d0();
- final Map<String, Object> configWithSmallBuffer = new HashMap<String, Object>() {{
- // set to bufferSize < total message size but still greater than any individual object requires
- put("bufferSize", 50);
- }};
- binarySerializerWithSmallBuffer.configure(configWithSmallBuffer, null);
-
- ByteBuf buf = binarySerializerWithSmallBuffer.serializeRequestAsBinary(request, allocator);
- assertTrue(buf.isReadable());
- assertEquals(71, buf.readableBytes());
- }
-
- private void assertCommon(final ResponseMessage response) {
- assertEquals(requestId, response.getRequestId());
- assertEquals(ResponseStatusCode.SUCCESS, response.getStatus().getCode());
- }
-
- private ResponseMessage convertBinary(final Object toSerialize) throws SerializationException {
- final ByteBuf bb = binarySerializer.serializeResponseAsBinary(responseMessageBuilder.result(toSerialize).create(), allocator);
- return binarySerializer.deserializeResponse(bb);
- }
-
- private ResponseMessage convertText(final Object toSerialize) throws SerializationException {
- final ByteBuf bb = textSerializer.serializeResponseAsBinary(responseMessageBuilder.result(toSerialize).create(), allocator);
- return textSerializer.deserializeResponse(bb);
- }
-
- public static class ErrorOnlyClassResolverSupplierAsInstance implements Supplier<ClassResolver> {
-
- private static final ErrorOnlyClassResolverSupplierAsInstance instance = new ErrorOnlyClassResolverSupplierAsInstance();
-
- private ErrorOnlyClassResolverSupplierAsInstance() {}
-
- public static ErrorOnlyClassResolverSupplierAsInstance instance() {
- return instance;
- }
-
- @Override
- public ClassResolver get() {
- return new ErrorOnlyClassResolver();
- }
- }
-
- public static class ErrorOnlyClassResolverSupplierAsGetInstance implements Supplier<ClassResolver> {
-
- private static final ErrorOnlyClassResolverSupplierAsInstance instance = new ErrorOnlyClassResolverSupplierAsInstance();
-
- private ErrorOnlyClassResolverSupplierAsGetInstance() {}
-
- public static ErrorOnlyClassResolverSupplierAsInstance getInstance() {
- return instance;
- }
-
- @Override
- public ClassResolver get() {
- return new ErrorOnlyClassResolver();
- }
- }
-
- public static class ErrorOnlyClassResolverSupplier implements Supplier<ClassResolver> {
- @Override
- public ClassResolver get() {
- return new ErrorOnlyClassResolver();
- }
- }
-
- public static class ErrorOnlyClassResolver extends GryoClassResolverV1d0 {
- @Override
- public Registration getRegistration(Class clazz) {
- throw new RuntimeException("Registration is not allowed with this ClassResolver - it is not a good implementation");
- }
- }
-
- public static class ColorIoRegistry extends AbstractIoRegistry {
- public ColorIoRegistry() {
- register(GryoIo.class, Color.class, new ColorSerializer());
- }
- }
-
- public static class ColorIoRegistryInstance extends AbstractIoRegistry {
-
- private static final ColorIoRegistry instance = new ColorIoRegistry();
-
- private ColorIoRegistryInstance() {
- register(GryoIo.class, Color.class, new ColorSerializer());
- }
-
- public static ColorIoRegistry instance() {
- return instance;
- }
- }
-
- public static class ColorIoRegistryGetInstance extends AbstractIoRegistry {
-
- private static final ColorIoRegistry instance = new ColorIoRegistry();
-
- private ColorIoRegistryGetInstance() {
- register(GryoIo.class, Color.class, new ColorSerializer());
- }
-
- public static ColorIoRegistry getInstance() {
- return instance;
- }
- }
-
- public static class ColorSerializer extends Serializer<Color> {
- @Override
- public void write(final Kryo kryo, final Output output, final Color color) {
- output.write(color.equals(Color.RED) ? 1 : 0);
- }
-
- @Override
- public Color read(final Kryo kryo, final Input input, final Class<Color> aClass) {
- return input.read() == 1 ? Color.RED : Color.BLACK;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index 746c6f8..041095c 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -342,8 +342,8 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
fail("Should have thrown exception over bad serialization");
} catch (Exception ex) {
final Throwable inner = ExceptionUtils.getRootCause(ex);
- assertTrue(inner instanceof RuntimeException);
- assertThat(inner.getMessage(), startsWith("Encountered unregistered class ID:"));
+ assertThat(inner, instanceOf(ResponseException.class));
+ assertEquals(ResponseStatusCode.SERVER_ERROR_SERIALIZATION, ((ResponseException) inner).getResponseStatusCode());
}
// should not die completely just because we had a bad serialization error. that kind of stuff happens
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfcdd26e/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
index e691e1c..94b6513 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinResultSetIntegrateTest.java
@@ -23,7 +23,7 @@ import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
import org.apache.tinkerpop.gremlin.driver.Result;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
-import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
+import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0;
import org.apache.tinkerpop.gremlin.driver.ser.Serializers;
import org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
@@ -42,7 +42,7 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.hamcrest.CoreMatchers;
import org.junit.After;
@@ -80,9 +80,9 @@ public class GremlinResultSetIntegrateTest extends AbstractGremlinServerIntegrat
@Before
public void beforeTest() {
- final MessageSerializer serializer = new GryoMessageSerializerV1d0();
+ final MessageSerializer serializer = new GryoMessageSerializerV3d0();
final Map<String,Object> c = new HashMap<>();
- c.put("ioRegistries", Collections.singletonList(TinkerIoRegistryV1d0.class.getName()));
+ c.put("ioRegistries", Collections.singletonList(TinkerIoRegistryV3d0.class.getName()));
c.put("custom", Collections.singletonList("groovy.json.JsonBuilder;org.apache.tinkerpop.gremlin.driver.ser.JsonBuilderGryoSerializer"));
serializer.configure(c, null);