@Test
  public void testAuthManager() throws Exception {
    Configuration conf = UTIL.getConfiguration();
    /**
     * test a race condition causing AuthManager to sometimes fail global permissions checks when
     * the global cache is being updated
     */
    AuthManager authManager = new AuthManager(conf);
    // currently running user is the system user and should have global admin perms
    User currentUser = User.getCurrent();
    assertTrue(authManager.authorizeUserGlobal(currentUser, Permission.Action.ADMIN));
    try (Connection connection = ConnectionFactory.createConnection(conf)) {
      for (int i = 1; i <= 50; i++) {
        addUserPermission(conf,
          new UserPermission("testauth" + i,
            Permission.newBuilder()
              .withActions(Permission.Action.ADMIN, Permission.Action.READ, Permission.Action.WRITE)
              .build()),
          connection.getTable(PermissionStorage.ACL_TABLE_NAME));
        // make sure the system user still shows as authorized
        assertTrue("Failed current user auth check on iter " + i,
          authManager.authorizeUserGlobal(currentUser, Permission.Action.ADMIN));
      }
    }
  }
The PermissionStorage.addUserPermission may throw exception before closing the table.
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java