@Test
  public void loadExistingFilter() {
    int n = 1000;
    double p = 0.01;

    String name = "loadExistingTest";
    String testString = "simpletest";
    String testString2 = "simpletest2";

    cleanupRedis();
    BloomFilter<String> first = createFilter(name, n, p, true);
    first.add(testString);
    System.out.println(first.asString());

    BloomFilter<String> loaded = createFilter(name, n, p, false);

    System.out.println(loaded.asString());
    assertTrue(loaded.contains(testString));

    loaded.add(testString2);

    assertTrue(first.contains(testString2));

    cleanupRedis();
  }
  @Test
  public void overwriteExistingFilter() {
    int n = 1000;
    double p = 0.01;

    String name = "loadExistingTest";
    String testString = "simpletest";
    String testString2 = "simpletest2";

    cleanupRedis();
    BloomFilter<String> first = createFilter(name, n, p, true);
    first.add(testString);
    System.out.println(first.asString());

    BloomFilter<String> loaded = createFilter(name, n, p, true);
    System.out.println(loaded.asString());
    assertFalse(loaded.contains(testString));
    assertTrue(loaded.getExpectedElements() == n);
    assertEquals(first.getSize(), loaded.getSize());
    assertEquals(first.getHashes(), loaded.getHashes());
    assertEquals(0, Math.round(first.getEstimatedPopulation()));

    loaded.add(testString2);

    assertTrue(first.contains(testString2));

    cleanupRedis();
  }
  @Test
  public void testDatabase() throws Exception {
    final String filterName = "dbtest";
    BloomFilter<String> bfDb1 = createFilter(filterName, 10_000, 0.01, true);
    assertEquals(filterName, bfDb1.config().name());
    bfDb1.add("element1");
    assertTrue(bfDb1.contains("element1"));
    assertFalse(bfDb1.contains("element2"));

    BloomFilter<String> bfDb2 = createFilter(filterName, 10_000, 0.01, true, 1);
    assertEquals(filterName, bfDb2.config().name());
    assertFalse(bfDb2.contains("element1"));
    bfDb2.add("element2");
    assertTrue(bfDb2.contains("element2"));
    assertFalse(bfDb1.contains("element2"));
  }
 @Test
 public void testAsNormalFilter() {
   BloomFilter<String> first = createFilter("I_m_in_Redis", 10_000, 0.01, true);
   first.add("42");
   BloomFilter<String> second;
   if (filterTypes == FilterTypes.COUNTING)
     second = ((CountingBloomFilterRedis<String>) first).toMemoryFilter();
   else second = ((BloomFilterRedis<String>) first).toMemoryFilter();
   assertTrue(second.contains("42"));
 }
  @Test
  public void testPool() throws Exception {
    int n = 1000;
    double p = 0.01;
    BloomFilter<String> bf = createFilter("pooltest", 10_000, 0.01, true);
    RedisPool pool = bf.config().pool();

    FilterBuilder clonedConfig = bf.config().clone().name("pooltest-cloned");
    BloomFilter<String> filter =
        filterTypes == FilterTypes.COUNTING
            ? clonedConfig.buildCountingBloomFilter()
            : clonedConfig.buildBloomFilter();
    filter.add("filter");
    bf.add("bf");

    assertTrue(filter.contains("filter"));
    assertTrue(bf.contains("bf"));
    assertFalse(filter.contains("bf"));
    assertSame(pool, filter.config().pool());
  }
  @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 removeExistingFilter() {
    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);

    first.remove();

    if (filterTypes == FilterTypes.SENTINEL_CONFIG) {
      assert (!getSentinelJedis().getResource().exists(name));
    } else {
      assert (!getJedis().exists(name));
    }
  }