This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2279 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 37fc9a0374ce70b2cbcdba9e94c2efa23063333c Author: Stephen Mallette <sp...@genoprime.com> AuthorDate: Thu Aug 15 15:27:09 2019 -0400 All GLV tests passing for GraphBinary Had to make a nubmer of tweaks to get this working. Most specifically PSerializer which wasn't properly accounting for the normalization that java seems to do. --- .../gremlin/driver/ser/binary/types/PSerializer.java | 18 ++++++++++++------ .../binary/GraphBinaryReaderWriterRoundTripTest.java | 1 + gremlin-python/pom.xml | 2 +- .../gremlin_python/structure/io/graphbinaryV1.py | 9 ++++++++- .../jython/tests/structure/io/test_graphbinaryV1.py | 11 ++++++++++- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/PSerializer.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/PSerializer.java index f83816f..be399f0 100644 --- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/PSerializer.java +++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/PSerializer.java @@ -62,14 +62,15 @@ public class PSerializer<T extends P> extends SimpleTypeSerializer<T> { args[i] = context.read(buffer); argumentClasses[i] = args[i].getClass(); } - - if ("and".equals(predicateName)) { + + if ("and".equals(predicateName)) return (T) ((P) args[0]).and((P) args[1]); - } else if ("or".equals(predicateName)) { + else if ("or".equals(predicateName)) return (T) ((P) args[0]).or((P) args[1]); - } + else if ("not".equals(predicateName)) + return (T) P.not((P) args[0]); - CheckedFunction<Object[], T> f = getMethod(predicateName, argumentClasses); + final CheckedFunction<Object[], T> f = getMethod(predicateName, argumentClasses); try { return f.apply(args); @@ -99,7 +100,12 @@ public class PSerializer<T extends P> extends SimpleTypeSerializer<T> { try { m = classOfP.getMethod(predicateName, Object.class); } catch (NoSuchMethodException ex2) { - throw new SerializationException(String.format("Can't find predicate method: '%s'", predicateName), ex2); + // finally go for the generics + try { + m = classOfP.getMethod(predicateName, Object.class, Object.class); + } catch (NoSuchMethodException ex3) { + throw new SerializationException(String.format("Can't find predicate method: '%s'", predicateName), ex2); + } } } } diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java index 48e324c..8f7874e 100644 --- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java +++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java @@ -228,6 +228,7 @@ public class GraphBinaryReaderWriterRoundTripTest { new Object[] {"Por", P.gt(1).or(P.lt(2)), null}, new Object[] {"Pnot", P.not(P.lte(1)), null}, new Object[] {"Pwithout", P.without(1,2,3,4), null}, + new Object[] {"Pinside", P.inside(0.0d, 0.6d), null}, new Object[] {"TextP", TextP.startingWith("mark"), null}, // graph diff --git a/gremlin-python/pom.xml b/gremlin-python/pom.xml index 48a45b0..4fd9c47 100644 --- a/gremlin-python/pom.xml +++ b/gremlin-python/pom.xml @@ -419,7 +419,7 @@ limitations under the License. <env key="PYTHONPATH" value=""/> <arg line="setup.py install"/> </exec> - <!-- run for graphson 2.0 --> + <!-- run for graphson 3.0 --> <exec executable="env/bin/radish" dir="${project.build.directory}/python2" failonerror="true"> <env key="PYTHONPATH" value=""/> diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py index ce03f40..738cfe7 100644 --- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py +++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py @@ -16,6 +16,8 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + +import six import datetime import calendar import struct @@ -127,7 +129,12 @@ class GraphBinaryWriter(object): def toDict(self, obj): try: - return self.serializers[type(obj)].dictify(obj, self) + t = type(obj) + + # coerce unicode to str so the serializer will be found properly in the cache...better way? + if not six.PY3: + t = str if isinstance(obj, unicode) else t + return self.serializers[t].dictify(obj, self) except KeyError: for key, serializer in self.serializers.items(): if isinstance(obj, key): diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py index bcaad3d..917e7f2 100644 --- a/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py +++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py @@ -119,7 +119,16 @@ class TestGraphSONWriter(object): 987: ["go", "deep", {"here": "!"}]} output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x)) assert x == output - + + x = {"marko": [666], "noone": ["blah"]} + output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x)) + assert x == output + + x = {"ripple": [], "peter": ["created"], "noone": ["blah"], "vadas": [], + "josh": ["created", "created"], "lop": [], "marko": [666, "created", "knows", "knows"]} + output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x)) + assert x == output + def test_uuid(self): x = uuid.UUID("41d2e28a-20a4-4ab0-b379-d810dede3786") output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))