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/08/22 20:40:10 UTC
[25/48] tinkerpop git commit: TINKERPOP-1274: GraphSON 2.0.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-normalized-v2d0.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-normalized-v2d0.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-normalized-v2d0.json
new file mode 100644
index 0000000..cb08148
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-normalized-v2d0.json
@@ -0,0 +1,6 @@
+{"id":1,"label":"vertex","outE":{"created":[{"id":9,"inV":3,"properties":{"weight":0.4}}],"knows":[{"id":7,"inV":2,"properties":{"weight":0.5}},{"id":8,"inV":4,"properties":{"weight":1.0}}]},"properties":{"age":[{"id":2,"value":29}],"name":[{"id":0,"value":"marko"}]}}
+{"id":2,"label":"vertex","inE":{"knows":[{"id":7,"outV":1,"properties":{"weight":0.5}}]},"properties":{"age":[{"id":4,"value":27}],"name":[{"id":3,"value":"vadas"}]}}
+{"id":3,"label":"vertex","inE":{"created":[{"id":11,"outV":4,"properties":{"weight":0.4}},{"id":12,"outV":6,"properties":{"weight":0.2}},{"id":9,"outV":1,"properties":{"weight":0.4}}]},"properties":{"lang":[{"id":6,"value":"java"}],"name":[{"id":5,"value":"lop"}]}}
+{"id":4,"label":"vertex","inE":{"knows":[{"id":8,"outV":1,"properties":{"weight":1.0}}]},"outE":{"created":[{"id":10,"inV":5,"properties":{"weight":1.0}},{"id":11,"inV":3,"properties":{"weight":0.4}}]},"properties":{"age":[{"id":8,"value":32}],"name":[{"id":7,"value":"josh"}]}}
+{"id":5,"label":"vertex","inE":{"created":[{"id":10,"outV":4,"properties":{"weight":1.0}}]},"properties":{"lang":[{"id":10,"value":"java"}],"name":[{"id":9,"value":"ripple"}]}}
+{"id":6,"label":"vertex","outE":{"created":[{"id":12,"inV":3,"properties":{"weight":0.2}}]},"properties":{"age":[{"id":12,"value":35}],"name":[{"id":11,"value":"peter"}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0-typed.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0-typed.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0-typed.json
new file mode 100644
index 0000000..56956ea
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0-typed.json
@@ -0,0 +1,6 @@
+{"id":{"@type":"gremlin:int32","@value":1},"label":"vertex","outE":{"created":[{"id":{"@type":"gremlin:int32","@value":9},"inV":{"@type":"gremlin:int32","@value":3},"properties":{"weight":{"@type":"gremlin:float","@value":0.4}}}],"knows":[{"id":{"@type":"gremlin:int32","@value":7},"inV":{"@type":"gremlin:int32","@value":2},"properties":{"weight":{"@type":"gremlin:float","@value":0.5}}},{"id":{"@type":"gremlin:int32","@value":8},"inV":{"@type":"gremlin:int32","@value":4},"properties":{"weight":{"@type":"gremlin:float","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int32","@value":0},"value":"marko"}],"age":[{"id":{"@type":"gremlin:int32","@value":2},"value":{"@type":"gremlin:int32","@value":29}}]}}
+{"id":{"@type":"gremlin:int32","@value":2},"label":"vertex","inE":{"knows":[{"id":{"@type":"gremlin:int32","@value":7},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"weight":{"@type":"gremlin:float","@value":0.5}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int32","@value":3},"value":"vadas"}],"age":[{"id":{"@type":"gremlin:int32","@value":4},"value":{"@type":"gremlin:int32","@value":27}}]}}
+{"id":{"@type":"gremlin:int32","@value":3},"label":"vertex","inE":{"created":[{"id":{"@type":"gremlin:int32","@value":9},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"weight":{"@type":"gremlin:float","@value":0.4}}},{"id":{"@type":"gremlin:int32","@value":11},"outV":{"@type":"gremlin:int32","@value":4},"properties":{"weight":{"@type":"gremlin:float","@value":0.4}}},{"id":{"@type":"gremlin:int32","@value":12},"outV":{"@type":"gremlin:int32","@value":6},"properties":{"weight":{"@type":"gremlin:float","@value":0.2}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int32","@value":5},"value":"lop"}],"lang":[{"id":{"@type":"gremlin:int32","@value":6},"value":"java"}]}}
+{"id":{"@type":"gremlin:int32","@value":4},"label":"vertex","inE":{"knows":[{"id":{"@type":"gremlin:int32","@value":8},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"weight":{"@type":"gremlin:float","@value":1.0}}}]},"outE":{"created":[{"id":{"@type":"gremlin:int32","@value":10},"inV":{"@type":"gremlin:int32","@value":5},"properties":{"weight":{"@type":"gremlin:float","@value":1.0}}},{"id":{"@type":"gremlin:int32","@value":11},"inV":{"@type":"gremlin:int32","@value":3},"properties":{"weight":{"@type":"gremlin:float","@value":0.4}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int32","@value":7},"value":"josh"}],"age":[{"id":{"@type":"gremlin:int32","@value":8},"value":{"@type":"gremlin:int32","@value":32}}]}}
+{"id":{"@type":"gremlin:int32","@value":5},"label":"vertex","inE":{"created":[{"id":{"@type":"gremlin:int32","@value":10},"outV":{"@type":"gremlin:int32","@value":4},"properties":{"weight":{"@type":"gremlin:float","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int32","@value":9},"value":"ripple"}],"lang":[{"id":{"@type":"gremlin:int32","@value":10},"value":"java"}]}}
+{"id":{"@type":"gremlin:int32","@value":6},"label":"vertex","outE":{"created":[{"id":{"@type":"gremlin:int32","@value":12},"inV":{"@type":"gremlin:int32","@value":3},"properties":{"weight":{"@type":"gremlin:float","@value":0.2}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int32","@value":11},"value":"peter"}],"age":[{"id":{"@type":"gremlin:int32","@value":12},"value":{"@type":"gremlin:int32","@value":35}}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0.json
new file mode 100644
index 0000000..5ccfe05
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-classic-v2d0.json
@@ -0,0 +1,6 @@
+{"id":1,"label":"vertex","outE":{"created":[{"id":9,"inV":3,"properties":{"weight":0.4}}],"knows":[{"id":7,"inV":2,"properties":{"weight":0.5}},{"id":8,"inV":4,"properties":{"weight":1.0}}]},"properties":{"name":[{"id":0,"value":"marko"}],"age":[{"id":2,"value":29}]}}
+{"id":2,"label":"vertex","inE":{"knows":[{"id":7,"outV":1,"properties":{"weight":0.5}}]},"properties":{"name":[{"id":3,"value":"vadas"}],"age":[{"id":4,"value":27}]}}
+{"id":3,"label":"vertex","inE":{"created":[{"id":9,"outV":1,"properties":{"weight":0.4}},{"id":11,"outV":4,"properties":{"weight":0.4}},{"id":12,"outV":6,"properties":{"weight":0.2}}]},"properties":{"name":[{"id":5,"value":"lop"}],"lang":[{"id":6,"value":"java"}]}}
+{"id":4,"label":"vertex","inE":{"knows":[{"id":8,"outV":1,"properties":{"weight":1.0}}]},"outE":{"created":[{"id":10,"inV":5,"properties":{"weight":1.0}},{"id":11,"inV":3,"properties":{"weight":0.4}}]},"properties":{"name":[{"id":7,"value":"josh"}],"age":[{"id":8,"value":32}]}}
+{"id":5,"label":"vertex","inE":{"created":[{"id":10,"outV":4,"properties":{"weight":1.0}}]},"properties":{"name":[{"id":9,"value":"ripple"}],"lang":[{"id":10,"value":"java"}]}}
+{"id":6,"label":"vertex","outE":{"created":[{"id":12,"inV":3,"properties":{"weight":0.2}}]},"properties":{"name":[{"id":11,"value":"peter"}],"age":[{"id":12,"value":35}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0-typed.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0-typed.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0-typed.json
new file mode 100644
index 0000000..e688520
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0-typed.json
@@ -0,0 +1,6 @@
+{"id":{"@type":"gremlin:int32","@value":1},"label":"person","outE":{"uses":[{"id":{"@type":"gremlin:int32","@value":16},"inV":{"@type":"gremlin:int32","@value":11},"properties":{"skill":{"@type":"gremlin:int32","@value":5}}},{"id":{"@type":"gremlin:int32","@value":15},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"skill":{"@type":"gremlin:int32","@value":4}}}],"develops":[{"id":{"@type":"gremlin:int32","@value":13},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"since":{"@type":"gremlin:int32","@value":2009}}},{"id":{"@type":"gremlin:int32","@value":14},"inV":{"@type":"gremlin:int32","@value":11},"properties":{"since":{"@type":"gremlin:int32","@value":2010}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":0},"value":"marko"}],"location":[{"id":{"@type":"gremlin:int64","@value":6},"value":"san diego","properties":{"startTime":{"@type":"gremlin:int32","@value":1997},"endTime":{"@type":"gremlin:int32","@value":2001}}},{"id":{"@type":"gremlin:int6
4","@value":7},"value":"santa cruz","properties":{"startTime":{"@type":"gremlin:int32","@value":2001},"endTime":{"@type":"gremlin:int32","@value":2004}}},{"id":{"@type":"gremlin:int64","@value":8},"value":"brussels","properties":{"startTime":{"@type":"gremlin:int32","@value":2004},"endTime":{"@type":"gremlin:int32","@value":2005}}},{"id":{"@type":"gremlin:int64","@value":9},"value":"santa fe","properties":{"startTime":{"@type":"gremlin:int32","@value":2005}}}]}}
+{"id":{"@type":"gremlin:int32","@value":7},"label":"person","outE":{"uses":[{"id":{"@type":"gremlin:int32","@value":19},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"skill":{"@type":"gremlin:int32","@value":5}}},{"id":{"@type":"gremlin:int32","@value":20},"inV":{"@type":"gremlin:int32","@value":11},"properties":{"skill":{"@type":"gremlin:int32","@value":4}}}],"develops":[{"id":{"@type":"gremlin:int32","@value":17},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"since":{"@type":"gremlin:int32","@value":2010}}},{"id":{"@type":"gremlin:int32","@value":18},"inV":{"@type":"gremlin:int32","@value":11},"properties":{"since":{"@type":"gremlin:int32","@value":2011}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":1},"value":"stephen"}],"location":[{"id":{"@type":"gremlin:int64","@value":10},"value":"centreville","properties":{"startTime":{"@type":"gremlin:int32","@value":1990},"endTime":{"@type":"gremlin:int32","@value":2000}}},{"id":{"@type":"gremlin
:int64","@value":11},"value":"dulles","properties":{"startTime":{"@type":"gremlin:int32","@value":2000},"endTime":{"@type":"gremlin:int32","@value":2006}}},{"id":{"@type":"gremlin:int64","@value":12},"value":"purcellville","properties":{"startTime":{"@type":"gremlin:int32","@value":2006}}}]}}
+{"id":{"@type":"gremlin:int32","@value":8},"label":"person","outE":{"uses":[{"id":{"@type":"gremlin:int32","@value":22},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"skill":{"@type":"gremlin:int32","@value":3}}},{"id":{"@type":"gremlin:int32","@value":23},"inV":{"@type":"gremlin:int32","@value":11},"properties":{"skill":{"@type":"gremlin:int32","@value":3}}}],"develops":[{"id":{"@type":"gremlin:int32","@value":21},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"since":{"@type":"gremlin:int32","@value":2012}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":2},"value":"matthias"}],"location":[{"id":{"@type":"gremlin:int64","@value":13},"value":"bremen","properties":{"startTime":{"@type":"gremlin:int32","@value":2004},"endTime":{"@type":"gremlin:int32","@value":2007}}},{"id":{"@type":"gremlin:int64","@value":14},"value":"baltimore","properties":{"startTime":{"@type":"gremlin:int32","@value":2007},"endTime":{"@type":"gremlin:int32","@value":2011}
}},{"id":{"@type":"gremlin:int64","@value":15},"value":"oakland","properties":{"startTime":{"@type":"gremlin:int32","@value":2011},"endTime":{"@type":"gremlin:int32","@value":2014}}},{"id":{"@type":"gremlin:int64","@value":16},"value":"seattle","properties":{"startTime":{"@type":"gremlin:int32","@value":2014}}}]}}
+{"id":{"@type":"gremlin:int32","@value":9},"label":"person","outE":{"uses":[{"id":{"@type":"gremlin:int32","@value":24},"inV":{"@type":"gremlin:int32","@value":10},"properties":{"skill":{"@type":"gremlin:int32","@value":5}}},{"id":{"@type":"gremlin:int32","@value":25},"inV":{"@type":"gremlin:int32","@value":11},"properties":{"skill":{"@type":"gremlin:int32","@value":3}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":3},"value":"daniel"}],"location":[{"id":{"@type":"gremlin:int64","@value":17},"value":"spremberg","properties":{"startTime":{"@type":"gremlin:int32","@value":1982},"endTime":{"@type":"gremlin:int32","@value":2005}}},{"id":{"@type":"gremlin:int64","@value":18},"value":"kaiserslautern","properties":{"startTime":{"@type":"gremlin:int32","@value":2005},"endTime":{"@type":"gremlin:int32","@value":2009}}},{"id":{"@type":"gremlin:int64","@value":19},"value":"aachen","properties":{"startTime":{"@type":"gremlin:int32","@value":2009}}}]}}
+{"id":{"@type":"gremlin:int32","@value":10},"label":"software","inE":{"uses":[{"id":{"@type":"gremlin:int32","@value":19},"outV":{"@type":"gremlin:int32","@value":7},"properties":{"skill":{"@type":"gremlin:int32","@value":5}}},{"id":{"@type":"gremlin:int32","@value":22},"outV":{"@type":"gremlin:int32","@value":8},"properties":{"skill":{"@type":"gremlin:int32","@value":3}}},{"id":{"@type":"gremlin:int32","@value":24},"outV":{"@type":"gremlin:int32","@value":9},"properties":{"skill":{"@type":"gremlin:int32","@value":5}}},{"id":{"@type":"gremlin:int32","@value":15},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"skill":{"@type":"gremlin:int32","@value":4}}}],"develops":[{"id":{"@type":"gremlin:int32","@value":17},"outV":{"@type":"gremlin:int32","@value":7},"properties":{"since":{"@type":"gremlin:int32","@value":2010}}},{"id":{"@type":"gremlin:int32","@value":21},"outV":{"@type":"gremlin:int32","@value":8},"properties":{"since":{"@type":"gremlin:int32","@value":2012}}},{"id":
{"@type":"gremlin:int32","@value":13},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"since":{"@type":"gremlin:int32","@value":2009}}}]},"outE":{"traverses":[{"id":{"@type":"gremlin:int32","@value":26},"inV":{"@type":"gremlin:int32","@value":11}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":4},"value":"gremlin"}]}}
+{"id":{"@type":"gremlin:int32","@value":11},"label":"software","inE":{"traverses":[{"id":{"@type":"gremlin:int32","@value":26},"outV":{"@type":"gremlin:int32","@value":10}}],"uses":[{"id":{"@type":"gremlin:int32","@value":16},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"skill":{"@type":"gremlin:int32","@value":5}}},{"id":{"@type":"gremlin:int32","@value":20},"outV":{"@type":"gremlin:int32","@value":7},"properties":{"skill":{"@type":"gremlin:int32","@value":4}}},{"id":{"@type":"gremlin:int32","@value":23},"outV":{"@type":"gremlin:int32","@value":8},"properties":{"skill":{"@type":"gremlin:int32","@value":3}}},{"id":{"@type":"gremlin:int32","@value":25},"outV":{"@type":"gremlin:int32","@value":9},"properties":{"skill":{"@type":"gremlin:int32","@value":3}}}],"develops":[{"id":{"@type":"gremlin:int32","@value":18},"outV":{"@type":"gremlin:int32","@value":7},"properties":{"since":{"@type":"gremlin:int32","@value":2011}}},{"id":{"@type":"gremlin:int32","@value":14},"outV":{"@
type":"gremlin:int32","@value":1},"properties":{"since":{"@type":"gremlin:int32","@value":2010}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":5},"value":"tinkergraph"}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0.json
new file mode 100644
index 0000000..2165e4d
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-crew-v2d0.json
@@ -0,0 +1,6 @@
+{"id":1,"label":"person","outE":{"uses":[{"id":16,"inV":11,"properties":{"skill":5}},{"id":15,"inV":10,"properties":{"skill":4}}],"develops":[{"id":13,"inV":10,"properties":{"since":2009}},{"id":14,"inV":11,"properties":{"since":2010}}]},"properties":{"name":[{"id":0,"value":"marko"}],"location":[{"id":6,"value":"san diego","properties":{"startTime":1997,"endTime":2001}},{"id":7,"value":"santa cruz","properties":{"startTime":2001,"endTime":2004}},{"id":8,"value":"brussels","properties":{"startTime":2004,"endTime":2005}},{"id":9,"value":"santa fe","properties":{"startTime":2005}}]}}
+{"id":7,"label":"person","outE":{"uses":[{"id":19,"inV":10,"properties":{"skill":5}},{"id":20,"inV":11,"properties":{"skill":4}}],"develops":[{"id":17,"inV":10,"properties":{"since":2010}},{"id":18,"inV":11,"properties":{"since":2011}}]},"properties":{"name":[{"id":1,"value":"stephen"}],"location":[{"id":10,"value":"centreville","properties":{"startTime":1990,"endTime":2000}},{"id":11,"value":"dulles","properties":{"startTime":2000,"endTime":2006}},{"id":12,"value":"purcellville","properties":{"startTime":2006}}]}}
+{"id":8,"label":"person","outE":{"uses":[{"id":22,"inV":10,"properties":{"skill":3}},{"id":23,"inV":11,"properties":{"skill":3}}],"develops":[{"id":21,"inV":10,"properties":{"since":2012}}]},"properties":{"name":[{"id":2,"value":"matthias"}],"location":[{"id":13,"value":"bremen","properties":{"startTime":2004,"endTime":2007}},{"id":14,"value":"baltimore","properties":{"startTime":2007,"endTime":2011}},{"id":15,"value":"oakland","properties":{"startTime":2011,"endTime":2014}},{"id":16,"value":"seattle","properties":{"startTime":2014}}]}}
+{"id":9,"label":"person","outE":{"uses":[{"id":24,"inV":10,"properties":{"skill":5}},{"id":25,"inV":11,"properties":{"skill":3}}]},"properties":{"name":[{"id":3,"value":"daniel"}],"location":[{"id":17,"value":"spremberg","properties":{"startTime":1982,"endTime":2005}},{"id":18,"value":"kaiserslautern","properties":{"startTime":2005,"endTime":2009}},{"id":19,"value":"aachen","properties":{"startTime":2009}}]}}
+{"id":10,"label":"software","inE":{"uses":[{"id":19,"outV":7,"properties":{"skill":5}},{"id":22,"outV":8,"properties":{"skill":3}},{"id":24,"outV":9,"properties":{"skill":5}},{"id":15,"outV":1,"properties":{"skill":4}}],"develops":[{"id":17,"outV":7,"properties":{"since":2010}},{"id":21,"outV":8,"properties":{"since":2012}},{"id":13,"outV":1,"properties":{"since":2009}}]},"outE":{"traverses":[{"id":26,"inV":11}]},"properties":{"name":[{"id":4,"value":"gremlin"}]}}
+{"id":11,"label":"software","inE":{"traverses":[{"id":26,"outV":10}],"uses":[{"id":16,"outV":1,"properties":{"skill":5}},{"id":20,"outV":7,"properties":{"skill":4}},{"id":23,"outV":8,"properties":{"skill":3}},{"id":25,"outV":9,"properties":{"skill":3}}],"develops":[{"id":18,"outV":7,"properties":{"since":2011}},{"id":14,"outV":1,"properties":{"since":2010}}]},"properties":{"name":[{"id":5,"value":"tinkergraph"}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-normalized-v2d0.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-normalized-v2d0.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-normalized-v2d0.json
new file mode 100644
index 0000000..8c259ea
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-normalized-v2d0.json
@@ -0,0 +1,6 @@
+{"id":1,"label":"person","outE":{"created":[{"id":9,"inV":3,"properties":{"weight":0.4}}],"knows":[{"id":7,"inV":2,"properties":{"weight":0.5}},{"id":8,"inV":4,"properties":{"weight":1.0}}]},"properties":{"age":[{"id":1,"value":29}],"name":[{"id":0,"value":"marko"}]}}
+{"id":2,"label":"person","inE":{"knows":[{"id":7,"outV":1,"properties":{"weight":0.5}}]},"properties":{"age":[{"id":3,"value":27}],"name":[{"id":2,"value":"vadas"}]}}
+{"id":3,"label":"software","inE":{"created":[{"id":11,"outV":4,"properties":{"weight":0.4}},{"id":12,"outV":6,"properties":{"weight":0.2}},{"id":9,"outV":1,"properties":{"weight":0.4}}]},"properties":{"lang":[{"id":5,"value":"java"}],"name":[{"id":4,"value":"lop"}]}}
+{"id":4,"label":"person","inE":{"knows":[{"id":8,"outV":1,"properties":{"weight":1.0}}]},"outE":{"created":[{"id":10,"inV":5,"properties":{"weight":1.0}},{"id":11,"inV":3,"properties":{"weight":0.4}}]},"properties":{"age":[{"id":7,"value":32}],"name":[{"id":6,"value":"josh"}]}}
+{"id":5,"label":"software","inE":{"created":[{"id":10,"outV":4,"properties":{"weight":1.0}}]},"properties":{"lang":[{"id":9,"value":"java"}],"name":[{"id":8,"value":"ripple"}]}}
+{"id":6,"label":"person","outE":{"created":[{"id":12,"inV":3,"properties":{"weight":0.2}}]},"properties":{"age":[{"id":11,"value":35}],"name":[{"id":10,"value":"peter"}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0-typed.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0-typed.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0-typed.json
new file mode 100644
index 0000000..9a297c3
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0-typed.json
@@ -0,0 +1,6 @@
+{"id":{"@type":"gremlin:int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"gremlin:int32","@value":9},"inV":{"@type":"gremlin:int32","@value":3},"properties":{"weight":{"@type":"gremlin:double","@value":0.4}}}],"knows":[{"id":{"@type":"gremlin:int32","@value":7},"inV":{"@type":"gremlin:int32","@value":2},"properties":{"weight":{"@type":"gremlin:double","@value":0.5}}},{"id":{"@type":"gremlin:int32","@value":8},"inV":{"@type":"gremlin:int32","@value":4},"properties":{"weight":{"@type":"gremlin:double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"gremlin:int64","@value":1},"value":{"@type":"gremlin:int32","@value":29}}]}}
+{"id":{"@type":"gremlin:int32","@value":2},"label":"person","inE":{"knows":[{"id":{"@type":"gremlin:int32","@value":7},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"weight":{"@type":"gremlin:double","@value":0.5}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":2},"value":"vadas"}],"age":[{"id":{"@type":"gremlin:int64","@value":3},"value":{"@type":"gremlin:int32","@value":27}}]}}
+{"id":{"@type":"gremlin:int32","@value":3},"label":"software","inE":{"created":[{"id":{"@type":"gremlin:int32","@value":9},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"weight":{"@type":"gremlin:double","@value":0.4}}},{"id":{"@type":"gremlin:int32","@value":11},"outV":{"@type":"gremlin:int32","@value":4},"properties":{"weight":{"@type":"gremlin:double","@value":0.4}}},{"id":{"@type":"gremlin:int32","@value":12},"outV":{"@type":"gremlin:int32","@value":6},"properties":{"weight":{"@type":"gremlin:double","@value":0.2}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":4},"value":"lop"}],"lang":[{"id":{"@type":"gremlin:int64","@value":5},"value":"java"}]}}
+{"id":{"@type":"gremlin:int32","@value":4},"label":"person","inE":{"knows":[{"id":{"@type":"gremlin:int32","@value":8},"outV":{"@type":"gremlin:int32","@value":1},"properties":{"weight":{"@type":"gremlin:double","@value":1.0}}}]},"outE":{"created":[{"id":{"@type":"gremlin:int32","@value":10},"inV":{"@type":"gremlin:int32","@value":5},"properties":{"weight":{"@type":"gremlin:double","@value":1.0}}},{"id":{"@type":"gremlin:int32","@value":11},"inV":{"@type":"gremlin:int32","@value":3},"properties":{"weight":{"@type":"gremlin:double","@value":0.4}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":6},"value":"josh"}],"age":[{"id":{"@type":"gremlin:int64","@value":7},"value":{"@type":"gremlin:int32","@value":32}}]}}
+{"id":{"@type":"gremlin:int32","@value":5},"label":"software","inE":{"created":[{"id":{"@type":"gremlin:int32","@value":10},"outV":{"@type":"gremlin:int32","@value":4},"properties":{"weight":{"@type":"gremlin:double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":8},"value":"ripple"}],"lang":[{"id":{"@type":"gremlin:int64","@value":9},"value":"java"}]}}
+{"id":{"@type":"gremlin:int32","@value":6},"label":"person","outE":{"created":[{"id":{"@type":"gremlin:int32","@value":12},"inV":{"@type":"gremlin:int32","@value":3},"properties":{"weight":{"@type":"gremlin:double","@value":0.2}}}]},"properties":{"name":[{"id":{"@type":"gremlin:int64","@value":10},"value":"peter"}],"age":[{"id":{"@type":"gremlin:int64","@value":11},"value":{"@type":"gremlin:int32","@value":35}}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0.json
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0.json b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0.json
new file mode 100644
index 0000000..18c265d
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphson/tinkerpop-modern-v2d0.json
@@ -0,0 +1,6 @@
+{"id":1,"label":"person","outE":{"created":[{"id":9,"inV":3,"properties":{"weight":0.4}}],"knows":[{"id":7,"inV":2,"properties":{"weight":0.5}},{"id":8,"inV":4,"properties":{"weight":1.0}}]},"properties":{"name":[{"id":0,"value":"marko"}],"age":[{"id":1,"value":29}]}}
+{"id":2,"label":"person","inE":{"knows":[{"id":7,"outV":1,"properties":{"weight":0.5}}]},"properties":{"name":[{"id":2,"value":"vadas"}],"age":[{"id":3,"value":27}]}}
+{"id":3,"label":"software","inE":{"created":[{"id":9,"outV":1,"properties":{"weight":0.4}},{"id":11,"outV":4,"properties":{"weight":0.4}},{"id":12,"outV":6,"properties":{"weight":0.2}}]},"properties":{"name":[{"id":4,"value":"lop"}],"lang":[{"id":5,"value":"java"}]}}
+{"id":4,"label":"person","inE":{"knows":[{"id":8,"outV":1,"properties":{"weight":1.0}}]},"outE":{"created":[{"id":10,"inV":5,"properties":{"weight":1.0}},{"id":11,"inV":3,"properties":{"weight":0.4}}]},"properties":{"name":[{"id":6,"value":"josh"}],"age":[{"id":7,"value":32}]}}
+{"id":5,"label":"software","inE":{"created":[{"id":10,"outV":4,"properties":{"weight":1.0}}]},"properties":{"name":[{"id":8,"value":"ripple"}],"lang":[{"id":9,"value":"java"}]}}
+{"id":6,"label":"person","outE":{"created":[{"id":12,"inV":3,"properties":{"weight":0.2}}]},"properties":{"name":[{"id":10,"value":"peter"}],"age":[{"id":11,"value":35}]}}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/tinkergraph-gremlin/pom.xml
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/pom.xml b/tinkergraph-gremlin/pom.xml
index 4ee4878..85f7cc9 100644
--- a/tinkergraph-gremlin/pom.xml
+++ b/tinkergraph-gremlin/pom.xml
@@ -76,7 +76,7 @@ limitations under the License.
</activation>
<properties>
- <io.tmp.dir>${project.build.directory}/tinkerpop-io</io.tmp.dir>
+ <io.tmp.dir>${project.build.directory}/test-case-data/TinkerGraphTest/tinkerpop-io</io.tmp.dir>
</properties>
<build>
@@ -115,7 +115,7 @@ limitations under the License.
<directory>${io.tmp.dir}</directory>
<filtering>false</filtering>
<excludes>
- <exclude>**/*-normalized.json</exclude>
+ <exclude>**/*-normalized*.json</exclude>
<exclude>**/sample.kryo</exclude>
</excludes>
</resource>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
new file mode 100644
index 0000000..97c1cba
--- /dev/null
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerIoRegistryV2d0.java
@@ -0,0 +1,213 @@
+/*
+ * 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.tinkergraph.structure;
+
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONUtil;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TinkerPopJacksonModule;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
+import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
+import org.apache.tinkerpop.shaded.jackson.core.JsonParser;
+import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException;
+import org.apache.tinkerpop.shaded.jackson.databind.DeserializationContext;
+import org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider;
+import org.apache.tinkerpop.shaded.jackson.databind.deser.std.StdDeserializer;
+import org.apache.tinkerpop.shaded.jackson.databind.jsontype.TypeSerializer;
+import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdScalarSerializer;
+import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
+import org.apache.tinkerpop.shaded.kryo.Kryo;
+import org.apache.tinkerpop.shaded.kryo.Serializer;
+import org.apache.tinkerpop.shaded.kryo.io.Input;
+import org.apache.tinkerpop.shaded.kryo.io.Output;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An implementation of the {@link org.apache.tinkerpop.gremlin.structure.io.IoRegistry} interface that provides serializers with custom configurations for
+ * implementation specific classes that might need to be serialized. This registry allows a {@link org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph} to
+ * be serialized directly which is useful for moving small graphs around on the network.
+ * <p/>
+ * Most providers need not implement this kind of custom serializer as they will deal with much larger graphs that
+ * wouldn't be practical to serialize in this fashion. This is a bit of a special case for TinkerGraph given its
+ * in-memory status. Typical implementations would create serializers for a complex vertex identifier or a
+ * custom data class like a "geographic point".
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public final class TinkerIoRegistryV2d0 extends AbstractIoRegistry {
+
+ private static final TinkerIoRegistryV2d0 INSTANCE = new TinkerIoRegistryV2d0();
+
+ private TinkerIoRegistryV2d0() {
+ register(GryoIo.class, TinkerGraph.class, new TinkerGraphGryoSerializer());
+ register(GraphSONIo.class, null, new TinkerModuleV2d0());
+ }
+
+ public static TinkerIoRegistryV2d0 getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Provides a method to serialize an entire {@link org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph} into itself for Gryo. This is useful when
+ * shipping small graphs around through Gremlin Server. Reuses the existing Kryo instance for serialization.
+ */
+ final static class TinkerGraphGryoSerializer extends Serializer<TinkerGraph> {
+ @Override
+ public void write(final Kryo kryo, final Output output, final TinkerGraph graph) {
+ try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
+ GryoWriter.build().mapper(() -> kryo).create().writeGraph(stream, graph);
+ final byte[] bytes = stream.toByteArray();
+ output.writeInt(bytes.length);
+ output.write(bytes);
+ } catch (Exception io) {
+ throw new RuntimeException(io);
+ }
+ }
+
+ @Override
+ public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) {
+ final TinkerGraph graph = TinkerGraph.open();
+ final int len = input.readInt();
+ final byte[] bytes = input.readBytes(len);
+ try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) {
+ GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph);
+ } catch (Exception io) {
+ throw new RuntimeException(io);
+ }
+
+ return graph;
+ }
+ }
+
+ /**
+ * Provides a method to serialize an entire {@link org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph} into itself for GraphSON. This is useful when
+ * shipping small graphs around through Gremlin Server.
+ */
+ final static class TinkerModuleV2d0 extends TinkerPopJacksonModule {
+ public TinkerModuleV2d0() {
+ super("tinkergraph-2.0");
+ addSerializer(TinkerGraph.class, new TinkerGraphJacksonSerializer());
+ addDeserializer(TinkerGraph.class, new TinkerGraphJacksonDeserializer());
+ }
+
+ @Override
+ public Map<Class, String> getTypeDefinitions() {
+ return new HashMap<Class, String>(){{
+ put(TinkerGraph.class, "graph");
+ }};
+ }
+
+ @Override
+ public String getTypeNamespace() {
+ return "gremlin";
+ }
+ }
+
+ /**
+ * Serializes the graph into an edge list format. Edge list is a better choices than adjacency list (which is
+ * typically standard from the {@link org.apache.tinkerpop.gremlin.structure.io.GraphReader} and {@link org.apache.tinkerpop.gremlin.structure.io.GraphWriter} perspective) in this case because
+ * the use case for this isn't around massive graphs. The use case is for "small" subgraphs that are being
+ * shipped over the wire from Gremlin Server. Edge list format is a bit easier for non-JVM languages to work
+ * with as a format and doesn't require a cache for loading (as vertex labels are not serialized in adjacency
+ * list).
+ */
+ final static class TinkerGraphJacksonSerializer extends StdScalarSerializer<TinkerGraph> {
+
+ public TinkerGraphJacksonSerializer() {
+ super(TinkerGraph.class);
+ }
+
+ @Override
+ public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
+ throws IOException {
+ jsonGenerator.writeStartObject();
+ jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
+ jsonGenerator.writeStartArray();
+
+ final Iterator<Vertex> vertices = graph.vertices();
+ while (vertices.hasNext()) {
+ serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
+ }
+
+ jsonGenerator.writeEndArray();
+ jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
+ jsonGenerator.writeStartArray();
+
+ final Iterator<Edge> edges = graph.edges();
+ while (edges.hasNext()) {
+ serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
+ }
+
+ jsonGenerator.writeEndArray();
+ jsonGenerator.writeEndObject();
+ }
+ }
+
+ /**
+ * Deserializes the edge list format.
+ */
+ static class TinkerGraphJacksonDeserializer extends StdDeserializer<TinkerGraph> {
+ public TinkerGraphJacksonDeserializer() {
+ super(TinkerGraph.class);
+ }
+
+ @Override
+ public TinkerGraph deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ final TinkerGraph graph = TinkerGraph.open();
+
+ final List<? extends Edge> edges;
+ final List<? extends Vertex> vertices;
+
+ jsonParser.nextToken();
+ final Map<String, Object> graphData = deserializationContext.readValue(jsonParser, Map.class);
+ vertices = (List<DetachedVertex>) graphData.get(GraphSONTokens.VERTICES);
+ edges = (List<DetachedEdge>) graphData.get(GraphSONTokens.EDGES);
+
+
+ vertices.forEach(e -> {
+ if (e instanceof DetachedVertex) {
+ ((DetachedVertex)e).attach(Attachable.Method.getOrCreate(graph));
+ }
+ });
+
+ edges.forEach(e -> {
+ if (e instanceof DetachedEdge) {
+ ((DetachedEdge) e).attach(Attachable.Method.getOrCreate(graph));
+ }
+ });
+
+ return graph;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
index 86fc733..d07105b 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/IoDataGenerationTest.java
@@ -30,7 +30,9 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLWriter;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
import org.junit.BeforeClass;
@@ -49,7 +51,7 @@ import java.util.stream.IntStream;
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class IoDataGenerationTest {
- private static String tempPath;
+ private static final String tempPath;
static {
tempPath = TestHelper.makeTestDataPath(TinkerGraphTest.class, "tinkerpop-io").getPath() + File.separator;
@@ -195,6 +197,94 @@ public class IoDataGenerationTest {
os.close();
}
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphAsGraphSONV2d0NoTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-v2d0.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create()
+ .writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphAsGraphSOV2d0NNoTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-v2d0.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create()
+ .writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewGraphAsGraphSONV2d0NoTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-v2d0.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create()
+ .writeGraph(os, TinkerFactory.createTheCrew());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphNormalizedAsGraphSONV2d0() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-normalized-v2d0.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create()).create()
+ .writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphNormalizedAsGraphSONV2d0() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-normalized-v2d0.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create()).create()
+ .writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteClassicGraphAsGraphSONV2d0WithTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-v2d0-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).create()).create()
+ .writeGraph(os, TinkerFactory.createClassic());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteModernGraphAsGraphSONV2d0WithTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-v2d0-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).create()).create()
+ .writeGraph(os, TinkerFactory.createModern());
+ os.close();
+ }
+
+ /**
+ * No assertions. Just write out the graph for convenience.
+ */
+ @Test
+ public void shouldWriteCrewGraphAsGraphSONV2d0WithTypes() throws IOException {
+ final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-v2d0-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).create()).create()
+ .writeGraph(os, TinkerFactory.createTheCrew());
+ os.close();
+ }
+
@Test
public void shouldWriteSampleForGremlinServer() throws IOException {
final Graph g = TinkerGraph.open();
@@ -267,12 +357,27 @@ public class IoDataGenerationTest {
GraphSONWriter.build().mapper(GraphSONMapper.build().create()).create().writeGraph(os2, g);
os2.close();
- final OutputStream os3 = new FileOutputStream(tempPath + "grateful-dead.xml");
- GraphMLWriter.build().create().writeGraph(os3, g);
+ final OutputStream os3 = new FileOutputStream(tempPath + "grateful-dead-v2d0.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0)
+ .typeInfo(TypeInfo.NO_TYPES).create())
+ .create()
+ .writeGraph(os3, g);
os3.close();
- final OutputStream os4 = new FileOutputStream(tempPath + "grateful-dead-typed.json");
- GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create()).create().writeGraph(os4, g);
+ final OutputStream os4 = new FileOutputStream(tempPath + "grateful-dead.xml");
+ GraphMLWriter.build().create().writeGraph(os4, g);
os4.close();
+
+ final OutputStream os5 = new FileOutputStream(tempPath + "grateful-dead-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().embedTypes(true).create()).create().writeGraph(os5, g);
+ os5.close();
+
+ final OutputStream os6 = new FileOutputStream(tempPath + "grateful-dead-v2d0-typed.json");
+ GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0)
+ .typeInfo(TypeInfo.PARTIAL_TYPES).create())
+ .create()
+ .writeGraph(os6, g);
+ os6.close();
+
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/115eb3c7/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
new file mode 100644
index 0000000..907aaed
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphGraphSONSerializerV2d0Test.java
@@ -0,0 +1,557 @@
+/*
+ * 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.tinkergraph.structure;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import org.apache.tinkerpop.gremlin.process.traversal.util.Metrics;
+import org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
+import org.apache.tinkerpop.gremlin.structure.io.GraphWriter;
+import org.apache.tinkerpop.gremlin.structure.io.IoTest;
+import org.apache.tinkerpop.gremlin.structure.io.Mapper;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.time.Year;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+
+public class TinkerGraphGraphSONSerializerV2d0Test {
+
+ // As of TinkerPop 3.2.1 default for GraphSON 2.0 means types enabled.
+ Mapper defaultMapperV2d0 = GraphSONMapper.build()
+ .version(GraphSONVersion.V2_0)
+ .addRegistry(TinkerIoRegistryV2d0.getInstance())
+ .create();
+
+ Mapper noTypesMapperV2d0 = GraphSONMapper.build()
+ .version(GraphSONVersion.V2_0)
+ .typeInfo(TypeInfo.NO_TYPES)
+ .addRegistry(TinkerIoRegistryV2d0.getInstance())
+ .create();
+
+ /**
+ * Checks that the graph has been fully ser/deser with types.
+ */
+ @Test
+ public void shouldDeserializeGraphSONIntoTinkerGraphWithPartialTypes() throws IOException {
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+ TinkerGraph baseModern = TinkerFactory.createModern();
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, baseModern);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ IoTest.assertModernGraph(read, true, false);
+ }
+ }
+
+ /**
+ * Checks that the graph has been fully ser/deser without types.
+ */
+ @Test
+ public void shouldDeserializeGraphSONIntoTinkerGraphWithoutTypes() throws IOException {
+ GraphWriter writer = getWriter(noTypesMapperV2d0);
+ GraphReader reader = getReader(noTypesMapperV2d0);
+ TinkerGraph baseModern = TinkerFactory.createModern();
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, baseModern);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ IoTest.assertModernGraph(read, true, false);
+ }
+ }
+
+ /**
+ * Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props
+ */
+ @Test
+ public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException {
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ Graph sampleGraph1 = TinkerFactory.createModern();
+ Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID());
+ Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID());
+ v1.addEdge("hello", v2, T.id, 101L,
+ "uuid", UUID.randomUUID());
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, sampleGraph1);
+ String json = out.toString();
+
+ TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class);
+ assertTrue(approximateGraphsCheck(sampleGraph1, read));
+ }
+ }
+
+ /**
+ * Asserts the approximateGraphsChecks function fails when expected. Vertex ids.
+ */
+ @Test
+ public void shouldLooseTypesWithGraphSONNoTypesForVertexIds() throws IOException {
+ GraphWriter writer = getWriter(noTypesMapperV2d0);
+ GraphReader reader = getReader(noTypesMapperV2d0);
+ Graph sampleGraph1 = TinkerFactory.createModern();
+ sampleGraph1.addVertex(T.id, 100L, "name", "kevin");
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, sampleGraph1);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ // Should fail on deserialized vertex Id.
+ assertFalse(approximateGraphsCheck(sampleGraph1, read));
+ }
+ }
+
+ /**
+ * Asserts the approximateGraphsChecks function fails when expected. Vertex props.
+ */
+ @Test
+ public void shouldLooseTypesWithGraphSONNoTypesForVertexProps() throws IOException {
+ GraphWriter writer = getWriter(noTypesMapperV2d0);
+ GraphReader reader = getReader(noTypesMapperV2d0);
+ Graph sampleGraph1 = TinkerFactory.createModern();
+
+ sampleGraph1.addVertex(T.id, 100, "name", "kevin", "uuid", UUID.randomUUID());
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, sampleGraph1);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ // Should fail on deserialized vertex prop.
+ assertFalse(approximateGraphsCheck(sampleGraph1, read));
+ }
+ }
+
+ /**
+ * Asserts the approximateGraphsChecks function fails when expected. Edge ids.
+ */
+ @Test
+ public void shouldLooseTypesWithGraphSONNoTypesForEdgeIds() throws IOException {
+ GraphWriter writer = getWriter(noTypesMapperV2d0);
+ GraphReader reader = getReader(noTypesMapperV2d0);
+ Graph sampleGraph1 = TinkerFactory.createModern();
+ Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
+ v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101L);
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, sampleGraph1);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ // Should fail on deserialized edge Id.
+ assertFalse(approximateGraphsCheck(sampleGraph1, read));
+ }
+ }
+
+ /**
+ * Asserts the approximateGraphsChecks function fails when expected. Edge props.
+ */
+ @Test
+ public void shouldLooseTypesWithGraphSONNoTypesForEdgeProps() throws IOException {
+ GraphWriter writer = getWriter(noTypesMapperV2d0);
+ GraphReader reader = getReader(noTypesMapperV2d0);
+ Graph sampleGraph1 = TinkerFactory.createModern();
+
+ Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
+ v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101,
+ "uuid", UUID.randomUUID());
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, sampleGraph1);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ // Should fail on deserialized edge prop.
+ assertFalse(approximateGraphsCheck(sampleGraph1, read));
+ }
+ }
+
+ /**
+ * Those kinds of types are declared differently in the GraphSON type deserializer, check that all are handled
+ * properly.
+ */
+ @Test
+ public void shouldKeepTypesWhenDeserializingSerializedTinkerGraph() throws IOException {
+ TinkerGraph tg = TinkerGraph.open();
+
+ Vertex v = tg.addVertex("vertexTest");
+ UUID uuidProp = UUID.randomUUID();
+ Duration durationProp = Duration.ofHours(3);
+ Long longProp = 2L;
+ ByteBuffer byteBufferProp = ByteBuffer.wrap("testbb".getBytes());
+
+ // One Java util type natively supported by Jackson
+ v.property("uuid", uuidProp);
+ // One custom time type added by the GraphSON module
+ v.property("duration", durationProp);
+ // One Java native type not handled by JSON natively
+ v.property("long", longProp);
+ // One Java util type added by GraphSON
+ v.property("bytebuffer", byteBufferProp);
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeGraph(out, tg);
+ String json = out.toString();
+ TinkerGraph read = TinkerGraph.open();
+ reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
+ Vertex vRead = read.traversal().V().hasLabel("vertexTest").next();
+ assertEquals(vRead.property("uuid").value(), uuidProp);
+ assertEquals(vRead.property("duration").value(), durationProp);
+ assertEquals(vRead.property("long").value(), longProp);
+ assertEquals(vRead.property("bytebuffer").value(), byteBufferProp);
+ }
+ }
+
+
+ @Test
+ public void deserializersTestsVertex() {
+ TinkerGraph tg = TinkerGraph.open();
+
+ Vertex v = tg.addVertex("vertexTest");
+ v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50));
+ v.property("dead", LocalDateTime.of(1971, 1, 7, 20, 50));
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, v);
+ String json = out.toString();
+
+ // Object works, because there's a type in the payload now
+ // Vertex.class would work as well
+ // Anything else would not because we check the type in param here with what's in the JSON, for safety.
+ Vertex vRead = (Vertex)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ assertEquals(v, vRead);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsEdge() {
+ TinkerGraph tg = TinkerGraph.open();
+
+ Vertex v = tg.addVertex("vertexTest");
+ Vertex v2 = tg.addVertex("vertexTest");
+
+ Edge ed = v.addEdge("knows", v2, "time", LocalDateTime.now());
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, ed);
+ String json = out.toString();
+
+ // Object works, because there's a type in the payload now
+ // Edge.class would work as well
+ // Anything else would not because we check the type in param here with what's in the JSON, for safety.
+ Edge eRead = (Edge)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ assertEquals(ed, eRead);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsTinkerGraph() {
+ TinkerGraph tg = TinkerGraph.open();
+
+ Vertex v = tg.addVertex("vertexTest");
+ Vertex v2 = tg.addVertex("vertexTest");
+
+ Edge ed = v.addEdge("knows", v2);
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, tg);
+ String json = out.toString();
+
+ Graph gRead = (Graph)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ assertTrue(approximateGraphsCheck(tg, gRead));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsProperty() {
+ TinkerGraph tg = TinkerGraph.open();
+
+ Vertex v = tg.addVertex("vertexTest");
+ Vertex v2 = tg.addVertex("vertexTest");
+
+ Edge ed = v.addEdge("knows", v2);
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ Property prop = ed.property("since", Year.parse("1993"));
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, prop);
+ String json = out.toString();
+
+ Property pRead = (Property)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ //can't use equals here, because pRead is detached, its parent element has not been intentionally
+ //serialized and "equals()" checks that.
+ assertTrue(prop.key().equals(pRead.key()) && prop.value().equals(pRead.value()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsVertexProperty() {
+ TinkerGraph tg = TinkerGraph.open();
+
+ Vertex v = tg.addVertex("vertexTest");
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ VertexProperty prop = v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50));
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, prop);
+ String json = out.toString();
+
+ VertexProperty vPropRead = (VertexProperty)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ //only classes and ids are checked, that's ok, full vertex property ser/de
+ //is checked elsewhere.
+ assertEquals(prop, vPropRead);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsPath() {
+ TinkerGraph tg = TinkerFactory.createModern();
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ Path p = tg.traversal().V(1).as("a").has("name").as("b").
+ out("knows").out("created").as("c").
+ has("name", "ripple").values("name").as("d").
+ identity().as("e").path().next();
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, p);
+ String json = out.toString();
+
+ Path pathRead = (Path)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+
+ for (int i = 0; i < p.objects().size(); i++) {
+ Object o = p.objects().get(i);
+ Object oRead = pathRead.objects().get(i);
+ assertEquals(o, oRead);
+ }
+ for (int i = 0; i < p.labels().size(); i++) {
+ Set<String> o = p.labels().get(i);
+ Set<String> oRead = pathRead.labels().get(i);
+ assertEquals(o, oRead);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsMetrics() {
+ TinkerGraph tg = TinkerFactory.createModern();
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
+ out("knows").out("created").as("c").
+ has("name", "ripple").values("name").as("d").
+ identity().as("e").profile().next();
+
+ MutableMetrics m = new MutableMetrics(tm.getMetrics(0));
+ // making sure nested metrics are included in serde
+ m.addNested(new MutableMetrics(tm.getMetrics(1)));
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, m);
+ String json = out.toString();
+
+ Metrics metricsRead = (Metrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ // toString should be enough to compare Metrics
+ assertTrue(m.toString().equals(metricsRead.toString()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTestsTraversalMetrics() {
+ TinkerGraph tg = TinkerFactory.createModern();
+
+ GraphWriter writer = getWriter(defaultMapperV2d0);
+ GraphReader reader = getReader(defaultMapperV2d0);
+
+ TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
+ out("knows").out("created").as("c").
+ has("name", "ripple").values("name").as("d").
+ identity().as("e").profile().next();
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ writer.writeObject(out, tm);
+ String json = out.toString();
+
+ TraversalMetrics traversalMetricsRead = (TraversalMetrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ // toString should be enough to compare TraversalMetrics
+ assertTrue(tm.toString().equals(traversalMetricsRead.toString()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void deserializersTree() {
+ TinkerGraph tg = TinkerFactory.createModern();
+
+ GraphWriter writer = getWriter(noTypesMapperV2d0);
+ GraphReader reader = getReader(noTypesMapperV2d0);
+
+ Tree t = tg.traversal().V().out().out().tree().next();
+
+ try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ Vertex v = tg.traversal().V(1).next();
+ v.property("myUUIDprop", UUID.randomUUID());
+ writer.writeObject(out, v);
+
+
+// writer.writeObject(out, t);
+ String json = out.toString();
+
+ System.out.println("json = " + json);
+
+// Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
+ //Map's equals should check each component of the tree recursively
+ //on each it will call "equals()" which for Vertices will compare ids, which
+ //is ok. Complete vertex deser is checked elsewhere.
+// assertEquals(t, treeRead);
+
+
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private GraphWriter getWriter(Mapper paramMapper) {
+ return GraphSONWriter.build().mapper(paramMapper).create();
+ }
+
+ private GraphReader getReader(Mapper paramMapper) {
+ return GraphSONReader.build().mapper(paramMapper).create();
+ }
+
+ /**
+ * Checks sequentially vertices and egdes of both graphs. Will check sequentially Vertex IDs, Vertex Properties IDs
+ * and values and classes. Then same for edges. To use when serializing a Graph and deserializing the supposedly
+ * same Graph.
+ */
+ private boolean approximateGraphsCheck(Graph g1, Graph g2) {
+ Iterator<Vertex> itV = g1.vertices();
+ Iterator<Vertex> itVRead = g2.vertices();
+
+ while (itV.hasNext()) {
+ Vertex v = itV.next();
+ Vertex vRead = itVRead.next();
+
+ // Will only check IDs but that's 'good' enough.
+ if (!v.equals(vRead)) {
+ return false;
+ }
+
+ Iterator itVP = v.properties();
+ Iterator itVPRead = vRead.properties();
+ while (itVP.hasNext()) {
+ VertexProperty vp = (VertexProperty) itVP.next();
+ VertexProperty vpRead = (VertexProperty) itVPRead.next();
+ if (!vp.value().equals(vpRead.value())
+ || !vp.equals(vpRead)) {
+ return false;
+ }
+ }
+ }
+
+ Iterator<Edge> itE = g1.edges();
+ Iterator<Edge> itERead = g2.edges();
+
+ while (itE.hasNext()) {
+ Edge e = itE.next();
+ Edge eRead = itERead.next();
+ // Will only check IDs but that's good enough.
+ if (!e.equals(eRead)) {
+ return false;
+ }
+
+ Iterator itEP = e.properties();
+ Iterator itEPRead = eRead.properties();
+ while (itEP.hasNext()) {
+ Property ep = (Property) itEP.next();
+ Property epRead = (Property) itEPRead.next();
+ if (!ep.value().equals(epRead.value())
+ || !ep.equals(epRead)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}