Search in sources :

Example 1 with BloomFilter

use of org.apache.accumulo.core.bloomfilter.BloomFilter in project Gaffer by gchq.

the class FilterWritabilityTest method shouldAcceptValidFilter.

@Test
public void shouldAcceptValidFilter() {
    // Given
    final BloomFilter filter = new BloomFilter(100, 5, Hash.MURMUR_HASH);
    filter.add(new Key("ABC".getBytes()));
    filter.add(new Key("DEF".getBytes()));
    // Then
    assertTrue(filter.membershipTest(new Key("ABC".getBytes())));
    assertTrue(filter.membershipTest(new Key("DEF".getBytes())));
    assertFalse(filter.membershipTest(new Key("lkjhgfdsa".getBytes())));
}
Also used : BloomFilter(org.apache.accumulo.core.bloomfilter.BloomFilter) Key(org.apache.hadoop.util.bloom.Key) Test(org.junit.jupiter.api.Test)

Example 2 with BloomFilter

use of org.apache.accumulo.core.bloomfilter.BloomFilter in project Gaffer by gchq.

the class FilterWritabilityTest method shouldWriteAndReadFilter.

@Test
public void shouldWriteAndReadFilter() throws IOException {
    // Given
    final BloomFilter filter = new BloomFilter(100, 5, Hash.MURMUR_HASH);
    filter.add(new Key("ABC".getBytes()));
    filter.add(new Key("DEF".getBytes()));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final DataOutputStream out = new DataOutputStream(baos);
    filter.write(out);
    String x = new String(baos.toByteArray(), AccumuloStoreConstants.BLOOM_FILTER_CHARSET);
    final ByteArrayInputStream bais = new ByteArrayInputStream(x.getBytes(AccumuloStoreConstants.BLOOM_FILTER_CHARSET));
    // When
    final DataInputStream in = new DataInputStream(bais);
    final BloomFilter read = new BloomFilter();
    read.readFields(in);
    // Then
    assertTrue(read.membershipTest(new Key("ABC".getBytes())));
    assertTrue(read.membershipTest(new Key("DEF".getBytes())));
    assertFalse(read.membershipTest(new Key("lkjhgfdsa".getBytes())));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) BloomFilter(org.apache.accumulo.core.bloomfilter.BloomFilter) Key(org.apache.hadoop.util.bloom.Key) Test(org.junit.jupiter.api.Test)

Aggregations

BloomFilter (org.apache.accumulo.core.bloomfilter.BloomFilter)2 Key (org.apache.hadoop.util.bloom.Key)2 Test (org.junit.jupiter.api.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1