@Test
  public void alterDatabase() throws Exception {
    String dbName = "alterdb";
    String dbLocationUri = testTempDir;
    String dbDescription = "no description";
    msClient.createDatabase(new Database(dbName, dbDescription, dbLocationUri, emptyParameters));
    // get the db for comparison below since it may include additional parameters
    Database dbBefore = msClient.getDatabase(dbName);
    // create alter database notification
    String newDesc = "test database";
    Database dbAfter = dbBefore.deepCopy();
    dbAfter.setDescription(newDesc);
    dbAfter.setOwnerName("test2");
    dbAfter.setOwnerType(PrincipalType.USER);
    msClient.alterDatabase(dbName, dbAfter);
    dbAfter = msClient.getDatabase(dbName);

    // Read notification from metastore
    NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
    assertEquals(2, rsp.getEventsSize());
    // check the contents of alter database notification
    NotificationEvent event = rsp.getEvents().get(1);
    assertEquals(firstEventId + 2, event.getEventId());
    assertTrue(event.getEventTime() >= startTime);
    assertEquals(EventType.ALTER_DATABASE.toString(), event.getEventType());
    assertEquals(dbName, event.getDbName());
    assertNull(event.getTableName());

    // Parse the message field
    AlterDatabaseMessage alterDatabaseMessage = md.getAlterDatabaseMessage(event.getMessage());
    assertEquals(dbName, alterDatabaseMessage.getDB());
    assertEquals(dbBefore, alterDatabaseMessage.getDbObjBefore());
    assertEquals(dbAfter, alterDatabaseMessage.getDbObjAfter());
  }
Tests DbNotificationListener when used as a transactional event listener
(hive.metastore.transactional.event.listeners)
itests/hcatalog-unit/src/test/java/org/apache/hive/hcatalog/listener/TestDbNotificationListener.java