@Test
  public void fetchNotificationEventBasedOnTables() throws Exception {
    String dbName = "default";
    String table1 = "test_tbl1";
    String table2 = "test_tbl2";
    String table3 = "test_tbl3";
    // Generate some table events
    generateSometableEvents(dbName, table1);
    generateSometableEvents(dbName, table2);
    generateSometableEvents(dbName, table3);

    // Verify events by table names
    NotificationEventRequest request = new NotificationEventRequest();
    request.setLastEvent(firstEventId);
    request.setMaxEvents(-1);
    request.setDbName(dbName);
    request.setTableNames(Arrays.asList(table1));
    NotificationEventResponse rsp1 = msClient.getNextNotification(request, true, null);
    assertEquals(12, rsp1.getEventsSize());
    request.setTableNames(Arrays.asList(table1, table2));
    request.setEventTypeSkipList(Arrays.asList("CREATE_TABLE"));
    NotificationEventResponse rsp2 = msClient.getNextNotification(request, true, null);
    // The actual count of events should 24. Having CREATE_TABLE event in the event skip
    // list will result in events count reduced 22 as it skips fetching 2 create_table events
    // associated with two different tables.
    assertEquals(22, rsp2.getEventsSize());
    request.unsetTableNames();
    request.unsetEventTypeSkipList();
    NotificationEventResponse rsp3 = msClient.getNextNotification(request, true, null);
    assertEquals(36, rsp3.getEventsSize());

    NotificationEventsCountRequest eventsReq = new NotificationEventsCountRequest(firstEventId, dbName);
    eventsReq.setTableNames(Arrays.asList(table1));
    assertEquals(12, msClient.getNotificationEventsCount(eventsReq).getEventsCount());
    eventsReq.setTableNames(Arrays.asList(table1, table2));
    assertEquals(24, msClient.getNotificationEventsCount(eventsReq).getEventsCount());
    eventsReq.unsetTableNames();
    assertEquals(36, msClient.getNotificationEventsCount(eventsReq).getEventsCount());
  }
The method creates some events in notification log and fetches the events
based on the fields set on the NotificationEventRequest object. It includes
setting database name, table name(s), event skip list (i.e., filter out events
that are not required). These fields are optional.
@throws Exception
itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java