[
https://issues.apache.org/jira/browse/TINKERPOP-1036?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15053841#comment-15053841
]
ASF GitHub Bot commented on TINKERPOP-1036:
-------------------------------------------
Github user spmallette commented on a diff in the pull request:
https://github.com/apache/incubator-tinkerpop/pull/175#discussion_r47421541
--- Diff:
gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
---
@@ -249,6 +250,63 @@ public void shouldProperlyEncodeWithGraphML() throws
Exception {
// need to manually close the "g2" instance
graphProvider.clear(g2, configuration);
}
+
+ @Test
+ @FeatureRequirement(featureClass =
Graph.Features.EdgeFeatures.class, feature =
Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+ @FeatureRequirement(featureClass = EdgePropertyFeatures.class,
feature = FEATURE_STRING_VALUES)
+ @FeatureRequirement(featureClass =
Graph.Features.VertexFeatures.class, feature =
Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+ public void shouldReadWriteSelfLoopingEdges() throws Exception {
+ final Configuration sourceConf =
graphProvider.newGraphConfiguration("source", this.getClass(),
name.getMethodName(), null);
+ final Graph source = GraphFactory.open(sourceConf);
+ final Vertex v1 = source.addVertex();
+ final Vertex v2 = source.addVertex();
+ v1.addEdge("CONTROL", v2);
+ v1.addEdge("SELF-LOOP", v1);
+
+ final Configuration targetConf =
graphProvider.newGraphConfiguration("target", this.getClass(),
name.getMethodName(), null);
+ final Graph target = GraphFactory.open(targetConf);
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+
source.io(IoCore.graphml()).writer().create().writeGraph(os, source);
+ try (ByteArrayInputStream is = new
ByteArrayInputStream(os.toByteArray())) {
+
target.io(IoCore.graphml()).reader().create().readGraph(is, target);
+ }
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+
+ assertEquals(IteratorUtils.count(source.vertices()),
IteratorUtils.count(target.vertices()));
+ assertEquals(IteratorUtils.count(source.edges()),
IteratorUtils.count(target.vertices()));
--- End diff --
i bet this is why your test passes................. you are counting
"source" edges against "target" vertices. those counts happen to match. the
assert is bad. and yeah, now i see where the self-relation is only written on
"inE" which is why it won't get read on "outE". Given that we know your
asserts are off, please double check gryo/graphml now and be sure those are
passing too.
as for why, it doesn't write the edge for both "outE" and "inE" - it just
seems to be the way the `StarGraph` is implemented. I sense that we call
`addEdge()` on `StarGraph` which in turn chooses to call `addOutEdge` so it
only gets added as an "out" edge. Not sure what the implications of that are.
@okram not sure if we need to do anything with that in `StarGraph` but
something to be aware of with self-relations.
> Support self-looping edges in IO
> --------------------------------
>
> Key: TINKERPOP-1036
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1036
> Project: TinkerPop
> Issue Type: Bug
> Components: io
> Affects Versions: 3.1.0-incubating
> Reporter: stephen mallette
> Assignee: stephen mallette
> Fix For: 3.1.1-incubating
>
>
> Seems like GraphSON is having trouble with self-loops. Not sure about other
> IO at this time.
> {code}
> gremlin> a = TinkerGraph.open()
> ==>tinkergraph[vertices:0 edges:0]
> gremlin> v1 = a.addVertex()
> ==>v[0]
> gremlin> v2 = a.addVertex()
> ==>v[1]
> gremlin> control = v1.addEdge("CONTROL", v2)
> ==>e[2][0-CONTROL->1]
> gremlin> selfLoop = v1.addEdge("SELF-LOOP", v1)
> ==>e[3][0-SELF-LOOP->0]
> gremlin> a.io(IoCore.graphson()).writeGraph("test.gson")
> ==>null
> gremlin> b = TinkerGraph.open()
> ==>tinkergraph[vertices:0 edges:0]
> gremlin> b.io(IoCore.graphson()).readGraph("test.gson")
> ==>null
> gremlin> b.traversal().E()
> ==>e[2][0-CONTROL->1]
> {code}
> with graphson of:
> {code}
> {"id":0,"label":"vertex","inE":{"SELF-LOOP":[{"id":3,"outV":0}]},"outE":{"CONTROL":[{"id":2,"inV":1}]}}
> {"id":1,"label":"vertex","inE":{"CONTROL":[{"id":2,"outV":0}]}}
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)