@Test
public void testRefreshProxyUser() throws Exception {

  Path dirPath = new Path("/testdir1");
  Path subDirPath = new Path("/testdir1/subdir1");
  UserGroupInformation loginUserUgi =  UserGroupInformation.getLoginUser();
  String proxyUser = "fakeuser";
  String realUser = loginUserUgi.getShortUserName();
  UserGroupInformation proxyUgi =
      UserGroupInformation.createProxyUserForTesting(proxyUser,
          loginUserUgi, loginUserUgi.getGroupNames());
  // create a directory as login user and re-assign it to proxy user
  loginUserUgi.doAs(new PrivilegedExceptionAction<Integer>() {
    @Override
    public Integer run() throws Exception {
      cluster.getFileSystem().mkdirs(dirPath);
      cluster.getFileSystem().setOwner(dirPath, proxyUser,
          proxyUgi.getPrimaryGroupName());
      return 0;
    }
  });
  // try creating subdirectory inside the directory as proxy user,
  // This should fail because of the current user hasn't still been proxied
  try {
    proxyUgi.doAs(new PrivilegedExceptionAction<Integer>() {
      @Override public Integer run() throws Exception {
        cluster.getFileSystem().mkdirs(subDirPath);
        return 0;
      }
    });
  } catch (RemoteException re) {
    Assert.assertTrue(re.unwrapRemoteException()
        instanceof AccessControlException);
    Assert.assertTrue(re.unwrapRemoteException().getMessage()
        .equals("User: " + realUser +
            " is not allowed to impersonate " + proxyUser));
  }
  // refresh will look at configuration on the server side
  // add additional resource with the new value
  // so the server side will pick it up
  String userKeyGroups = DefaultImpersonationProvider.getTestProvider().
      getProxySuperuserGroupConfKey(realUser);
  String userKeyHosts = DefaultImpersonationProvider.getTestProvider().
      getProxySuperuserIpConfKey(realUser);
  String rsrc = "testGroupMappingRefresh_rsrc.xml";
  tempResource = TestRefreshUserMappings.addNewConfigResource(rsrc,
      userKeyGroups, "*", userKeyHosts, "*");
  String[] args = new String[]{"-refreshSuperUserGroupsConfiguration"};
  admin.run(args);
  // After proxying the fakeuser, the mkdir should work
  proxyUgi.doAs(new PrivilegedExceptionAction<Integer>() {
    @Override
    public Integer run() throws Exception {
      cluster.getFileSystem().mkdirs(dirPath);
      return 0;
    }
  });
}