use of org.janusgraph.graphdb.relations.RelationIdentifier in project janusgraph by JanusGraph.
the class JanusGraphTest method testImplicitKey.
/**
* Test the correct application of {@link org.janusgraph.graphdb.types.system.ImplicitKey}
* to vertices, edges, and properties.
* <p>
* Additionally tests RelationIdentifier since this is closely related to ADJACENT and JANUSGRAPHID implicit keys.
*/
@Test
public void testImplicitKey() {
JanusGraphVertex v = graph.addVertex("name", "Dan"), u = graph.addVertex();
Edge e = v.addEdge("knows", u);
graph.tx().commit();
RelationIdentifier eid = (RelationIdentifier) e.id();
assertEquals(v.id(), v.value(ID_NAME));
assertEquals(eid, e.value(ID_NAME));
assertEquals("knows", e.value(LABEL_NAME));
assertEquals(BaseVertexLabel.DEFAULT_VERTEXLABEL.name(), v.value(LABEL_NAME));
assertCount(1, v.query().direction(Direction.BOTH).labels("knows").has(ID_NAME, eid).edges());
assertCount(0, v.query().direction(Direction.BOTH).labels("knows").has(ID_NAME, RelationIdentifier.get(new long[] { 4, 5, 6, 7 })).edges());
assertCount(1, v.query().direction(Direction.BOTH).labels("knows").has("~nid", eid.getRelationId()).edges());
assertCount(0, v.query().direction(Direction.BOTH).labels("knows").has("~nid", 110111).edges());
// Test edge retrieval
assertNotNull(getE(graph, eid));
assertEquals(eid, getE(graph, eid).id());
// Test adjacent constraint
assertEquals(1, v.query().direction(BOTH).has("~adjacent", u.id()).edgeCount());
assertCount(1, v.query().direction(BOTH).has("~adjacent", (int) getId(u)).edges());
try {
// Not a valid vertex
assertCount(0, v.query().direction(BOTH).has("~adjacent", 110111).edges());
fail();
} catch (IllegalArgumentException ignored) {
}
}
use of org.janusgraph.graphdb.relations.RelationIdentifier in project janusgraph by JanusGraph.
the class RelationIdentifierGraphBinarySerializerTest method assertRelationIdentifier.
private void assertRelationIdentifier(final GraphBinaryMessageSerializerV1 serializer, final RelationIdentifier relationIdentifier) throws IOException {
final ByteBuf serialized = serializer.serializeResponseAsBinary(ResponseMessage.build(UUID.randomUUID()).result(relationIdentifier).create(), allocator);
final ResponseMessage deserialized = serializer.deserializeResponse(serialized);
final RelationIdentifier actual = (RelationIdentifier) deserialized.getResult().getData();
assertEquals(actual.toString(), relationIdentifier.toString());
}
use of org.janusgraph.graphdb.relations.RelationIdentifier in project janusgraph by JanusGraph.
the class JanusGraphSerializerBaseIT method testEdgeSerialization.
@Test
public void testEdgeSerialization(TestInfo testInfo) {
GraphTraversalSource g = traversal();
RelationIdentifier inputId = (RelationIdentifier) g.addV(testInfo.getDisplayName()).as("from").addV(testInfo.getDisplayName()).addE(testInfo.getDisplayName()).from("from").id().next();
Edge edge = g.E(inputId).next();
RelationIdentifier outputId = (RelationIdentifier) edge.id();
assertEquals(inputId, outputId);
}
use of org.janusgraph.graphdb.relations.RelationIdentifier in project janusgraph by JanusGraph.
the class JanusGraphBlueprintsTransaction method edges.
@Override
public Iterator<Edge> edges(Object... edgeIds) {
if (edgeIds == null || edgeIds.length == 0)
return (Iterator) getEdges().iterator();
ElementUtils.verifyArgsMustBeEitherIdOrElement(edgeIds);
RelationIdentifier[] ids = new RelationIdentifier[edgeIds.length];
int pos = 0;
for (Object edgeId : edgeIds) {
RelationIdentifier id = ElementUtils.getEdgeId(edgeId);
if (id != null)
ids[pos++] = id;
}
if (pos == 0)
return Collections.emptyIterator();
if (pos < ids.length)
ids = Arrays.copyOf(ids, pos);
return (Iterator) getEdges(ids).iterator();
}
Aggregations