/** Verify that the filter allows events through if no properties are set. */
 public void testUnspecifiedProperties() throws Exception {
   ReplicateFilter rf = new ReplicateFilter();
   rf.setTungstenSchema("tungsten_foo");
   filterHelper.setFilter(rf);
   verifyStmtAccept(filterHelper, 0, null, "insert into bar(val) values(1)");
   filterHelper.done();
 }
  /** Verify that we allow operations on schemas including wildcard substitutions. */
  public void testSchemasAccepted() throws ReplicatorException, InterruptedException {
    // Configure the filter to allow databases including wild cards.
    ReplicateFilter rf = new ReplicateFilter();
    rf.setTungstenSchema("tungsten_foo");
    rf.setDo("foo,ba?, foobar*");
    filterHelper.setFilter(rf);

    // Confirm that the following commands are accepted if the default
    // database is foo.
    verifyStmtAccept(filterHelper, 0, null, "create database foo");
    verifyStmtAccept(filterHelper, 1, null, "drop database bar");
    verifyStmtAccept(filterHelper, 2, null, "insert into foobar1.x1 values(1,2,3)");
    verifyStmtAccept(filterHelper, 3, null, "update test_tab set age=32 where id=1");

    // Just for calibration ensure we ignore a non-matching schema.
    verifyStmtIgnore(filterHelper, 4, null, "insert into test.tab values(52,1)");

    // All done.
    filterHelper.done();
  }
  /** Verify that we always accept the Tungsten catalog even if it is explicitly ignored. */
  public void testTungstenCatalogAccept() throws ReplicatorException, InterruptedException {
    // Configure the filter to allow databases including wild cards.
    ReplicateFilter rf = new ReplicateFilter();
    rf.setTungstenSchema("tungsten_foo");
    rf.setIgnore("tungsten_foo");
    filterHelper.setFilter(rf);

    // Confirm that the following commands are accepted.
    verifyStmtAccept(
        filterHelper, 0, "bar", "delete from tungsten_foo.trep_commit_seqno where task_id=9");
    verifyRowAccept(
        filterHelper,
        1,
        "tungsten_foo",
        "trep_commit_seqno",
        new String[] {"task_id"},
        new Object[] {0});

    // All done.
    filterHelper.done();
  }
  /** Verify that we handle cases where a subset of databases and/or tables is ignored. */
  public void testSchemasIgnoreSubset() throws ReplicatorException, InterruptedException {
    // Configure the filter to allow databases including wild cards.
    ReplicateFilter rf = new ReplicateFilter();
    rf.setTungstenSchema("tungsten_foo");
    rf.setDo("foobar?,bar*,foo");
    rf.setIgnore("foo.test,foobar2,bar23*");
    filterHelper.setFilter(rf);

    // Confirm that the following commands are accepted if the default
    // database is foo.
    verifyStmtAccept(filterHelper, 0, null, "create database foobar1");
    verifyStmtAccept(filterHelper, 1, "foo", "drop table foo.test2");
    verifyStmtAccept(filterHelper, 2, "foo", "delete from bar2.test where id=2");

    // Confirm that we ignore subset values.
    verifyStmtIgnore(filterHelper, 3, "foo", "delete from foo.test where id=2");
    verifyStmtIgnore(filterHelper, 4, "foo", "create table foobar2.foobar1 (id int)");
    verifyStmtIgnore(filterHelper, 5, "foo", "drop database bar234");

    // All done.
    filterHelper.done();
  }
  /**
   * Verify that we handle table acceptance including cases where the table names are wildcarded.
   */
  public void testTableAccept() throws ReplicatorException, InterruptedException {
    // Configure the filter to allow databases including wild cards.
    ReplicateFilter rf = new ReplicateFilter();
    rf.setTungstenSchema("tungsten_foo");
    rf.setDo("foo.*,bar.test1,bar.wild*,bar.w?");
    filterHelper.setFilter(rf);

    // Confirm that the following commands are accepted.
    verifyStmtAccept(filterHelper, 0, "bar", "insert into foo.test values(1)");
    verifyStmtAccept(filterHelper, 1, "foo", "delete from test1 where id=1");
    verifyStmtAccept(filterHelper, 2, "bar", "insert into wild1 values(1)");
    verifyStmtAccept(filterHelper, 3, "bar", "update w2 set age=29");

    // Confirm that the following are ignored, because they do not trigger
    // acceptance.
    verifyStmtIgnore(filterHelper, 4, null, "create database foo");
    verifyStmtIgnore(filterHelper, 5, "bar", "insert into test2 values(1)");
    verifyStmtIgnore(filterHelper, 6, "bar", "create table will1 (id int)");
    verifyStmtIgnore(filterHelper, 7, "bar", "delete from w22");

    // All done.
    filterHelper.done();
  }
  /** Verify that we accept and ignore databases appropriately when using row updates. */
  public void testRowHandling() throws ReplicatorException, InterruptedException {
    // Configure the filter to allow databases including wild cards.
    ReplicateFilter rf = new ReplicateFilter();
    rf.setTungstenSchema("tungsten_foo");
    rf.setDo("foobar?,bar*,foo");
    rf.setIgnore("foo.test,foobar2,bar23*");
    filterHelper.setFilter(rf);

    // Verify accepted events.
    String names[] = {"id"};
    Long values[] = {new Long(99)};
    verifyRowAccept(filterHelper, 0, "foobar1", "foobar2", names, values);
    verifyRowAccept(filterHelper, 1, "bar2", "foo", names, values);
    verifyRowAccept(filterHelper, 2, "foo", "test2", names, values);

    // Verify ignored events.
    verifyRowIgnore(filterHelper, 3, "foo", "test", names, values);
    verifyRowIgnore(filterHelper, 4, "foobar2", "foobar1", names, values);
    verifyRowIgnore(filterHelper, 5, "bar234", "foobar1", names, values);

    // All done.
    filterHelper.done();
  }
 // Confirms that a particular event is ignored.
 private void verifyIgnore(FilterVerificationHelper filterHelper, ReplDBMSEvent e)
     throws ReplicatorException, InterruptedException {
   ReplDBMSEvent e2 = filterHelper.filter(e);
   assertNull("Should ignore event: seqno=" + e.getSeqno(), e2);
 }
 // Confirms that a particular event is accepted.
 private void verifyAccept(FilterVerificationHelper filterHelper, ReplDBMSEvent e)
     throws ReplicatorException, InterruptedException {
   ReplDBMSEvent e2 = filterHelper.filter(e);
   assertTrue("Should allow event, seqno=" + e.getSeqno(), e == e2);
 }