Search in sources :

Example 1 with VertexLongList

use of org.janusgraph.graphdb.query.vertex.VertexLongList in project janusgraph by JanusGraph.

the class VertexListTest method testLists.

@Test
public void testLists() {
    int num = 13;
    JanusGraph g = JanusGraphFactory.open("inmemory");
    StandardJanusGraphTx tx = (StandardJanusGraphTx) g.newTransaction();
    VertexLongList vll = new VertexLongList(tx);
    VertexArrayList val = new VertexArrayList(tx);
    for (int i = 0; i < num; i++) {
        JanusGraphVertex v = tx.addVertex();
        vll.add(v);
        val.add(v);
    }
    assertEquals(num, Iterables.size(vll));
    assertEquals(num, Iterables.size(val));
    vll.sort();
    val.sort();
    assertTrue(vll.isSorted());
    assertTrue(val.isSorted());
    for (Iterable<JanusGraphVertex> iterable : new Iterable[] { val, vll }) {
        Iterator<JanusGraphVertex> iterator = iterable.iterator();
        JanusGraphVertex previous = null;
        for (int i = 0; i < num; i++) {
            JanusGraphVertex next = iterator.next();
            if (previous != null)
                assertTrue(previous.longId() < next.longId());
            previous = next;
        }
        try {
            iterator.next();
            fail();
        } catch (NoSuchElementException ignored) {
        }
    }
    tx.commit();
    g.close();
}
Also used : VertexLongList(org.janusgraph.graphdb.query.vertex.VertexLongList) VertexArrayList(org.janusgraph.graphdb.query.vertex.VertexArrayList) JanusGraph(org.janusgraph.core.JanusGraph) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)1 JanusGraph (org.janusgraph.core.JanusGraph)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 VertexArrayList (org.janusgraph.graphdb.query.vertex.VertexArrayList)1 VertexLongList (org.janusgraph.graphdb.query.vertex.VertexLongList)1 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)1 Test (org.junit.Test)1