Search in sources :

Example 11 with StatCallback

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());
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback) Test(org.junit.Test)

Example 12 with StatCallback

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();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeper(org.apache.zookeeper.ZooKeeper) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback)

Example 13 with StatCallback

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();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeper(org.apache.zookeeper.ZooKeeper) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback)

Example 14 with StatCallback

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();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeper(org.apache.zookeeper.ZooKeeper) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback)

Aggregations

StatCallback (org.apache.zookeeper.AsyncCallback.StatCallback)14 Stat (org.apache.zookeeper.data.Stat)12 ZooKeeper (org.apache.zookeeper.ZooKeeper)7 Watcher (org.apache.zookeeper.Watcher)6 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 VoidCallback (org.apache.zookeeper.AsyncCallback.VoidCallback)3 WatchedEvent (org.apache.zookeeper.WatchedEvent)3 ACLCallback (org.apache.zookeeper.AsyncCallback.ACLCallback)2 DataCallback (org.apache.zookeeper.AsyncCallback.DataCallback)2 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)2 ACL (org.apache.zookeeper.data.ACL)2 Test (org.junit.jupiter.api.Test)2 IOException (java.io.IOException)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1