for (int attempt = 0; attempt < attemptsPerThread; attempt++) {
int offset = random.nextInt(numPartitions);
int partition = partitions[offset];
long id = idPools[offset].nextID();
assertTrue(id < Integer.MAX_VALUE);
IntSet idset = ids[offset];
synchronized (idset) {
assertFalse(idset.contains((int) id));
idset.add((int) id);
}
}
}
});
threads[i].run();
}
for (int i = 0; i < numThreads; i++) threads[i].join();
for (int i = 0; i < idPools.length; i++) idPools[i].close();
//Verify consecutive id assignment
for (int i = 0; i < ids.length; i++) {
IntSet set = ids[i];
int max = 0;
int[] all = set.getAll();
for (int j=0;j<all.length;j++) if (all[j]>max) max=all[j];
for (int j=1;j<=max;j++) assertTrue(set.contains(j));
}
}