Search in sources :

Example 6 with RelationIdentifier

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) {
    }
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 7 with RelationIdentifier

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());
}
Also used : ResponseMessage(org.apache.tinkerpop.gremlin.driver.message.ResponseMessage) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ByteBuf(io.netty.buffer.ByteBuf)

Example 8 with RelationIdentifier

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);
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.jupiter.api.Test)

Example 9 with RelationIdentifier

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();
}
Also used : Iterator(java.util.Iterator) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier)

Aggregations

RelationIdentifier (org.janusgraph.graphdb.relations.RelationIdentifier)9 Test (org.junit.jupiter.api.Test)3 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)2 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 LongArrayList (com.carrotsearch.hppc.LongArrayList)1 Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 Predicates (com.google.common.base.Predicates)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalCause (com.google.common.cache.RemovalCause)1 RemovalListener (com.google.common.cache.RemovalListener)1 HashMultimap (com.google.common.collect.HashMultimap)1 Iterables (com.google.common.collect.Iterables)1 Maps (com.google.common.collect.Maps)1 SetMultimap (com.google.common.collect.SetMultimap)1 ByteBuf (io.netty.buffer.ByteBuf)1