예제 #1
0
  @Test
  public void testMinMaxSessionTimeout() throws Exception {
    // override the defaults
    final int MINSESS = 20000;
    final int MAXSESS = 240000;
    ZooKeeperServer zs = serverFactory.getZooKeeperServer();
    zs.setMinSessionTimeout(MINSESS);
    zs.setMaxSessionTimeout(MAXSESS);

    // validate typical case - requested == negotiated
    int timeout = 120000;
    DisconnectableZooKeeper zk = createClient(timeout);
    Assert.assertEquals(timeout, zk.getSessionTimeout());
    // make sure tostring works in both cases
    LOG.info(zk.toString());
    zk.close();
    LOG.info(zk.toString());

    // validate lower limit
    zk = createClient(MINSESS / 2);
    Assert.assertEquals(MINSESS, zk.getSessionTimeout());
    LOG.info(zk.toString());
    zk.close();
    LOG.info(zk.toString());

    // validate upper limit
    zk = createClient(MAXSESS * 2);
    Assert.assertEquals(MAXSESS, zk.getSessionTimeout());
    LOG.info(zk.toString());
    zk.close();
    LOG.info(zk.toString());
  }
  @Override
  public void start() throws Exception {
    ServerConfig config = new ServerConfig();
    config.parse(new String[] {"2181", "zk"});

    zkServer = new ZooKeeperServer();
    zkServer.setTxnLogFactory(
        new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir())));
    zkServer.setTickTime(config.getTickTime());
    zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
  }
예제 #3
0
  public static void createAndStartZooKeeper()
      throws IOException, ConfigException, InterruptedException {
    ServerConfig zkConf = createZooKeeperConf();

    zooKeeper = new ZooKeeperServer();
    FileTxnSnapLog ftxn =
        new FileTxnSnapLog(new File(zkConf.getDataLogDir()), new File(zkConf.getDataDir()));
    zooKeeper.setTxnLogFactory(ftxn);
    zooKeeper.setTickTime(zkConf.getTickTime());
    zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
    zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());

    cnxnFactory =
        new NIOServerCnxn.Factory(zkConf.getClientPortAddress(), zkConf.getMaxClientCnxns());
    cnxnFactory.startup(zooKeeper);
  }