org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GryoLiteMessageSerializerV1d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldSerializeEdge() throws Exception { final Graph g = TinkerGraph.open(); final Vertex v1 = g.addVertex(); final Vertex v2 = g.addVertex(); final Edge e = v1.addEdge("test", v2); e.property("abc", 123); final Iterable<Edge> iterable = IteratorUtils.list(g.edges()); final ResponseMessage response = convertBinary(iterable); assertCommon(response); final List<ReferenceEdge> edgeList = (List<ReferenceEdge>) response.getResult().getData(); assertEquals(1, edgeList.size()); final ReferenceEdge deserializedEdge = edgeList.get(0); assertEquals(e.id(), deserializedEdge.id()); assertEquals("test", deserializedEdge.label()); assertEquals(0, IteratorUtils.count(deserializedEdge.properties())); assertEquals(v1.id(), deserializedEdge.outVertex().id()); assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.outVertex().label()); assertEquals(v2.id(), deserializedEdge.inVertex().id()); assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.inVertex().label()); }
Example #2
Source File: EdgeSerializer.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override protected Edge readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException { final Object id = context.read(buffer); final String label = context.readValue(buffer, String.class, false); final ReferenceVertex inV = new ReferenceVertex(context.read(buffer), context.readValue(buffer, String.class, false)); final ReferenceVertex outV = new ReferenceVertex(context.read(buffer), context.readValue(buffer, String.class, false)); // discard the parent vertex - we only send "references so this should always be null, but will we change our // minds someday???? context.read(buffer); // discard the properties - as we only send "references" this should always be null, but will we change our // minds some day???? context.read(buffer); return new ReferenceEdge(id, label, inV, outV); }
Example #3
Source File: ActGraphTest.java From act-platform with ISC License | 5 votes |
@Test public void testIterateEdgesWithUuidIdSupportUsingReferenceEdge() { Edge edge1 = createEdge(); Edge edge2 = getActGraph().edges(ReferenceFactory.detach(edge1)).next(); assertEquals(edge1.id(), edge2.id()); assertFalse(edge2 instanceof ReferenceEdge); }
Example #4
Source File: ActGraphTest.java From act-platform with ISC License | 5 votes |
@Test public void testIterateEdgesWithUuidIdSupportUsingReferenceEdge() { Edge edge1 = createEdge(); Edge edge2 = getActGraph().edges(ReferenceFactory.detach(edge1)).next(); assertEquals(edge1.id(), edge2.id()); assertFalse(edge2 instanceof ReferenceEdge); }
Example #5
Source File: HaltedTraverserStrategyTest.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Test public void shouldReturnReferenceElements() { final Graph graph = TinkerFactory.createModern(); GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.reference()); g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass())); g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass())); g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass())); g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass())); g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass())); g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass())); g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); // the default should be reference elements g = graph.traversal().withComputer(); g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass())); g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass())); g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass())); g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass())); g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass())); g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass())); g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); // should handle nested collections g.V().out().fold().next().forEach(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); }
Example #6
Source File: TypeSerializerFailureTests.java From tinkerpop with Apache License 2.0 | 5 votes |
@Parameterized.Parameters(name = "Value={0}") public static Collection input() { final Bytecode.Binding b = new Bytecode.Binding(null, "b"); final ReferenceVertex vertex = new ReferenceVertex("a vertex", null); final Bytecode bytecode = new Bytecode(); bytecode.addStep(null); final BulkSet<Object> bulkSet = new BulkSet<>(); bulkSet.add(vertex, 1L); final MutableMetrics metrics = new MutableMetrics("a metric", null); final Tree<Vertex> tree = new Tree<>(); tree.put(vertex, null); // Provide instances that are malformed for serialization to fail return Arrays.asList( b, vertex, Collections.singletonMap("one", b), bulkSet, bytecode, Collections.singletonList(vertex), new ReferenceEdge("an edge", null, vertex, vertex), Lambda.supplier(null), metrics, new DefaultTraversalMetrics(1L, Collections.singletonList(metrics)), new DefaultRemoteTraverser<>(new Object(), 1L), tree, new ReferenceVertexProperty<>("a prop", null, "value"), new InvalidPath() ); }
Example #7
Source File: GryoClassResolverV1d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Class coerceType(final Class clazz) { // force all instances of Vertex, Edge, VertexProperty, etc. to their respective interface final Class type; if (!ReferenceVertex.class.isAssignableFrom(clazz) && !DetachedVertex.class.isAssignableFrom(clazz) && Vertex.class.isAssignableFrom(clazz)) type = Vertex.class; else if (!ReferenceEdge.class.isAssignableFrom(clazz) && !DetachedEdge.class.isAssignableFrom(clazz) && Edge.class.isAssignableFrom(clazz)) type = Edge.class; else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz)) type = VertexProperty.class; else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && !ReferenceVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz)) type = Property.class; else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz)) type = Path.class; else if (Lambda.class.isAssignableFrom(clazz)) type = Lambda.class; else if (ByteBuffer.class.isAssignableFrom(clazz)) type = ByteBuffer.class; else if (Class.class.isAssignableFrom(clazz)) type = Class.class; else if (InetAddress.class.isAssignableFrom(clazz)) type = InetAddress.class; else if (ConnectiveP.class.isAssignableFrom(clazz)) type = P.class; else type = clazz; return type; }
Example #8
Source File: GryoClassResolverV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Class coerceType(final Class clazz) { // force all instances of Vertex, Edge, VertexProperty, etc. to their respective interface final Class type; if (!ReferenceVertex.class.isAssignableFrom(clazz) && !DetachedVertex.class.isAssignableFrom(clazz) && Vertex.class.isAssignableFrom(clazz)) type = Vertex.class; else if (!ReferenceEdge.class.isAssignableFrom(clazz) && !DetachedEdge.class.isAssignableFrom(clazz) && Edge.class.isAssignableFrom(clazz)) type = Edge.class; else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz)) type = VertexProperty.class; else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && !ReferenceVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz)) type = Property.class; else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz)) type = Path.class; else if (Lambda.class.isAssignableFrom(clazz)) type = Lambda.class; else if (ByteBuffer.class.isAssignableFrom(clazz)) type = ByteBuffer.class; else if (Class.class.isAssignableFrom(clazz)) type = Class.class; else if (InetAddress.class.isAssignableFrom(clazz)) type = InetAddress.class; else if (ConnectiveP.class.isAssignableFrom(clazz)) type = P.class; else if (Metrics.class.isAssignableFrom(clazz)) type = Metrics.class; else if (TraversalMetrics.class.isAssignableFrom(clazz)) type = TraversalMetrics.class; else type = clazz; return type; }
Example #9
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferencePropertyOfEdgeWhenChanged() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v); final String label = e.label(); final Object inId = v.id(); final Object outId = v.id(); e.property("to-change", "no!"); final MutationListener listener = new AbstractMutationListener() { @Override public void edgePropertyChanged(final Edge element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals(label, element.label()); assertEquals(inId, element.inVertex().id()); assertEquals(outId, element.outVertex().id()); assertEquals("no!", oldValue.value()); assertEquals("to-change", oldValue.key()); assertEquals("yay!", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.E(e).property("to-change","yay!").iterate(); tryCommit(graph); assertEquals(1, IteratorUtils.count(g.E(e).properties())); assertThat(triggered.get(), is(true)); }
Example #10
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferencePropertyOfEdgeWhenNew() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v); final String label = e.label(); final Object inId = v.id(); final Object outId = v.id(); e.property("to-change", "no!"); final MutationListener listener = new AbstractMutationListener() { @Override public void edgePropertyChanged(final Edge element, final Property oldValue, final Object setValue) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals(label, element.label()); assertEquals(inId, element.inVertex().id()); assertEquals(outId, element.outVertex().id()); assertThat(oldValue, instanceOf(KeyedProperty.class)); assertEquals("new", oldValue.key()); assertEquals("yay!", setValue); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.E(e).property("new","yay!").iterate(); tryCommit(graph); assertEquals(2, IteratorUtils.count(g.E(e).properties())); assertThat(triggered.get(), is(true)); }
Example #11
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferenceEdgeWhenRemoved() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Edge e = v.addEdge("self", v, "dropped", "yay!"); final String label = e.label(); final Object inId = v.id(); final Object outId = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void edgeRemoved(final Edge element) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals(label, element.label()); assertEquals(inId, element.inVertex().id()); assertEquals(outId, element.outVertex().id()); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.E(e).drop().iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 0); assertThat(triggered.get(), is(true)); }
Example #12
Source File: EventStrategyProcessTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldReferenceEdgeWhenAdded() { final AtomicBoolean triggered = new AtomicBoolean(false); final Vertex v = graph.addVertex(); final Object id = v.id(); final MutationListener listener = new AbstractMutationListener() { @Override public void edgeAdded(final Edge element) { assertThat(element, instanceOf(ReferenceEdge.class)); assertEquals("self", element.label()); assertEquals(id, element.inVertex().id()); assertEquals(id, element.outVertex().id()); assertThat(element.properties().hasNext(), is(false)); triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).as("a").addE("self").property("here", "there").from("a").to("a").iterate(); tryCommit(graph); assertVertexEdgeCounts(graph, 1, 1); assertThat(triggered.get(), is(true)); }
Example #13
Source File: HaltedTraverserStrategyTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldReturnReferenceElements() { final Graph graph = TinkerFactory.createModern(); GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.reference()); g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass())); g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass())); g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass())); g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass())); g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass())); g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass())); g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); // the default should be reference elements g = graph.traversal().withComputer(); g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass())); g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass())); g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass())); g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass())); g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass())); g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass())); g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); // should handle nested collections g.V().out().fold().next().forEach(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass())); }
Example #14
Source File: GremlinResultSetIntegrateTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Test public void shouldHandleEdgeResult() throws Exception { final ResultSet results = client.submit("gmodern.E().next()"); final Edge e = results.all().get().get(0).getEdge(); assertThat(e, instanceOf(ReferenceEdge.class)); }