Search in sources :

Example 21 with IntHashSet

use of com.carrotsearch.hppc.IntHashSet in project janusgraph by JanusGraph.

the class JanusGraphPartitionGraphTest method testPartitionSpread.

private void testPartitionSpread(boolean flush, boolean batchCommit) {
    Object[] options = { option(GraphDatabaseConfiguration.IDS_FLUSH), flush };
    clopen(options);
    int[] groupDegrees = { 10, 15, 10, 17, 10, 4, 7, 20, 11 };
    int numVertices = setupGroupClusters(groupDegrees, batchCommit ? CommitMode.BATCH : CommitMode.PER_VERTEX);
    // to track the "spread" of partition ids
    IntSet partitionIds = new IntHashSet(numVertices);
    for (int i = 0; i < groupDegrees.length; i++) {
        JanusGraphVertex g = getOnlyVertex(tx.query().has("groupid", "group" + i));
        assertCount(groupDegrees[i], g.edges(Direction.OUT, "contain"));
        assertCount(groupDegrees[i], g.edges(Direction.IN, "member"));
        assertCount(groupDegrees[i], g.query().direction(Direction.OUT).edges());
        assertCount(groupDegrees[i], g.query().direction(Direction.IN).edges());
        assertCount(groupDegrees[i] * 2, g.query().edges());
        for (Object o : g.query().direction(Direction.IN).labels("member").vertices()) {
            JanusGraphVertex v = (JanusGraphVertex) o;
            int pid = getPartitionID(v);
            partitionIds.add(pid);
            assertEquals(g, getOnlyElement(v.query().direction(Direction.OUT).labels("member").vertices()));
            VertexList vertexList = v.query().direction(Direction.IN).labels("contain").vertexIds();
            assertEquals(1, vertexList.size());
            assertEquals(pid, idManager.getPartitionId(vertexList.getID(0)));
            assertEquals(g, vertexList.get(0));
        }
    }
    if (flush || !batchCommit) {
        // In these cases we would expect significant spread across partitions
        // This is a probabilistic test that might fail
        assertTrue(partitionIds.size() > numPartitions / 2);
    } else {
        // No spread in this case
        assertEquals(1, partitionIds.size());
    }
}
Also used : IntSet(com.carrotsearch.hppc.IntSet) IntHashSet(com.carrotsearch.hppc.IntHashSet)

Aggregations

IntHashSet (com.carrotsearch.hppc.IntHashSet)21 IntSet (com.carrotsearch.hppc.IntSet)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional (java.util.Optional)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 MetaData (org.elasticsearch.cluster.metadata.MetaData)3 SnapshotRecoverySource (org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource)3 Test (org.junit.Test)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 IntContainer (com.carrotsearch.hppc.IntContainer)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2