use of org.apache.zookeeper.AsyncCallback.StatCallback in project bookkeeper by apache.
the class TestZKLogStreamMetadataStore method testGetMissingPathsFailure.
@Test(timeout = 60000)
public void testGetMissingPathsFailure() throws Exception {
ZooKeeper mockZk = mock(ZooKeeper.class);
ZooKeeperClient mockZkc = mock(ZooKeeperClient.class);
when(mockZkc.get()).thenReturn(mockZk);
doAnswer(invocationOnMock -> {
String path = (String) invocationOnMock.getArguments()[0];
StatCallback callback = (StatCallback) invocationOnMock.getArguments()[2];
callback.processResult(Code.BADVERSION.intValue(), path, null, null);
return null;
}).when(mockZk).exists(anyString(), anyBoolean(), any(StatCallback.class), any());
try {
FutureUtils.result(getMissingPaths(mockZkc, uri, "path_failure/to/log_failure"));
fail("Should fail on getting missing paths on zookeeper exceptions.");
} catch (ZKException zke) {
assertEquals(Code.BADVERSION, zke.getKeeperExceptionCode());
}
}
use of org.apache.zookeeper.AsyncCallback.StatCallback in project bookkeeper by apache.
the class ZooKeeperClient method exists.
@Override
public void exists(final String path, final boolean watch, final StatCallback cb, final Object context) {
final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, existsStats) {
final StatCallback stCb = new StatCallback() {
@Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
ZooWorker worker = (ZooWorker) ctx;
if (allowRetry(worker, rc)) {
backOffAndRetry(that, worker.nextRetryWaitTime());
} else {
cb.processResult(rc, path, context, stat);
}
}
};
@Override
void zkRun() {
ZooKeeper zkHandle = zk.get();
if (null == zkHandle) {
ZooKeeperClient.super.exists(path, watch, stCb, worker);
} else {
zkHandle.exists(path, watch, stCb, worker);
}
}
@Override
public String toString() {
return String.format("exists (%s, watcher = %s)", path, watch);
}
};
// execute it immediately
proc.run();
}
use of org.apache.zookeeper.AsyncCallback.StatCallback in project bookkeeper by apache.
the class ZooKeeperClient method exists.
@Override
public void exists(final String path, final Watcher watcher, final StatCallback cb, final Object context) {
final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, existsStats) {
final StatCallback stCb = new StatCallback() {
@Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
ZooWorker worker = (ZooWorker) ctx;
if (allowRetry(worker, rc)) {
backOffAndRetry(that, worker.nextRetryWaitTime());
} else {
cb.processResult(rc, path, context, stat);
}
}
};
@Override
void zkRun() {
ZooKeeper zkHandle = zk.get();
if (null == zkHandle) {
ZooKeeperClient.super.exists(path, watcher, stCb, worker);
} else {
zkHandle.exists(path, watcher, stCb, worker);
}
}
@Override
public String toString() {
return String.format("exists (%s, watcher = %s)", path, watcher);
}
};
// execute it immediately
proc.run();
}
use of org.apache.zookeeper.AsyncCallback.StatCallback in project bookkeeper by apache.
the class ZooKeeperClient method setACL.
@Override
public void setACL(final String path, final List<ACL> acl, final int version, final StatCallback cb, final Object context) {
final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, setACLStats) {
final StatCallback stCb = new StatCallback() {
@Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
ZooWorker worker = (ZooWorker) ctx;
if (allowRetry(worker, rc)) {
backOffAndRetry(that, worker.nextRetryWaitTime());
} else {
cb.processResult(rc, path, context, stat);
}
}
};
@Override
public String toString() {
return String.format("setACL (%s, acl = %s, version = %d)", path, acl, version);
}
@Override
void zkRun() {
ZooKeeper zkHandle = zk.get();
if (null == zkHandle) {
ZooKeeperClient.super.setACL(path, acl, version, stCb, worker);
} else {
zkHandle.setACL(path, acl, version, stCb, worker);
}
}
};
// execute it immediately
proc.run();
}
Aggregations