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());
}
}
Aggregations