Search in sources :

Example 1 with RandomStringGenerator

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);
}
Also used : RandomStringGenerator(org.apache.cassandra.utils.KeyGenerator.RandomStringGenerator) Random(java.util.Random) FilterKey(org.apache.cassandra.utils.IFilter.FilterKey) Test(org.junit.Test)

Example 2 with RandomStringGenerator

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);
    }
}
Also used : RandomStringGenerator(org.apache.cassandra.utils.KeyGenerator.RandomStringGenerator) Random(java.util.Random) ByteBuffer(java.nio.ByteBuffer) FilterKey(org.apache.cassandra.utils.IFilter.FilterKey)

Aggregations

Random (java.util.Random)2 FilterKey (org.apache.cassandra.utils.IFilter.FilterKey)2 RandomStringGenerator (org.apache.cassandra.utils.KeyGenerator.RandomStringGenerator)2 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1