Search in sources :

Example 1 with NoAuthException

use of org.apache.zookeeper.KeeperException.NoAuthException in project xian by happyyangyuan.

the class TestNamespaceFacade method testACL.

/**
 * Test that ACLs work on a NamespaceFacade. See CURATOR-132
 * @throws Exception
 */
@Test
public void testACL() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    client.getZookeeperClient().blockUntilConnectedOrTimedOut();
    client.create().creatingParentsIfNeeded().forPath("/parent/child", "A string".getBytes());
    CuratorFramework client2 = client.usingNamespace("parent");
    Assert.assertNotNull(client2.getData().forPath("/child"));
    client.setACL().withACL(Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, ZooDefs.Ids.ANYONE_ID_UNSAFE))).forPath("/parent/child");
    // a slash
    try {
        List<ACL> acls = client2.getACL().forPath("/child");
        Assert.assertNotNull(acls);
        Assert.assertEquals(acls.size(), 1);
        Assert.assertEquals(acls.get(0).getId(), ZooDefs.Ids.ANYONE_ID_UNSAFE);
        Assert.assertEquals(acls.get(0).getPerms(), ZooDefs.Perms.WRITE);
        client2.setACL().withACL(Collections.singletonList(new ACL(ZooDefs.Perms.DELETE, ZooDefs.Ids.ANYONE_ID_UNSAFE))).forPath("/child");
        Assert.fail("Expected auth exception was not thrown");
    } catch (NoAuthException e) {
    // Expected
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) NoAuthException(org.apache.zookeeper.KeeperException.NoAuthException) ACL(org.apache.zookeeper.data.ACL) Test(org.testng.annotations.Test)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)1 RetryOneTime (org.apache.curator.retry.RetryOneTime)1 NoAuthException (org.apache.zookeeper.KeeperException.NoAuthException)1 ACL (org.apache.zookeeper.data.ACL)1 Test (org.testng.annotations.Test)1