Search in sources :

Example 6 with ZooKeeperWatcherBase

use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project pulsar by yahoo.

the class ZkBookieRackAffinityMappingTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    localZkS = new ZookeeperServerTest(LOCAL_ZOOKEEPER_PORT);
    localZkS.start();
    ZooKeeperWatcherBase zkWatcherBase = new ZooKeeperWatcherBase(10000);
    localZkc = ZkUtils.createConnectedZookeeperClient("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT, zkWatcherBase);
    BOOKIE1 = new BookieSocketAddress("127.0.0.1:3181");
    BOOKIE2 = new BookieSocketAddress("127.0.0.2:3181");
    BOOKIE3 = new BookieSocketAddress("127.0.0.3:3181");
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ZooKeeperWatcherBase

use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project bookkeeper by apache.

the class BookKeeperClientZKSessionExpiry method testSessionLossWhileWriting.

@Test
public void testSessionLossWhileWriting() throws Exception {
    Thread expiryThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    Thread.sleep(5000);
                    long sessionId = bkc.getZkHandle().getSessionId();
                    byte[] sessionPasswd = bkc.getZkHandle().getSessionPasswd();
                    try {
                        ZooKeeperWatcherBase watcher = new ZooKeeperWatcherBase(10000);
                        ZooKeeper zk = new ZooKeeper(zkUtil.getZooKeeperConnectString(), 10000, watcher, sessionId, sessionPasswd);
                        zk.close();
                    } catch (Exception e) {
                        LOG.info("Error killing session", e);
                    }
                }
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                return;
            }
        }
    };
    expiryThread.start();
    for (int i = 0; i < 3; i++) {
        LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.MAC, "foobar".getBytes());
        for (int j = 0; j < 100; j++) {
            lh.asyncAddEntry("foobar".getBytes(), new AddCallbackFuture(j), null);
        }
        startNewBookie();
        killBookie(0);
        lh.addEntry("lastEntry".getBytes());
        lh.close();
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) AddCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture) Test(org.junit.Test)

Aggregations

ZooKeeperWatcherBase (org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase)7 ZooKeeper (org.apache.zookeeper.ZooKeeper)4 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 KeeperException (org.apache.zookeeper.KeeperException)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Map (java.util.Map)1 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)1 AddCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture)1 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1 Test (org.junit.Test)1