@Test public void bulkContains() { int n = 1000; double p = 0.01; String name = "loadExistingTest"; String testString = "simpletest"; cleanupRedis(); BloomFilter<String> first = createFilter(name, n, p, true); first.add(testString); List<String> samples = new ArrayList<>(); samples.add("one"); samples.add("two"); samples.add("three"); samples.add("four"); first.addAll(samples); samples.add("five"); samples.add("six"); samples.add(testString); List<Boolean> exists = first.contains(samples); assertTrue(exists.get(0)); // "one" assertTrue(exists.get(1)); // "two" assertTrue(exists.get(2)); // "three" assertTrue(exists.get(3)); // "four" assertTrue(!exists.get(4)); // "five" assertTrue(!exists.get(5)); // "six" assertTrue(exists.get(6)); // "simpleTest" ArrayList<String> testPositive = new ArrayList<>(); testPositive.add("one"); testPositive.add("two"); testPositive.add("three"); testPositive.add("four"); ArrayList<String> testNegative = new ArrayList<>(); testNegative.add("five"); testNegative.add("six"); assertTrue(first.containsAll(testPositive)); assertFalse(first.containsAll(testNegative)); }
@Test public void testSlaveReads() throws Exception { int n = 1000; double p = 0.01; BloomFilter<String> filter = createSlaveFilter("slaves", n, p, true); List<String> items = IntStream.range(0, 100) .mapToObj(i -> "obj" + String.valueOf(i)) .collect(Collectors.toList()); items.forEach(filter::add); // On localhost, there is no perceivable replication lag // Thread.sleep(10); assertTrue(filter.containsAll(items)); items.forEach(i -> assertTrue(filter.contains(i))); filter.remove(); }