本文整理汇总了Java中org.apache.zookeeper.KeeperException.AuthFailedException方法的典型用法代码示例。如果您正苦于以下问题:Java KeeperException.AuthFailedException方法的具体用法?Java KeeperException.AuthFailedException怎么用?Java KeeperException.AuthFailedException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.KeeperException
的用法示例。
在下文中一共展示了KeeperException.AuthFailedException方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBadAuthNotifiesWatch
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testBadAuthNotifiesWatch() throws Exception {
ZooKeeper zk = createClient();
try {
zk.addAuthInfo("FOO", "BAR".getBytes());
zk.getData("/path1", false, null);
Assert.fail("Should get auth state error");
} catch(KeeperException.AuthFailedException e) {
if(!authFailed.await(CONNECTION_TIMEOUT,
TimeUnit.MILLISECONDS))
{
Assert.fail("Should have called my watcher");
}
}
finally {
zk.close();
}
}
示例2: testBadAuthThenSendOtherCommands
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testBadAuthThenSendOtherCommands() throws Exception {
ZooKeeper zk = createClient();
try {
zk.addAuthInfo("INVALID", "BAR".getBytes());
zk.exists("/foobar", false);
zk.getData("/path1", false, null);
Assert.fail("Should get auth state error");
} catch(KeeperException.AuthFailedException e) {
if(!authFailed.await(CONNECTION_TIMEOUT,
TimeUnit.MILLISECONDS))
{
Assert.fail("Should have called my watcher");
}
}
finally {
zk.close();
}
}
示例3: validAuth
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
public void validAuth() throws Exception {
ZooKeeper zk = createClient();
// any multiple of 5 will do...
zk.addAuthInfo("key", "25".getBytes());
try {
createNodePrintAcl(zk, "/valid", "testValidAuth");
zk.getData("/abc", false, null);
zk.setData("/abc", "testData3".getBytes(), -1);
} catch (KeeperException.AuthFailedException e) {
Assert.fail("test failed :" + e);
} finally {
zk.close();
}
}
示例4: validAuth2
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
public void validAuth2() throws Exception {
ZooKeeper zk = createClient();
// any multiple of 5 will do...
zk.addAuthInfo("key", "125".getBytes());
try {
createNodePrintAcl(zk, "/valid2", "testValidAuth2");
zk.getData("/abc", false, null);
zk.setData("/abc", "testData3".getBytes(), -1);
} catch (KeeperException.AuthFailedException e) {
Assert.fail("test failed :" + e);
} finally {
zk.close();
}
}
示例5: blockUntilAvailable
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
public static byte[] blockUntilAvailable(
final ZooKeeperWatcher zkw, final String znode, final long timeout)
throws InterruptedException {
if (timeout < 0) throw new IllegalArgumentException();
if (zkw == null) throw new IllegalArgumentException();
if (znode == null) throw new IllegalArgumentException();
byte[] data = null;
boolean finished = false;
final long endTime = System.currentTimeMillis() + timeout;
while (!finished) {
try {
data = ZKUtil.getData(zkw, znode);
} catch(KeeperException e) {
if (e instanceof KeeperException.SessionExpiredException
|| e instanceof KeeperException.AuthFailedException) {
// non-recoverable errors so stop here
throw new InterruptedException("interrupted due to " + e);
}
LOG.warn("Unexpected exception handling blockUntilAvailable", e);
}
if (data == null && (System.currentTimeMillis() +
HConstants.SOCKET_RETRY_WAIT_MS < endTime)) {
Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
} else {
finished = true;
}
}
return data;
}
示例6: testGetActiveData
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
* verify that receiveActiveData gives data when active exists, tells that
* active does not exist and reports error in getting active information
*
* @throws IOException
* @throws InterruptedException
* @throws KeeperException
* @throws ActiveNotFoundException
*/
@Test
public void testGetActiveData() throws ActiveNotFoundException,
KeeperException, InterruptedException, IOException {
// get valid active data
byte[] data = new byte[8];
Mockito.when(
mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject())).thenReturn(data);
Assert.assertEquals(data, elector.getActiveData());
Mockito.verify(mockZK, Mockito.times(1)).getData(
Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject());
// active does not exist
Mockito.when(
mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject())).thenThrow(
new KeeperException.NoNodeException());
try {
elector.getActiveData();
Assert.fail("ActiveNotFoundException expected");
} catch(ActiveNotFoundException e) {
Mockito.verify(mockZK, Mockito.times(2)).getData(
Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject());
}
// error getting active data rethrows keeperexception
try {
Mockito.when(
mockZK.getData(Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject())).thenThrow(
new KeeperException.AuthFailedException());
elector.getActiveData();
Assert.fail("KeeperException.AuthFailedException expected");
} catch(KeeperException.AuthFailedException ke) {
Mockito.verify(mockZK, Mockito.times(3)).getData(
Mockito.eq(ZK_LOCK_NAME), Mockito.eq(false),
Mockito.<Stat> anyObject());
}
}