Search in sources :

Example 1 with ZooKeeperServerShim

use of org.apache.bookkeeper.shims.zk.ZooKeeperServerShim in project distributedlog by twitter.

the class LocalDLMEmulator method runZookeeperOnAnyPort.

/**
     * Try to start zookkeeper locally on any port beginning with some base port.
     * Dump some socket info when bind fails.
     */
public static Pair<ZooKeeperServerShim, Integer> runZookeeperOnAnyPort(int basePort, File zkDir) throws Exception {
    final int MAX_RETRIES = 20;
    final int MIN_PORT = 1025;
    final int MAX_PORT = 65535;
    ZooKeeperServerShim zks = null;
    int zkPort = basePort;
    boolean success = false;
    int retries = 0;
    while (!success) {
        try {
            LOG.info("zk trying to bind to port " + zkPort);
            zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkDir);
            success = true;
        } catch (BindException be) {
            retries++;
            if (retries > MAX_RETRIES) {
                throw be;
            }
            zkPort++;
            if (zkPort > MAX_PORT) {
                zkPort = MIN_PORT;
            }
        }
    }
    return Pair.of(zks, zkPort);
}
Also used : ZooKeeperServerShim(org.apache.bookkeeper.shims.zk.ZooKeeperServerShim) BindException(java.net.BindException)

Example 2 with ZooKeeperServerShim

use of org.apache.bookkeeper.shims.zk.ZooKeeperServerShim in project distributedlog by twitter.

the class TestDLMTestUtil method testRunZookeeperOnAnyPort.

@Test(timeout = 60000)
public void testRunZookeeperOnAnyPort() throws Exception {
    Pair<ZooKeeperServerShim, Integer> serverAndPort1 = null;
    Pair<ZooKeeperServerShim, Integer> serverAndPort2 = null;
    Pair<ZooKeeperServerShim, Integer> serverAndPort3 = null;
    try {
        File zkTmpDir1 = IOUtils.createTempDir("zookeeper1", "distrlog");
        serverAndPort1 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir1);
        File zkTmpDir2 = IOUtils.createTempDir("zookeeper2", "distrlog");
        serverAndPort2 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir2);
        File zkTmpDir3 = IOUtils.createTempDir("zookeeper3", "distrlog");
        serverAndPort3 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir3);
    } catch (Exception ex) {
        if (null != serverAndPort1) {
            serverAndPort1.getLeft().stop();
        }
        if (null != serverAndPort2) {
            serverAndPort2.getLeft().stop();
        }
        if (null != serverAndPort3) {
            serverAndPort3.getLeft().stop();
        }
    }
}
Also used : ZooKeeperServerShim(org.apache.bookkeeper.shims.zk.ZooKeeperServerShim) File(java.io.File) Test(org.junit.Test)

Example 3 with ZooKeeperServerShim

use of org.apache.bookkeeper.shims.zk.ZooKeeperServerShim in project distributedlog by twitter.

the class TestDistributedLogBase method setupCluster.

@BeforeClass
public static void setupCluster() throws Exception {
    File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog");
    tmpDirs.add(zkTmpDir);
    Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir);
    zks = serverAndPort.getLeft();
    zkPort = serverAndPort.getRight();
    bkutil = LocalDLMEmulator.newBuilder().numBookies(numBookies).zkHost("127.0.0.1").zkPort(zkPort).serverConf(DLMTestUtil.loadTestBkConf()).shouldStartZK(false).build();
    bkutil.start();
    zkServers = "127.0.0.1:" + zkPort;
}
Also used : ZooKeeperServerShim(org.apache.bookkeeper.shims.zk.ZooKeeperServerShim) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

ZooKeeperServerShim (org.apache.bookkeeper.shims.zk.ZooKeeperServerShim)3 File (java.io.File)2 BindException (java.net.BindException)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1