Tests: Speed up CopyOnWriteHash(Map|Set)Tests

These tests create artificial hash collisions in order to make sure that they
can be resolved correctly. But this also makes the tests very slow if there
are too many collisions because insertions/deletions become linear in such
cases. The tests have been modified to not do too many iterations when
collisions are likely.

Close #10442
This commit is contained in:
Adrien Grand 2015-04-07 13:34:08 +02:00
parent 1d56502e52
commit 37f3351b58
2 changed files with 6 additions and 2 deletions

View File

@ -55,9 +55,11 @@ public class CopyOnWriteHashMapTests extends ElasticsearchTestCase {
public void testDuel() { public void testDuel() {
final int iters = scaledRandomIntBetween(2, 5); final int iters = scaledRandomIntBetween(2, 5);
for (int iter = 0; iter < iters; ++iter) { for (int iter = 0; iter < iters; ++iter) {
final int numOps = randomInt(5000);
final int valueBits = randomIntBetween(1, 30); final int valueBits = randomIntBetween(1, 30);
final int hashBits = randomInt(valueBits); final int hashBits = randomInt(valueBits);
// we compute the total number of ops based on the bits of the hash
// since the test is much heavier when few bits are used for the hash
final int numOps = randomInt(10 + hashBits * 100);
Map<O, Integer> ref = new HashMap<>(); Map<O, Integer> ref = new HashMap<>();
CopyOnWriteHashMap<O, Integer> map = new CopyOnWriteHashMap<>(); CopyOnWriteHashMap<O, Integer> map = new CopyOnWriteHashMap<>();

View File

@ -55,9 +55,11 @@ public class CopyOnWriteHashSetTests extends ElasticsearchTestCase {
public void testDuel() { public void testDuel() {
final int iters = scaledRandomIntBetween(2, 5); final int iters = scaledRandomIntBetween(2, 5);
for (int iter = 0; iter < iters; ++iter) { for (int iter = 0; iter < iters; ++iter) {
final int numOps = randomInt(5000);
final int valueBits = randomIntBetween(1, 30); final int valueBits = randomIntBetween(1, 30);
final int hashBits = randomInt(valueBits); final int hashBits = randomInt(valueBits);
// we compute the total number of ops based on the bits of the hash
// since the test is much heavier when few bits are used for the hash
final int numOps = randomInt(10 + hashBits * 100);
Set<O> ref = new HashSet<>(); Set<O> ref = new HashSet<>();
CopyOnWriteHashSet<O> set = new CopyOnWriteHashSet<>(); CopyOnWriteHashSet<O> set = new CopyOnWriteHashSet<>();