@Test
  public void testPostDeleteNamespace() throws IOException {
    final Admin admin = UTIL.getAdmin();
    final String ns = "postdeletens";
    final TableName tn1 = TableName.valueOf(ns, "table1");

    admin.createNamespace(NamespaceDescriptor.create(ns).build());
    admin.createTable(TableDescriptorBuilder.newBuilder(tn1)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f1")).build())
      .build());

    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    MasterObserverForTest observer =
      master.getMasterCoprocessorHost().findCoprocessor(MasterObserverForTest.class);
    int preCount = observer.postHookCalls.get();
    try {
      admin.deleteNamespace(ns);
      fail("Deleting a non-empty namespace should be disallowed");
    } catch (IOException e) {
      // Pass
    }
    int postCount = observer.postHookCalls.get();
    assertEquals("Expected no invocations of postDeleteNamespace when the operation fails",
      preCount, postCount);

    // Disable and delete the table so that we can delete the NS.
    admin.disableTable(tn1);
    admin.deleteTable(tn1);

    // Validate that the postDeletNS hook is invoked
    preCount = observer.postHookCalls.get();
    admin.deleteNamespace(ns);
    postCount = observer.postHookCalls.get();
    assertEquals("Expected 1 invocation of postDeleteNamespace", preCount + 1, postCount);
  }
Tests class that validates that "post" observer hook methods are only invoked when the operation
was successful.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestMasterObserverPostCalls.java