Java Code Examples for org.apache.zookeeper.server.ZooKeeperServer

The following examples show how to use org.apache.zookeeper.server.ZooKeeperServer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: RDFS   Source File: MiniAvatarCluster.java    License: Apache License 2.0 6 votes vote down vote up
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);

}
 
Example 2
Source Project: xian   Source File: ServerHelper.java    License: Apache License 2.0 6 votes vote down vote up
static Object       makeFactory(ZooKeeperServer server, int port) throws Exception
{
    Object      factory;
    if ( nioServerCnxn != null )
    {
        factory = nioServerCnxn.constructor.newInstance(new InetSocketAddress(port));
        if ( server != null )
        {
            nioServerCnxn.startupMethod.invoke(factory, server);
        }
    }
    else
    {
        factory = serverCnxnFactoryMethods.constructor.newInstance();
        serverCnxnFactoryMethods.configureMethod.invoke(factory, new InetSocketAddress(port), 0);
        if ( server != null )
        {
            serverCnxnFactoryMethods.startupMethod.invoke(factory, server);
        }
    }
    return factory;
}
 
Example 3
public CCEmbeddedZookeeper() {
  int tickTime = 500;
  try {
    File snapshotDir = CCKafkaTestUtils.newTempDir();
    File logDir = CCKafkaTestUtils.newTempDir();
    _zk = new ZooKeeperServer(snapshotDir, logDir, tickTime);
    _cnxnFactory = new NIOServerCnxnFactory();
    InetAddress localHost = InetAddress.getLocalHost();
    _hostAddress = localHost.getHostAddress();
    InetSocketAddress bindAddress = new InetSocketAddress(localHost, 0);
    _cnxnFactory.configure(bindAddress, 0);
    _cnxnFactory.startup(_zk);
    _port = _zk.getClientPort();
  } catch (Exception e) {
    throw new IllegalStateException(e);
  }
  //sanity check
  if (_zk.getClientPort() != _port) {
    throw new IllegalStateException();
  }
}
 
Example 4
Source Project: centraldogma   Source File: EmbeddedZooKeeper.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static DataTree dataTree(@Nullable EmbeddedZooKeeper peer) {
    if (peer == null) {
        return null;
    }

    final ZooKeeperServer activeServer = peer.getActiveServer();
    if (activeServer == null) {
        return null;
    }

    final ZKDatabase database = activeServer.getZKDatabase();
    if (database == null) {
        return null;
    }

    return database.getDataTree();
}
 
Example 5
Source Project: hadoop   Source File: TestCurrentInprogress.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  LOG.info("Starting ZK server");
  zkTmpDir = File.createTempFile("zookeeper", "test");
  zkTmpDir.delete();
  zkTmpDir.mkdir();
  try {
    zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }
  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example 6
Source Project: hadoop   Source File: TestBookKeeperConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  // create a ZooKeeper server(dataDir, dataLogDir, port)
  LOG.info("Starting ZK server");
  ZkTmpDir = File.createTempFile("zookeeper", "test");
  ZkTmpDir.delete();
  ZkTmpDir.mkdir();

  try {
    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }

  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example 7
Source Project: hadoop   Source File: ClientBaseWithFixes.java    License: Apache License 2.0 6 votes vote down vote up
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
 
Example 8
Source Project: hadoop   Source File: ClientBaseWithFixes.java    License: Apache License 2.0 6 votes vote down vote up
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);
    
            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
 
Example 9
public EmbeddedZookeeper() {
  try {
    snapshotDir = KafkaTestUtils.newTempDir();
    logDir = KafkaTestUtils.newTempDir();
    tickTime = 500;
    zk = new ZooKeeperServer(snapshotDir, logDir, tickTime);
    registerShutdownHandler(zk);
    cnxnFactory = new NIOServerCnxnFactory();
    InetAddress localHost = InetAddress.getLocalHost();
    hostAddress = localHost.getHostAddress();
    InetSocketAddress bindAddress = new InetSocketAddress(localHost, port);
    cnxnFactory.configure(bindAddress, 0);
    cnxnFactory.startup(zk);
    port = zk.getClientPort();
  } catch (Exception e) {
    throw new IllegalStateException(e);
  }
  //sanity check
  if (zk.getClientPort() != port) {
    throw new IllegalStateException();
  }
}
 
Example 10
/**
 * starting with ZK 3.4.9 there's a shutdown handler.
 * if one isnt registered ZK will spew errors at shutdown time, even though
 * both the handler interface and the method of registering one are not public API.
 * see https://issues.apache.org/jira/browse/ZOOKEEPER-2795
 * such craftsmanship. much wow.
 * @param zk a ZK server instance
 * @throws Exception if anything goes wrong
 */
