Search in sources :

Example 36 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project pinpoint by naver.

the class DefaultZookeeperClient method exists.

@Override
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
    checkState();
    ZooKeeper zookeeper = this.zookeeper;
    try {
        Stat stat = zookeeper.exists(path, false);
        if (stat == null) {
            return false;
        }
    } catch (KeeperException exception) {
        if (exception.code() != Code.NODEEXISTS) {
            handleException(exception);
        }
    }
    return true;
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Example 37 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project pinpoint by naver.

the class ZookeeperClient method exists.

public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
    checkState();
    ZooKeeper zookeeper = this.zookeeper;
    try {
        Stat stat = zookeeper.exists(path, false);
        if (stat == null) {
            return false;
        }
    } catch (KeeperException exception) {
        if (exception.code() != Code.NODEEXISTS) {
            handleException(exception);
        }
    }
    return true;
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Example 38 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project Dempsy by Dempsy.

the class TestZookeeperClusterImpl method testBadZooKeeperConnection.

@Test
public void testBadZooKeeperConnection() throws Throwable {
    int port = ZookeeperTestServer.findNextPort();
    ZookeeperTestServer server = new ZookeeperTestServer();
    Throwable receivedException = null;
    ZookeeperSession session = null;
    try {
        server.start();
        session = new ZookeeperSession("127.0.0.1:" + port, 5000) {

            @Override
            protected ZooKeeper makeZooKeeperClient(String connectString, int sessionTimeout) throws IOException {
                return new ZooKeeper(connectString, sessionTimeout, new ZkWatcher()) {

                    @Override
                    public List<String> getChildren(String path, Watcher watcher) throws KeeperException {
                        throw (appropriateException = new KeeperException(Code.DATAINCONSISTENCY) {

                            private static final long serialVersionUID = 1L;
                        });
                    }
                };
            }
        };
        try {
            session.getSubdirs(new ClusterId("test", "test").asPath(), null);
        } catch (Exception e) {
            receivedException = e.getCause();
        }
    } finally {
        server.shutdown();
        if (session != null)
            session.stop();
    }
    assertNotNull(appropriateException);
    assertTrue(receivedException == appropriateException);
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) Watcher(org.apache.zookeeper.Watcher) IOException(java.io.IOException) ClusterInfoException(com.nokia.dempsy.cluster.ClusterInfoException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ZooKeeper(org.apache.zookeeper.ZooKeeper) List(java.util.List) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 39 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project Dempsy by Dempsy.

the class ZookeeperTestServer method forceSessionExpiration.

public static void forceSessionExpiration(ZooKeeper origZk) throws Throwable {
    TestUtils.Condition<ZooKeeper> condition = new TestUtils.Condition<ZooKeeper>() {

        @Override
        public boolean conditionMet(ZooKeeper o) throws Throwable {
            try {
                return (o.getState() == ZooKeeper.States.CONNECTED) && o.exists("/", true) != null;
            } catch (KeeperException ke) {
                return false;
            }
        }
    };
    assertTrue(TestUtils.poll(5000, origZk, condition));
    boolean done = false;
    while (!done) {
        long sessionid = origZk.getSessionId();
        byte[] pw = origZk.getSessionPasswd();
        KWatcher kwatcher = new KWatcher();
        ZooKeeper killer = new ZooKeeper("127.0.0.1:" + port, 5000, kwatcher, sessionid, pw);
        kwatcher.connection.set(killer);
        // wait until we get a close
        boolean calledBack = TestUtils.poll(5000, kwatcher, new Condition<KWatcher>() {

            @Override
            public boolean conditionMet(KWatcher o) throws Throwable {
                return o.closed.get();
            }
        });
        if (!calledBack)
            killer.close();
        final AtomicBoolean isExpired = new AtomicBoolean(false);
        ZooKeeper check = new ZooKeeper("127.0.0.1:" + port, 5000, new Watcher() {

            @Override
            public void process(WatchedEvent event) {
                if (event.getState() == Watcher.Event.KeeperState.Expired)
                    isExpired.set(true);
            }
        }, sessionid, pw);
        done = TestUtils.poll(5000, isExpired, new Condition<AtomicBoolean>() {

            public boolean conditionMet(AtomicBoolean o) {
                return o.get();
            }
        });
        check.close();
    }
}
Also used : Condition(com.nokia.dempsy.TestUtils.Condition) Watcher(org.apache.zookeeper.Watcher) WatchedEvent(org.apache.zookeeper.WatchedEvent) TestUtils(com.nokia.dempsy.TestUtils) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ZooKeeper(org.apache.zookeeper.ZooKeeper) KeeperException(org.apache.zookeeper.KeeperException)

Example 40 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project pulsar by yahoo.

the class ZookeeperCacheLoaderTest method testZookeeperCacheLoader.

/**
     * Create znode for available broker in ZooKeeper and updates it again to verify ZooKeeper cache update
     *
     * @throws InterruptedException
     * @throws KeeperException
     * @throws IOException
     */
@Test
public void testZookeeperCacheLoader() throws InterruptedException, KeeperException, Exception {
    DiscoveryZooKeeperClientFactoryImpl.zk = mockZookKeeper;
    ZookeeperCacheLoader zkLoader = new ZookeeperCacheLoader(new DiscoveryZooKeeperClientFactoryImpl(), "");
    List<String> brokers = Lists.newArrayList("broker-1:15000", "broker-2:15000", "broker-3:15000");
    // 1. create znode for each broker
    brokers.stream().forEach(b -> {
        try {
            zkLoader.getLocalZkCache().getZooKeeper().create(LOADBALANCE_BROKERS_ROOT + "/" + b, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        } catch (KeeperException | InterruptedException e) {
            fail("failed while creating broker znodes");
        }
    });
    // wait for 100 msec: to get cache updated
    Thread.sleep(100);
    // 2. get available brokers from ZookeeperCacheLoader
    List<LoadReport> list = zkLoader.getAvailableBrokers();
    // 3. verify retrieved broker list
    Assert.assertTrue(brokers.containsAll(list));
    // 4.a add new broker
    zkLoader.getLocalZkCache().getZooKeeper().create(LOADBALANCE_BROKERS_ROOT + "/" + "broker-4:15000", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    brokers.add("broker-4:15000");
    // wait for 100 msec: to get cache updated
    Thread.sleep(100);
    // 4.b. get available brokers from ZookeeperCacheLoader
    list = zkLoader.getAvailableBrokers();
    // 4.c. verify retrieved broker list
    Assert.assertTrue(brokers.containsAll(list));
}
Also used : ZookeeperCacheLoader(com.yahoo.pulsar.discovery.service.web.ZookeeperCacheLoader) DiscoveryZooKeeperClientFactoryImpl(com.yahoo.pulsar.discovery.service.web.BaseZKStarterTest.DiscoveryZooKeeperClientFactoryImpl) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) KeeperException(org.apache.zookeeper.KeeperException) Test(org.testng.annotations.Test)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)608 IOException (java.io.IOException)206 Stat (org.apache.zookeeper.data.Stat)131 ZooKeeper (org.apache.zookeeper.ZooKeeper)89 ArrayList (java.util.ArrayList)55 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)45 Watcher (org.apache.zookeeper.Watcher)43 WatchedEvent (org.apache.zookeeper.WatchedEvent)42 Test (org.junit.jupiter.api.Test)38 HashMap (java.util.HashMap)33 List (java.util.List)32 CountDownLatch (java.util.concurrent.CountDownLatch)32 SolrException (org.apache.solr.common.SolrException)30 Test (org.junit.Test)29 ACL (org.apache.zookeeper.data.ACL)27 Map (java.util.Map)26 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)25 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)24 ServerName (org.apache.hadoop.hbase.ServerName)24 OpResult (org.apache.zookeeper.OpResult)21