for (int i = 0; i < 256; i++) fqns.add(Fqn.fromString("/" + Integer.toString(i, 36)));
doTest(fqns);
}
private void doTest(List<Fqn> fqns) {
LockContainer container = new ReentrantStripedLockContainer(512, AnyEquivalence.getInstance());
Map<Lock, Integer> distribution = new HashMap<Lock, Integer>();
for (Fqn f : fqns) {
NodeKey dataKey = new NodeKey(f, NodeKey.Type.DATA);
NodeKey structureKey = new NodeKey(f, NodeKey.Type.STRUCTURE);
addToDistribution(container.getLock(dataKey), distribution);
addToDistribution(container.getLock(structureKey), distribution);
}
System.out.println("Distribution: " + distribution);
assert distribution.size() <= container.size() : "Cannot have more locks than the container size!";
// assume at least a 2/3rd even distribution
// but also consider that data snd structure keys would typically provide the same hash code
// so we need to double this
assert distribution.size() * 1.5 * 2 >= container.size() : "Poorly distributed! Distribution size is just " + distribution.size() + " and there are " + container.size() + " shared locks";
}