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())));
}
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())));
}
Aggregations