private void registerShutdownHandler(ZooKeeperServer zk) throws Exception {
  Class<?> handlerClass;
  try {
    handlerClass = Class.forName("org.apache.zookeeper.server.ZooKeeperServerShutdownHandler");
  } catch (ClassNotFoundException e) {
    //older ZK. forget about it
    return;
  }
  Method registerMethod = ZooKeeperServer.class.getDeclaredMethod("registerServerShutdownHandler", handlerClass);
  Constructor<?> ctr = handlerClass.getDeclaredConstructor(CountDownLatch.class);
  ctr.setAccessible(true);
  shutdownLatch = new CountDownLatch(1);
  Object handlerInstance = ctr.newInstance(shutdownLatch);
  registerMethod.setAccessible(true);
  registerMethod.invoke(zk, handlerInstance);
}
 
Example 11
Source Project: big-c   Source File: TestCurrentInprogress.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  LOG.info("Starting ZK server");
  zkTmpDir = File.createTempFile("zookeeper", "test");
  zkTmpDir.delete();
  zkTmpDir.mkdir();
  try {
    zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }
  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example 12
Source Project: big-c   Source File: TestBookKeeperConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupZooKeeper() throws Exception {
  // create a ZooKeeper server(dataDir, dataLogDir, port)
  LOG.info("Starting ZK server");
  ZkTmpDir = File.createTempFile("zookeeper", "test");
  ZkTmpDir.delete();
  ZkTmpDir.mkdir();

  try {
    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), 10);
    serverFactory.startup(zks);
  } catch (Exception e) {
    LOG.error("Exception while instantiating ZooKeeper", e);
  }

  boolean b = LocalBookKeeper.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
  LOG.debug("ZooKeeper server up: " + b);
}
 
Example 13
Source Project: big-c   Source File: ClientBaseWithFixes.java    License: Apache License 2.0 6 votes vote down vote up
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
 
Example 14
Source Project: big-c   Source File: ClientBaseWithFixes.java    License: Apache License 2.0 6 votes vote down vote up
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);
    
            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
 
Example 15
Source Project: big-c   Source File: MiniZKFCCluster.java    License: Apache License 2.0 6 votes vote down vote up
public MiniZKFCCluster(Configuration conf, ZooKeeperServer zks) {
  this.conf = conf;
  // Fast check interval so tests run faster
  conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
  svcs = new DummyHAService[2];
  svcs[0] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc1", 1234));
  svcs[0].setSharedResource(sharedResource);
  svcs[1] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc2", 1234));
  svcs[1].setSharedResource(sharedResource);
  
  this.ctx = new TestContext();
  this.zks = zks;
}
 
Example 16
Source Project: pravega   Source File: ZooKeeperServiceRunner.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Starts the ZooKeeper Service in process.
 *
 * @throws Exception If an exception occurred.
 */
public void start() throws Exception {
    Preconditions.checkState(this.tmpDir.get() != null, "Not Initialized.");
    val s = new ZooKeeperServer(this.tmpDir.get(), this.tmpDir.get(), ZooKeeperServer.DEFAULT_TICK_TIME);
    if (!this.server.compareAndSet(null, s)) {
        s.shutdown();
        throw new IllegalStateException("Already started.");
    }
    this.serverFactory.set(NettyServerCnxnFactory.createFactory());
    val address = LOOPBACK_ADDRESS + ":" + this.zkPort;
    log.info("Starting Zookeeper server at " + address + " ...");
    this.serverFactory.get().configure(new InetSocketAddress(LOOPBACK_ADDRESS, this.zkPort), 1000, secureZK);
    this.serverFactory.get().startup(s);

    if (!waitForServerUp(this.zkPort, this.secureZK, this.keyStore, this.keyStorePasswordPath, this.trustStore,
            this.keyStorePasswordPath)) {
        throw new IllegalStateException("ZooKeeper server failed to start");
    }
}
 
Example 17
Source Project: vespa   Source File: ZooKeeperTestServer.java    License: Apache License 2.0 6 votes vote down vote up
private ZooKeeperTestServer(int port) throws IOException {
    zooKeeperDir = getTempDir();
    delete(zooKeeperDir);
    if (!zooKeeperDir.mkdir()) {
        throw new IllegalStateException("Failed to create directory " + zooKeeperDir);
    }
    zooKeeperDir.deleteOnExit();
    server = new ZooKeeperServer(zooKeeperDir, zooKeeperDir, (int)tickTime.toMillis());
    final int maxcc = 10000; // max number of connections from the same client
    factory = new NIOServerCnxnFactory();
    factory.configure(new InetSocketAddress(port), maxcc); // Use any port
    try{
        factory.startup(server);
    } catch (InterruptedException e) {
        throw (RuntimeException) new IllegalStateException("Interrupted during test startup: ").initCause(e);
    }
}
 
