类org.apache.zookeeper.KeeperException.NoAuthException源码实例Demo

下面列出了怎么用org.apache.zookeeper.KeeperException.NoAuthException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xian   文件: TestNamespaceFacade.java
/**
 * 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");
    // This will attempt to setACL on /parent/child, Previously this failed because /child
    // isn't present. Using "child" would case a failure because the path didn't start with
    // 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
    }
}
 
@Test(expected = NoAuthException.class)
public void assertInitWithDigestFailure() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
}
 
@Test(expected = NoAuthException.class)
public void assertInitWithDigestFailure() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
}
 
源代码4 项目: curator   文件: TestNamespaceFacade.java
/**
 * 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");
    // This will attempt to setACL on /parent/child, Previously this failed because /child
    // isn't present. Using "child" would case a failure because the path didn't start with
    // 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
    }
}
 
源代码5 项目: fluo   文件: ZKSecretIT.java
@Test
public void testClientWithoutZKSecret() {
  try (FluoClient client = FluoFactory.newClient(miniFluo.getClientConfiguration())) {
    try (Transaction tx = client.newTransaction()) {
      tx.set("node08", new Column("edge", "forward"), "node75");
      tx.commit();
    }

    miniFluo.waitForObservers();
  }

  FluoConfiguration conf = new FluoConfiguration(miniFluo.getClientConfiguration());
  conf.setZookeeperSecret("");
  try (FluoClient client = FluoFactory.newClient(conf)) {
    Assert.fail("Expected client creation to fail. " + client);
  } catch (Exception e) {
    boolean sawNoAuth = false;
    Throwable throwable = e;
    while (throwable != null) {
      if (throwable instanceof NoAuthException) {
        sawNoAuth = true;
        break;
      }
      throwable = throwable.getCause();
    }

    Assert.assertTrue(sawNoAuth);
  }

}
 
 类所在包
 同包方法