standaloneServerFactory.startup(server);
public void startServer() throws Exception { // create a ZooKeeper server(dataDir, dataLogDir, port) LOG.debug("Running ZK server"); // ServerStats.registerAsConcrete(); ClientBase.setupTestEnv(); ZkTmpDir = File.createTempFile("zookeeper", "test"); ZkTmpDir.delete(); ZkTmpDir.mkdir(); zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME); serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(zkaddr, 100); serverFactory.startup(zks); boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT); LOG.debug("Server up: " + b); // create a zookeeper client LOG.debug("Instantiate ZK Client"); zkc = ZooKeeperClient.newBuilder().connectString(getZooKeeperConnectString()).build(); // initialize the zk client with values zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); }
standaloneServerFactory.startup(server);
EmbeddedZooKeeper() throws IOException, InterruptedException { this.tmpDir = Files.createTempDirectory(null).toFile(); this.factory = new NIOServerCnxnFactory(); this.zookeeper = new ZooKeeperServer(new File(tmpDir, "data"), new File(tmpDir, "log"), TICK_TIME); InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 0); factory.configure(addr, 0); factory.startup(zookeeper); this.port = zookeeper.getClientPort(); }
@Override public void start() throws IOException { if (null == zks || null == serverFactory) { throw new IOException("Start zookeeper server before initialization."); } try { serverFactory.startup(zks); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException("Interrupted when starting zookeeper server : ", e); } }
public EmbeddedZkServer(int port) throws Exception { snapshotDir = Files.createTempDirectory("zookeeper-snapshot-"); logDir = Files.createTempDirectory("zookeeper-log-"); int tickTime = 500; zookeeper = new ZooKeeperServer(snapshotDir.toFile(), logDir.toFile(), tickTime); factory = new NIOServerCnxnFactory(); InetSocketAddress addr = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port); LOGGER.info("Starting Zookeeper at " + addr); factory.configure(addr, 0); factory.startup(zookeeper); }
public EmbeddedZookeeper startup(int timeout, TimeUnit unit) throws Exception { connectionFactory.startup(zkServer); if (timeout > 0) { waitForServerUp(getConnection(), unit.toMillis(timeout)); } return this; }
public EmbeddedZookeeper(int port) throws Exception { this.port = port; zookeeper = new ZooKeeperServer(snapshotDir, logDir, tickTime); addr = new InetSocketAddress("127.0.0.1", port); factory.configure(addr, 0); factory.startup(zookeeper); }
public void start() throws InterruptedException, IOException { if (!started.getAndSet(true)) { cnxnFactory.startup(zkServer); } }
public EmbeddedZookeeper startup(int timeout, TimeUnit unit) throws Exception { connectionFactory.startup(zkServer); if (timeout > 0) { waitForServerUp(getConnection(), unit.toMillis(timeout)); } return this; }
private void start(InetSocketAddress addr) throws IOException, InterruptedException { factory = new NIOServerCnxnFactory(); factory.configure(addr, 20); factory.startup(zk); }
public void run() throws Exception { File dir = new File(dataDirectory, "zookeeper").getAbsoluteFile(); NIOServerCnxnFactory factory = new NIOServerCnxnFactory(); ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTime); factory.setZooKeeperServer(server); factory.setMaxClientCnxnsPerHost(numConnections); factory.configure(new InetSocketAddress(clientPort), numConnections); factory.startup(server); }
/** * Constructs an embedded Zookeeper instance. * * @param connectString Zookeeper connection string. * * @throws IOException if an error occurs during Zookeeper initialization. */ public EmbeddedZookeeper(String connectString) throws IOException { this.snapshotDir = KafkaTestUtils.getTempDir(); this.logDir = KafkaTestUtils.getTempDir(); this.factory = new NIOServerCnxnFactory(); String hostname = connectString.split(":")[0]; int port = Integer.parseInt(connectString.split(":")[1]); int maxClientConnections = 1024; factory.configure(new InetSocketAddress(hostname, port), maxClientConnections); try { int tickTime = 500; factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime)); } catch (InterruptedException e) { throw new IOException(e); } }
public EmbeddedZookeeperInternal(int port) throws IOException, InterruptedException { this.port = port; logDir = TestUtils.tempDir(); snapshotDir = TestUtils.tempDir(); zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, 500); nioServerCnxnFactory = new NIOServerCnxnFactory(); InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", port); nioServerCnxnFactory.configure(inetSocketAddress, 0); nioServerCnxnFactory.startup(zooKeeperServer); }
private static void startZooKeeperServer() throws IOException, InterruptedException { String zooLocation = System.getProperty("java.io.tmpdir"); File zooFile = new File(zooLocation, "zookeeper-malhartest"); ZooKeeperServer zooKeeper = new ZooKeeperServer(zooFile, zooFile, 2000); NIOServerCnxnFactory serverFactory = new NIOServerCnxnFactory(); serverFactory.configure(new InetSocketAddress(2181),10); serverFactory.startup(zooKeeper); }
private void startSingleZkServer(final int tickTime, final File dataDir, final File dataLogDir, final int port) { try { _zk = new ZooKeeperServer(dataDir, dataLogDir, tickTime); _zk.setMinSessionTimeout(_minSessionTimeout); _nioFactory = new NIOServerCnxnFactory(); int maxClientConnections = 0; // 0 means unlimited _nioFactory.configure(new InetSocketAddress(port), maxClientConnections); _nioFactory.startup(_zk); } catch (IOException e) { throw new ZkException("Unable to start single ZooKeeper server.", e); } catch (InterruptedException e) { throw new ZkInterruptedException(e); } }
@Before public void setUp() throws Exception { zkDir = Files.createTempDir().getAbsoluteFile(); zkPort = Utils.getFreePorts(1)[0]; ZooKeeperServer zkServer = new ZooKeeperServer(zkDir, zkDir, 2000); standaloneServerFactory = new NIOServerCnxnFactory(); standaloneServerFactory.configure(new InetSocketAddress(zkPort.value), 5000); standaloneServerFactory.startup(zkServer); }
public void afterPropertiesSet() throws Exception { if( purge ) { deleteFilesInDir(getDataLogDir()); deleteFilesInDir(getDataDir()); } FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir()); zooKeeperServer.setTxnLogFactory(ftxn); zooKeeperServer.setTickTime(getTickTime()); zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout()); zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout()); connectionFactory = new NIOServerCnxnFactory(); connectionFactory.configure(getClientPortAddress(), getMaxClientConnections()); connectionFactory.startup(zooKeeperServer); }
public void afterPropertiesSet() throws Exception { if( purge ) { deleteFilesInDir(getDataLogDir()); deleteFilesInDir(getDataDir()); } FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir()); zooKeeperServer.setTxnLogFactory(ftxn); zooKeeperServer.setTickTime(getTickTime()); zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout()); zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout()); connectionFactory = new NIOServerCnxnFactory(); connectionFactory.configure(getClientPortAddress(), getMaxClientConnections()); connectionFactory.startup(zooKeeperServer); }
public void afterPropertiesSet() throws Exception { if( purge ) { deleteFilesInDir(getDataLogDir()); deleteFilesInDir(getDataDir()); } FileTxnSnapLog ftxn = new FileTxnSnapLog(getDataLogDir(), getDataDir()); zooKeeperServer.setTxnLogFactory(ftxn); zooKeeperServer.setTickTime(getTickTime()); zooKeeperServer.setMinSessionTimeout(getMinSessionTimeout()); zooKeeperServer.setMaxSessionTimeout(getMaxSessionTimeout()); connectionFactory = new NIOServerCnxnFactory(); connectionFactory.configure(getClientPortAddress(), getMaxClientConnections()); connectionFactory.startup(zooKeeperServer); }