@Test
  public void alterPartitions() throws Exception {
    String defaultDbName = "default";
    String tblName = "alterptns";
    new TableBuilder()
        .setDbName(defaultDbName).setTableName(tblName).setOwner("me")
        .addCol("col1", "int")
        .addPartCol("col2", "int")
        .addPartCol("col3", "string")
        .setLocation(testTempDir)
        .create(msClient, new HiveConf());

    Table table = msClient.getTable(new GetTableRequest(defaultDbName, tblName));
    List<Partition> partitions = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
      List<String> values = Arrays.asList(i + "", "part" + i);
      Partition part = new Partition(values, defaultDbName, tblName,
          0,  0, table.getSd(), emptyParameters);
      partitions.add(part);
    }
    msClient.add_partitions(partitions);
    partitions.forEach(partition -> partition.setCreateTime(startTime));
    msClient.alter_partitions(defaultDbName, tblName, partitions, null, null, -1);

    // Get notifications from metastore
    NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
    assertEquals(3, rsp.getEventsSize());
    NotificationEvent event = rsp.getEvents().get(2);
    assertEquals(firstEventId + 3, event.getEventId());
    assertTrue(event.getEventTime() >= startTime);
    assertEquals(EventType.ALTER_PARTITIONS.toString(), event.getEventType());
    assertEquals(defaultDbName, event.getDbName());
    assertEquals(tblName, event.getTableName());
    // Parse the message field
    AlterPartitionsMessage alterPtnsMsg = md.getAlterPartitionsMessage(event.getMessage());
    assertEquals(defaultDbName, alterPtnsMsg.getDB());
    assertEquals(tblName, alterPtnsMsg.getTable());
    Iterator<Partition> expectedIterator = partitions.iterator(),
        actualIterator = alterPtnsMsg.getPartitionObjs().iterator();
    while (expectedIterator.hasNext() && actualIterator.hasNext()) {
      assertEquals(expectedIterator.next(), actualIterator.next());
    }
    assertFalse(expectedIterator.hasNext() || actualIterator.hasNext());
    assertEquals(table.getTableType(), alterPtnsMsg.getTableType());

    // Verify the eventID was passed to the non-transactional listener
    MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.ADD_PARTITION, firstEventId + 2);
    MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_TABLE, firstEventId + 1);

    // When hive.metastore.transactional.event.listeners is set,
    // a failed event should not create a new notification
    DummyRawStoreFailEvent.setEventSucceed(false);
    try {
      msClient.alter_partitions(defaultDbName, tblName, partitions, null, null, -1);
      fail("Error: alter partition should've failed");
    } catch (Exception ex) {
      // expected
    }
    rsp = msClient.getNextNotification(firstEventId, 0, null);
    assertEquals(3, rsp.getEventsSize());
    testEventCounts(defaultDbName, firstEventId, null, null, 3);
  }
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