Example 18
Source Project: pulsar   Source File: ZookeeperServerTest.java    License: Apache License 2.0 6 votes vote down vote up
public void start() throws IOException {
    try {
        // Allow all commands on ZK control port
        System.setProperty("zookeeper.4lw.commands.whitelist", "*");
        // disable the admin server as to not have any port conflicts
        System.setProperty("zookeeper.admin.enableServer", "false");
        zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
        zks.setMaxSessionTimeout(20000);
        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(zkPort), 1000);
        serverFactory.startup(zks);
    } catch (Exception e) {
        log.error("Exception while instantiating ZooKeeper", e);
    }

    this.zkPort = serverFactory.getLocalPort();
    this.hostPort = "127.0.0.1:" + zkPort;

    LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000);
    log.info("ZooKeeper started at {}", hostPort);
}
 
Example 19
Source Project: ameliant-tools   Source File: EmbeddedZooKeeper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void before() throws Throwable {
    snapshotDir = tempDir(perTest("zk-snapshot"));
    logDir = tempDir(perTest("zk-log"));
    log.info("Setting up ZK Server with snapshotDir:{}, logDir:{}", snapshotDir, logDir);

    int tickTime = 500;
    try {
        zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime);
        cnxnFactory = new NIOServerCnxnFactory();
        cnxnFactory.configure(new InetSocketAddress("127.0.0.1", port), 0);
        cnxnFactory.startup(zooKeeperServer);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 20
Source Project: attic-apex-malhar   Source File: KafkaOperatorTestBase.java    License: Apache License 2.0 6 votes vote down vote up
public static void stopZookeeper()
{
  for (ZooKeeperServer zs : zkServer) {
    if (zs != null) {
      zs.shutdown();
    }
  }

  for (ServerCnxnFactory zkf : zkFactory) {
    if (zkf != null) {
      zkf.closeAll();
      zkf.shutdown();
    }
  }
  zkServer = new ZooKeeperServer[2];
  zkFactory = new ServerCnxnFactory[2];
}
 
Example 21
Source Project: attic-apex-malhar   Source File: KafkaOperatorTestBase.java    License: Apache License 2.0 6 votes vote down vote up
public static void stopZookeeper()
{
  for (ZooKeeperServer zs : zkServer) {
    if (zs != null) {
      zs.shutdown();
    }
  }

  for (ServerCnxnFactory zkf : zkFactory) {
    if (zkf != null) {
      zkf.closeAll();
      zkf.shutdown();
    }
  }
  zkServer = new ZooKeeperServer[2];
  zkFactory = new ServerCnxnFactory[2];
}
 
Example 22
/** */
private void shutdownServerInstance(ServerCnxnFactory factory)
{
    if (factory != null) {
        ZKDatabase zkDb = null;
        {
            ZooKeeperServer zs = getServer(factory);
            if (zs != null)
                zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            if (zkDb != null)
                zkDb.close();
        } catch (IOException ie) {
            // ignore
        }
    }
}
 
Example 23
Source Project: logback-kafka-appender   Source File: EmbeddedZookeeper.java    License: Apache License 2.0 6 votes vote down vote up
public void startup() throws IOException{
    if (this.port == -1) {
        this.port = TestUtils.getAvailablePort();
    }
    this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
    this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot");
    this.logDir = TestUtils.constructTempDir("embeeded-zk/log");
    final ZooKeeperServer zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime);
    try {
        factory.startup(zooKeeperServer);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
    assertEquals("standalone", zooKeeperServer.getState());
    assertEquals(this.port, zooKeeperServer.getClientPort());

}
 
Example 24
Source Project: karaf-decanter   Source File: EmbeddedZooKeeper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void before() throws IOException {
    snapshotDir = new File("target/test-classes/zk-snapshot");
    snapshotDir.mkdirs();
    logDir = new File("target/test-classes/zk-log");
    logDir.mkdirs();

    try {
        zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime);
        cnxnFactory = new NIOServerCnxnFactory();
        cnxnFactory.configure(new InetSocketAddress("localhost", port), 1024);
        cnxnFactory.startup(zooKeeperServer);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
 
Example 25
Source Project: curator   Source File: ServerHelper.java    License: Apache License 2.0 6 votes vote down vote up
static Object       makeFactory(ZooKeeperServer server, int port) throws Exception
{
    Object      factory;
    if ( nioServerCnxn != null )
    {
        factory = nioServerCnxn.constructor.newInstance(new InetSocketAddress(port));
        if ( server != null )
        {
            nioServerCnxn.startupMethod.invoke(factory, server);
        }
    }
    else
    {
        factory = serverCnxnFactoryMethods.constructor.newInstance();
        serverCnxnFactoryMethods.configureMethod.invoke(factory, new InetSocketAddress(port), 0);
        if ( server != null )
        {
            serverCnxnFactoryMethods.startupMethod.invoke(factory, server);
        }
    }
    return factory;
}
 
Example 26
Source Project: camel-spring-boot   Source File: ZookeeperServer.java    License: Apache License 2.0 5 votes vote down vote up
public ZookeeperServer(File root) throws IOException, InterruptedException {
    zkServer = new ZooKeeperServer();

    File dataDir = new File(root, "log");
    File snapDir = new File(root, "data");
    FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir);

    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(1000);

    connectionFactory = new NIOServerCnxnFactory();
    connectionFactory.configure(new InetSocketAddress("localhost", SocketUtils.findAvailableTcpPort()), 0);
    connectionFactory.startup(zkServer);
}
 
Example 27
Source Project: waltz   Source File: SmokeTest.java    License: Apache License 2.0 5 votes vote down vote up
private RunnerScheduler<ZooKeeperServer> scheduleZooKeeper(int id, long upDuration, long downDuration) throws Exception {
    Runner<ZooKeeperServer> runner = helper.getZooKeeperServerRunner();
    return new RunnerScheduler<ZooKeeperServer>("ZooKeeper", runner, upDuration, downDuration) {
        @Override
        protected void onServerStart() {
            clusterStateChanged(name, id, '*');
        }

        @Override
        protected void onServerStop() {
            clusterStateChanged(name, id, '.');
        }
    };
}
 
Example 28
Source Project: nifi   Source File: EmbeddedKafka.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Will create instance of the embedded Kafka server.
 *
 * @param kafkaConfig
 *            Kafka configuration properties
 * @param zookeeperConfig
 *            Zookeeper configuration properties
 */
public EmbeddedKafka(Properties kafkaConfig, Properties zookeeperConfig) {
    this.cleanupKafkaWorkDir();
    this.zookeeperConfig = zookeeperConfig;
    this.kafkaConfig = kafkaConfig;
    this.kafkaPort = this.availablePort();
    this.zookeeperPort = this.availablePort();

    this.kafkaConfig.setProperty("port", String.valueOf(this.kafkaPort));
    this.kafkaConfig.setProperty("zookeeper.connect", "localhost:" + this.zookeeperPort);
    this.zookeeperConfig.setProperty("clientPort", String.valueOf(this.zookeeperPort));
    this.zkServer = new ZooKeeperServer();
    this.kafkaServer = new KafkaServerStartable(new KafkaConfig(kafkaConfig));
}
 
Example 29
Source Project: localization_nifi   Source File: EmbeddedKafka.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Will create instance of the embedded Kafka server.
 *
 * @param kafkaConfig
 *            Kafka configuration properties
 * @param zookeeperConfig
 *            Zookeeper configuration properties
 */
public EmbeddedKafka(Properties kafkaConfig, Properties zookeeperConfig) {
    this.cleanupKafkaWorkDir();
    this.zookeeperConfig = zookeeperConfig;
    this.kafkaConfig = kafkaConfig;
    this.kafkaPort = this.availablePort();
    this.zookeeperPort = this.availablePort();

    this.kafkaConfig.setProperty("port", String.valueOf(this.kafkaPort));
    this.kafkaConfig.setProperty("zookeeper.connect", "localhost:" + this.zookeeperPort);
    this.zookeeperConfig.setProperty("clientPort", String.valueOf(this.zookeeperPort));
    this.zkServer = new ZooKeeperServer();
    this.kafkaServer = new KafkaServerStartable(new KafkaConfig(kafkaConfig));
}
 
Example 30
Source Project: curator   Source File: ChaosMonkeyCnxnFactory.java    License: Apache License 2.0 5 votes vote down vote up
public ChaosMonkeyZookeeperServer(ZooKeeperServer zks)
{
    this.zks = zks;
    setTxnLogFactory(zks.getTxnLogFactory());
    setTickTime(zks.getTickTime());
    setMinSessionTimeout(zks.getMinSessionTimeout());
    setMaxSessionTimeout(zks.getMaxSessionTimeout());
}