use of org.apache.cassandra.auth.DataResource in project cassandra by apache.
the class InvalidatePermissionsCacheTest method testInvalidatePermissionsForAllRoles.
@Test
public void testInvalidatePermissionsForAllRoles() {
DataResource rootDataResource = DataResource.root();
Set<Permission> dataPermissions = rootDataResource.applicablePermissions();
AuthenticatedUser roleA = new AuthenticatedUser(ROLE_A.getRoleName());
AuthenticatedUser roleB = new AuthenticatedUser(ROLE_B.getRoleName());
// cache permissions
roleA.getPermissions(rootDataResource);
roleB.getPermissions(rootDataResource);
long originalReadsCount = getRolePermissionsReadCount();
// enure permissions are cached
assertThat(roleA.getPermissions(rootDataResource)).isEqualTo(dataPermissions);
assertThat(roleB.getPermissions(rootDataResource)).isEqualTo(dataPermissions);
assertThat(originalReadsCount).isEqualTo(getRolePermissionsReadCount());
// invalidate both permissions
ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("invalidatepermissionscache");
tool.assertOnCleanExit();
assertThat(tool.getStdout()).isEmpty();
// ensure permission for roleA is reloaded
assertThat(roleA.getPermissions(rootDataResource)).isEqualTo(dataPermissions);
long readsCountAfterFirstReLoad = getRolePermissionsReadCount();
assertThat(originalReadsCount).isLessThan(readsCountAfterFirstReLoad);
// ensure permission for roleB is reloaded
assertThat(roleB.getPermissions(rootDataResource)).isEqualTo(dataPermissions);
long readsCountAfterSecondReLoad = getRolePermissionsReadCount();
assertThat(readsCountAfterFirstReLoad).isLessThan(readsCountAfterSecondReLoad);
}
Aggregations