Search in sources :

Example 1 with DataResource

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);
}
Also used : ToolRunner(org.apache.cassandra.tools.ToolRunner) Permission(org.apache.cassandra.auth.Permission) DataResource(org.apache.cassandra.auth.DataResource) AuthenticatedUser(org.apache.cassandra.auth.AuthenticatedUser) Test(org.junit.Test)

Aggregations

AuthenticatedUser (org.apache.cassandra.auth.AuthenticatedUser)1 DataResource (org.apache.cassandra.auth.DataResource)1 Permission (org.apache.cassandra.auth.Permission)1 ToolRunner (org.apache.cassandra.tools.ToolRunner)1 Test (org.junit.Test)1