@Test
  public void testRaceConditionOnPermissionUpdate() throws Exception {
    Configuration conf = UTIL.getConfiguration();
    User tom = User.createUserForTesting(conf, "tom", new String[] {});
    User jerry = User.createUserForTesting(conf, "jerry", new String[] {});
    ListMultimap<String, UserPermission> permissions = ArrayListMultimap.create();

    // update ACL: george RW
    writeToZookeeper(WATCHER_A,
      updatePermissions(permissions, tom, Permission.Action.READ, Permission.Action.WRITE));
    waitForModification(AUTH_A, 1000);

    // check it
    assertTrue(AUTH_A.authorizeUserTable(tom, TEST_TABLE, Permission.Action.READ));
    assertTrue(AUTH_A.authorizeUserTable(tom, TEST_TABLE, Permission.Action.WRITE));

    // update ACL: hubert A
    writeToZookeeper(WATCHER_A, updatePermissions(permissions, jerry, Permission.Action.ADMIN));
    // intended not to waitForModification(AUTH_A, 1000);
    // check george permission should not be updated/removed while updating permission for hubert
    for (int i = 0; i < 5000; i++) {
      assertTrue(AUTH_A.authorizeUserTable(tom, TEST_TABLE, Permission.Action.READ));
      assertTrue(AUTH_A.authorizeUserTable(tom, TEST_TABLE, Permission.Action.WRITE));
    }
  }
Test the reading and writing of access permissions to and from zookeeper.
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestZKPermissionWatcher.java