@Test
public void testGrantPrivilegeTwice() throws Exception {

  String roleName = "r1";
  /**
   * grantor is admin, there is no need to check grant option
   */
  String grantor = ADMIN_USER;
  sentryStore.createRole(SEARCH, roleName, grantor);
  PrivilegeObject queryPrivilegeWithOption = new Builder()
  .setComponent(SEARCH)
  .setAction(SearchConstants.QUERY)
  .setService(SERVICE)
  .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME)))
  .withGrantOption(true)
  .build();
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilegeWithOption, grantor);
  assertEquals(1,sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)).size());
  //grant again
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilegeWithOption, grantor);
  assertEquals(1,sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)).size());
  PrivilegeObject queryPrivilegeWithNoOption = new Builder()
  .setComponent(SEARCH)
  .setAction(SearchConstants.QUERY)
  .setService(SERVICE)
  .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME)))
  .withGrantOption(false)
  .build();
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilegeWithNoOption, grantor);
  assertEquals(2,sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)).size());
  //grant again
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilegeWithNoOption, grantor);
  assertEquals(2,sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)).size());
  PrivilegeObject queryPrivilegeWithNullGrant = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.QUERY)
      .setService(SERVICE)
      .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME)))
      .withGrantOption(null)
      .build();
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilegeWithNullGrant, grantor);
  assertEquals(3,sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)).size());
  //grant again
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilegeWithNullGrant, grantor);
  assertEquals(3,sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)).size());
}