Skip to content

Commit

Permalink
[TEST] create larger cuckoo filters for tests (elastic#46457)
Browse files Browse the repository at this point in the history
The cuckoofilters could be randomly created with too small of
capacity or precision, which means that they can only absorb a few
values before collisions start to make all filters look identical.

This increases the size of filters we generate (capacity >> than
the test cases) and lower fpp rate.
  • Loading branch information
polyfractal committed Sep 9, 2019
1 parent 88bed09 commit 8d17527
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class CuckooFilterTests extends AbstractWireSerializingTestCase<CuckooFil

@Override
protected CuckooFilter createTestInstance() {
CuckooFilter filter = new CuckooFilter(randomIntBetween(1, 100000),
((float)randomIntBetween(1, 50)) / 100.0, Randomness.get());
CuckooFilter filter = new CuckooFilter(randomIntBetween(10000, 100000),
((float)randomIntBetween(1, 20)) / 100.0, Randomness.get());

int num = randomIntBetween(0, 10);
for (int i = 0; i < num; i++) {
Expand All @@ -53,6 +53,15 @@ protected CuckooFilter mutateInstance(CuckooFilter instance) {
for (int i = 0; i < num; i++) {
newInstance.add(hash(randomLong()));
}
int attempts = 0;
while (newInstance.getCount() == instance.getCount() && attempts < 100) {
newInstance.add(hash(randomLong()));
attempts += 1;
}
if (newInstance.equals(instance)) {
fail("Unable to mutate filter enough to generate a different version. " +
"Are capacity/precision defaults too low?");
}
return newInstance;
}

Expand Down

0 comments on commit 8d17527

Please sign in to comment.