You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/01/05 23:54:57 UTC
[25/50] incubator-tinkerpop git commit: Removed test IoRegistry
implementations for ClassResolver.
Removed test IoRegistry implementations for ClassResolver.
Apparently, it is unnecessary to register a serializer to a class whose registration is overriden by the ClassResolver. That's kinda cool.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a51701d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a51701d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a51701d9
Branch: refs/heads/TINKERPOP-1033
Commit: a51701d907539328d8a486cfb4f03e7ef5082554
Parents: a94c51f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Dec 24 07:00:12 2015 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Dec 24 07:00:12 2015 -0500
----------------------------------------------------------------------
.../gremlin/structure/io/IoXIoRegistry.java | 6 --
.../gremlin/structure/io/IoYIoRegistry.java | 6 --
.../structure/io/gryo/GryoMapperTest.java | 75 ++++++++++----------
3 files changed, 36 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a51701d9/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
index ddc5477..c49ea0b 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
@@ -56,12 +56,6 @@ public class IoXIoRegistry {
}
}
- public static class SerializerToVertexBased extends AbstractIoRegistry {
- public SerializerToVertexBased() {
- register(GryoIo.class, IoX.class, new IoXToVertexSerializer());
- }
- }
-
/**
* Converts an {@link IoX} to a {@link DetachedVertex}.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a51701d9/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
index 53c3404..1654945 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
@@ -51,12 +51,6 @@ public class IoYIoRegistry {
}
}
- public static class SerializerToMapBased extends AbstractIoRegistry {
- public SerializerToMapBased() {
- register(GryoIo.class, IoY.class, new IoYToHashMapSerializer());
- }
- }
-
/**
* Converts an {@link IoX} to a {@link HashMap}.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a51701d9/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 947528c..76a2804 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
@@ -19,7 +19,6 @@
package org.apache.tinkerpop.gremlin.structure.io.gryo;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
import org.apache.tinkerpop.gremlin.structure.io.IoX;
import org.apache.tinkerpop.gremlin.structure.io.IoXIoRegistry;
import org.apache.tinkerpop.gremlin.structure.io.IoY;
@@ -86,9 +85,8 @@ public class GryoMapperTest {
@Test
public void shouldSerializeWithCustomClassResolverToDetachedVertex() throws Exception {
- final IoRegistry ioRegistry = new IoXIoRegistry.SerializerToVertexBased();
final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier();
- final GryoMapper mapper = GryoMapper.build().addRegistry(ioRegistry).classResolver(classResolver).create();
+ final GryoMapper mapper = GryoMapper.build().classResolver(classResolver).create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -108,9 +106,8 @@ public class GryoMapperTest {
@Test
public void shouldSerializeWithCustomClassResolverToHashMap() throws Exception {
- final IoRegistry ioRegistry = new IoXIoRegistry.SerializerToVertexBased();
final Supplier<ClassResolver> classResolver = new CustomClassResolverSupplier();
- final GryoMapper mapper = GryoMapper.build().addRegistry(ioRegistry).classResolver(classResolver).create();
+ final GryoMapper mapper = GryoMapper.build().classResolver(classResolver).create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
@@ -128,40 +125,6 @@ public class GryoMapperTest {
}
}
- /**
- * Creates new {@link CustomClassResolver} when requested.
- */
- public static class CustomClassResolverSupplier implements Supplier<ClassResolver> {
- @Override
- public ClassResolver get() {
- return new CustomClassResolver();
- }
- }
-
- /**
- * A custom {@code ClassResolver} that alters the {@code Registration} returned to Kryo when an {@link IoX} class
- * is requested, coercing it to a totally different class (a {@link DetachedVertex}). This coercion demonstrates
- * how a TinkerPop provider might take a custom internal class and serialize it into something core to
- * TinkerPop which then removes the requirement for providers to expose serializers on the client side for user
- * consumption.
- */
- public static class CustomClassResolver extends GryoClassResolver {
- private IoXIoRegistry.IoXToVertexSerializer ioXToVertexSerializer = new IoXIoRegistry.IoXToVertexSerializer();
- private IoYIoRegistry.IoYToHashMapSerializer ioYToHashMapSerializer = new IoYIoRegistry.IoYToHashMapSerializer();
-
- public Registration getRegistration(final Class clazz) {
- if (IoX.class.isAssignableFrom(clazz)) {
- final Registration registration = super.getRegistration(DetachedVertex.class);
- return new Registration(registration.getType(), ioXToVertexSerializer, registration.getId());
- } else if (IoY.class.isAssignableFrom(clazz)) {
- final Registration registration = super.getRegistration(HashMap.class);
- return new Registration(registration.getType(), ioYToHashMapSerializer, registration.getId());
- } else {
- return super.getRegistration(clazz);
- }
- }
- }
-
@Test
public void shouldSerializeWithoutRegistration() throws Exception {
final GryoMapper mapper = GryoMapper.build().registrationRequired(false).create();
@@ -236,4 +199,38 @@ public class GryoMapperTest {
}
}
}
+
+ /**
+ * Creates new {@link CustomClassResolver} when requested.
+ */
+ public static class CustomClassResolverSupplier implements Supplier<ClassResolver> {
+ @Override
+ public ClassResolver get() {
+ return new CustomClassResolver();
+ }
+ }
+
+ /**
+ * A custom {@code ClassResolver} that alters the {@code Registration} returned to Kryo when an {@link IoX} class
+ * is requested, coercing it to a totally different class (a {@link DetachedVertex}). This coercion demonstrates
+ * how a TinkerPop provider might take a custom internal class and serialize it into something core to
+ * TinkerPop which then removes the requirement for providers to expose serializers on the client side for user
+ * consumption.
+ */
+ public static class CustomClassResolver extends GryoClassResolver {
+ private IoXIoRegistry.IoXToVertexSerializer ioXToVertexSerializer = new IoXIoRegistry.IoXToVertexSerializer();
+ private IoYIoRegistry.IoYToHashMapSerializer ioYToHashMapSerializer = new IoYIoRegistry.IoYToHashMapSerializer();
+
+ public Registration getRegistration(final Class clazz) {
+ if (IoX.class.isAssignableFrom(clazz)) {
+ final Registration registration = super.getRegistration(DetachedVertex.class);
+ return new Registration(registration.getType(), ioXToVertexSerializer, registration.getId());
+ } else if (IoY.class.isAssignableFrom(clazz)) {
+ final Registration registration = super.getRegistration(HashMap.class);
+ return new Registration(registration.getType(), ioYToHashMapSerializer, registration.getId());
+ } else {
+ return super.getRegistration(clazz);
+ }
+ }
+ }
}