use of org.apache.cassandra.utils.KeyGenerator.RandomStringGenerator in project cassandra by apache.
the class BitSetTest method compareBitSets.
/**
* Test bitsets in a "real-world" environment, i.e., bloom filters
*/
@Test
public void compareBitSets() {
BloomFilter bf2 = (BloomFilter) FilterFactory.getFilter(FilterTestHelper.ELEMENTS / 2, FilterTestHelper.MAX_FAILURE_RATE, false);
BloomFilter bf3 = (BloomFilter) FilterFactory.getFilter(FilterTestHelper.ELEMENTS / 2, FilterTestHelper.MAX_FAILURE_RATE, true);
RandomStringGenerator gen1 = new KeyGenerator.RandomStringGenerator(new Random().nextInt(), FilterTestHelper.ELEMENTS);
// make sure both bitsets are empty.
compare(bf2.bitset, bf3.bitset);
while (gen1.hasNext()) {
FilterKey key = FilterTestHelper.wrap(gen1.next());
bf2.add(key);
bf3.add(key);
}
compare(bf2.bitset, bf3.bitset);
}
use of org.apache.cassandra.utils.KeyGenerator.RandomStringGenerator in project cassandra by apache.
the class BloomFilterTest method compareCachedKey.
@Test
public void compareCachedKey() {
try (BloomFilter bf1 = (BloomFilter) FilterFactory.getFilter(FilterTestHelper.ELEMENTS / 2, FilterTestHelper.MAX_FAILURE_RATE);
BloomFilter bf2 = (BloomFilter) FilterFactory.getFilter(FilterTestHelper.ELEMENTS / 2, FilterTestHelper.MAX_FAILURE_RATE);
BloomFilter bf3 = (BloomFilter) FilterFactory.getFilter(FilterTestHelper.ELEMENTS / 2, FilterTestHelper.MAX_FAILURE_RATE)) {
RandomStringGenerator gen1 = new KeyGenerator.RandomStringGenerator(new Random().nextInt(), FilterTestHelper.ELEMENTS);
// make sure all bitsets are empty.
compare(bf1.bitset, bf2.bitset);
compare(bf1.bitset, bf3.bitset);
while (gen1.hasNext()) {
ByteBuffer key = gen1.next();
FilterKey cached = FilterTestHelper.wrapCached(key);
bf1.add(FilterTestHelper.wrap(key));
bf2.add(cached);
bf3.add(cached);
}
compare(bf1.bitset, bf2.bitset);
compare(bf1.bitset, bf3.bitset);
}
}
Aggregations