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 2016/12/27 15:46:23 UTC
[27/27] tinkerpop git commit: TINKERPOP-1130 Fixed ByteBuffer
compatibility with Gryo.
TINKERPOP-1130 Fixed ByteBuffer compatibility with Gryo.
Required a fix to 3.2.4 and the tp32 branch for this to work completely.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/10d5bf87
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/10d5bf87
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/10d5bf87
Branch: refs/heads/TINKERPOP-1130
Commit: 10d5bf876e2c64503c32879368aecc9a06fef57c
Parents: a69bf43
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Dec 27 10:44:59 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Dec 27 10:44:59 2016 -0500
----------------------------------------------------------------------
gremlin-tools/gremlin-io-test/pom.xml | 2 -
.../tinkerpop/gremlin/structure/io/Model.java | 39 ++++++++++++++-----
.../io/AbstractTypedCompatibilityTest.java | 14 ++++---
.../io/gryo/GryoCompatibilityTest.java | 6 ++-
.../io/gryo/_3_2_4/bytebuffer-v1d0.kryo | Bin 10 -> 23 bytes
.../io/gryo/_3_2_4/manual-gryo-generator.groovy | 2 +-
.../io/gryo/_3_3_0/bytebuffer-v3d0.kryo | Bin 5 -> 23 bytes
7 files changed, 44 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/pom.xml b/gremlin-tools/gremlin-io-test/pom.xml
index ddac98f..7208530 100644
--- a/gremlin-tools/gremlin-io-test/pom.xml
+++ b/gremlin-tools/gremlin-io-test/pom.xml
@@ -339,10 +339,8 @@ mapper = GryoMapper.build().
addRegistry(TinkerIoRegistryV2d0.getInstance()).
create().createMapper()
-println "1.0*************************"
writeSupportedObjects(mapper, toGryoV1d0)
-println "3.0*************************"
mapper = GryoMapper.build().
version(GryoVersion.V3_0).
addRegistry(TinkerIoRegistryV2d0.getInstance()).
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Model.java
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Model.java b/gremlin-tools/gremlin-io-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Model.java
index 0b9fc26..b3c815f 100644
--- a/gremlin-tools/gremlin-io-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Model.java
+++ b/gremlin-tools/gremlin-io-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Model.java
@@ -73,6 +73,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -204,9 +205,9 @@ public class Model {
addExtendedEntry(new BigDecimal(new java.math.BigInteger("123456789987654321123456789987654321")), "BigDecimal", "", UNTYPED_GRAPHSON_ONLY.toArray(new Compatibility[UNTYPED_GRAPHSON_ONLY.size()]));
addExtendedEntry(new BigInteger("123456789987654321123456789987654321"), "BigInteger", "", UNTYPED_GRAPHSON_ONLY.toArray(new Compatibility[UNTYPED_GRAPHSON_ONLY.size()]));
addExtendedEntry(new Byte("1"), "Byte", "", UNTYPED_GRAPHSON_ONLY.toArray(new Compatibility[UNTYPED_GRAPHSON_ONLY.size()]));
- addExtendedEntry(java.nio.ByteBuffer.wrap("some bytes for you".getBytes()), "ByteBuffer", "",
- GraphSONCompatibility.V1D0_3_2_3, GraphSONCompatibility.V1D0_3_3_0, GraphSONCompatibility.V2D0_NO_TYPE_3_2_3, GraphSONCompatibility.V2D0_NO_TYPE_3_3_0,
- GryoCompatibility.V1D0_3_2_3, GryoCompatibility.V1D0_3_2_4, GryoCompatibility.V1D0_3_3_0);
+ addEntry("Extended", () -> java.nio.ByteBuffer.wrap("some bytes for you".getBytes()), "ByteBuffer", "",
+ GraphSONCompatibility.V1D0_3_2_3, GraphSONCompatibility.V1D0_3_3_0, GraphSONCompatibility.V2D0_NO_TYPE_3_2_3,
+ GraphSONCompatibility.V2D0_NO_TYPE_3_3_0, GryoCompatibility.V1D0_3_2_3);
addExtendedEntry("x".charAt(0), "Char", "", UNTYPED_GRAPHSON_ONLY.toArray(new Compatibility[UNTYPED_GRAPHSON_ONLY.size()]));
addExtendedEntry(Duration.ofDays(5), "Duration","The following example is a `Duration` of five days.");
try {
@@ -349,17 +350,29 @@ public class Model {
addEntry(group, obj, title, description, ALL);
}
- private void addEntry(final String group, final Object obj, final String title, final String description, final List<Compatibility> compatibleWith) {
- if (!entries.containsKey(group))
- entries.put(group, new ArrayList<>());
-
- entries.get(group).add(new Entry(title, obj, description, compatibleWith));
+ private void addEntry(final String group, final Supplier<?> maker, final String title, final String description, final Compatibility... incompatibleWith) {
+ addEntry(group, null, title, description, Collections.unmodifiableList(ALL.stream()
+ .filter(c -> !Arrays.asList(incompatibleWith).contains(c))
+ .collect(Collectors.toList())), maker);
}
private void addEntry(final String group, final Object obj, final String title, final String description, final Compatibility... incompatibleWith) {
addEntry(group, obj, title, description, Collections.unmodifiableList(ALL.stream()
.filter(c -> !Arrays.asList(incompatibleWith).contains(c))
- .collect(Collectors.toList())));
+ .collect(Collectors.toList())), null);
+ }
+
+ private void addEntry(final String group, final Object obj, final String title, final String description,
+ final List<Compatibility> compatibleWith) {
+ addEntry(group, obj, title, description, compatibleWith, null);
+ }
+
+ private void addEntry(final String group, final Object obj, final String title, final String description,
+ final List<Compatibility> compatibleWith, final Supplier<?> maker) {
+ if (!entries.containsKey(group))
+ entries.put(group, new ArrayList<>());
+
+ entries.get(group).add(new Entry(title, obj, description, compatibleWith, maker));
}
public void saveAsCsv(final String file) throws Exception {
@@ -403,12 +416,18 @@ public class Model {
private final Object object;
private final String description;
private final List<Compatibility> compatibleWith;
+ private final Supplier<?> maker;
public Entry(final String title, final Object object, final String description, final List<Compatibility> compatibleWith) {
+ this(title, object, description, compatibleWith, null);
+ }
+
+ public Entry(final String title, final Object object, final String description, final List<Compatibility> compatibleWith, final Supplier<?> maker) {
this.title = title;
this.object = object;
this.description = description;
this.compatibleWith = compatibleWith;
+ this.maker = maker;
}
public String getTitle() {
@@ -420,7 +439,7 @@ public class Model {
}
public <T> T getObject() {
- return (T) object;
+ return (T) ((null == object) ? maker.get() : object);
}
public String getDescription() {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
index 362175f..19114e5 100644
--- a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
+++ b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/AbstractTypedCompatibilityTest.java
@@ -188,11 +188,15 @@ public abstract class AbstractTypedCompatibilityTest extends AbstractCompatibili
final ByteBuffer resource = findModelEntryObject(resourceName);
final ByteBuffer fromStatic = read(getCompatibility().readFromResource(resourceName), ByteBuffer.class);
- final ByteBuffer recycled = read(write(fromStatic, ByteBuffer.class), ByteBuffer.class);
- assertNotSame(fromStatic, recycled);
- assertThat(Arrays.equals(fromStatic.array(), recycled.array()), is(true));
- assertThat(Arrays.equals(resource.array(), fromStatic.array()), is(true));
- assertThat(Arrays.equals(resource.array(), recycled.array()), is(true));
+ // have to re-read because once the bytebuffer is flushed to array it will be emptied
+ final ByteBuffer recycled = read(write(read(getCompatibility().readFromResource(resourceName), ByteBuffer.class), ByteBuffer.class), ByteBuffer.class);
+ assertNotSame(fromStatic, recycled);
+ final byte[] resourceArray = resource.array();
+ final byte[] fromStaticArray = fromStatic.array();
+ final byte[] recycledArray = recycled.array();
+ assertThat(Arrays.equals(fromStaticArray, recycledArray), is(true));
+ assertThat(Arrays.equals(resourceArray, fromStaticArray), is(true));
+ assertThat(Arrays.equals(resourceArray, recycledArray), is(true));
}
@Test
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoCompatibilityTest.java b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoCompatibilityTest.java
index 0d22643..3e7d41a 100644
--- a/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoCompatibilityTest.java
+++ b/gremlin-tools/gremlin-io-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoCompatibilityTest.java
@@ -38,13 +38,17 @@ public class GryoCompatibilityTest extends AbstractTypedCompatibilityTest {
private static Kryo mapperV1 = GryoMapper.build().
addRegistry(TinkerIoRegistryV2d0.instance()).create().createMapper();
+ private static Kryo mapperV3 = GryoMapper.build().
+ version(GryoVersion.V3_0).
+ addRegistry(TinkerIoRegistryV2d0.instance()).create().createMapper();
@Parameterized.Parameters(name = "expect({0})")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{GryoCompatibility.V1D0_3_2_3, mapperV1 },
{GryoCompatibility.V1D0_3_2_4, mapperV1 },
- {GryoCompatibility.V1D0_3_3_0, mapperV1 }});
+ {GryoCompatibility.V1D0_3_3_0, mapperV1 },
+ {GryoCompatibility.V3D0_3_3_0, mapperV3 }});
}
@Parameterized.Parameter(value = 0)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/bytebuffer-v1d0.kryo
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/bytebuffer-v1d0.kryo b/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/bytebuffer-v1d0.kryo
index 82bb738..ba94b5d 100644
Binary files a/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/bytebuffer-v1d0.kryo and b/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/bytebuffer-v1d0.kryo differ
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/manual-gryo-generator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/manual-gryo-generator.groovy b/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/manual-gryo-generator.groovy
index bc65144..d5576c8 100644
--- a/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/manual-gryo-generator.groovy
+++ b/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_2_4/manual-gryo-generator.groovy
@@ -169,7 +169,7 @@ writeSupportedObjects = { mapper, toGryoFunction ->
toGryoFunction(new java.math.BigDecimal(new java.math.BigInteger("123456789987654321123456789987654321")), "BigDecimal", mapper)
toGryoFunction(new java.math.BigInteger("123456789987654321123456789987654321"), "BigInteger", mapper)
toGryoFunction(new Byte("1"), "Byte", mapper)
- toGryoFunction(java.nio.ByteBuffer.wrap([1,2,3,4,5] as byte[]), "ByteBuffer", mapper)
+ toGryoFunction(java.nio.ByteBuffer.wrap("some bytes for you".getBytes()), "ByteBuffer", mapper)
toGryoFunction("x".charAt(0), "Char", mapper)
toGryoFunction(Duration.ofDays(5), "Duration", mapper)
toGryoFunction(java.net.InetAddress.getByName("localhost"), "InetAddress", mapper)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/10d5bf87/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_3_0/bytebuffer-v3d0.kryo
----------------------------------------------------------------------
diff --git a/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_3_0/bytebuffer-v3d0.kryo b/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_3_0/bytebuffer-v3d0.kryo
index 51d72fb..ba94b5d 100644
Binary files a/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_3_0/bytebuffer-v3d0.kryo and b/gremlin-tools/gremlin-io-test/src/test/resources/org/apache/tinkerpop/gremlin/structure/io/gryo/_3_3_0/bytebuffer-v3d0.kryo differ