@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); zkServer.startAndWait(); zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); }
@AfterClass public static void finish() { zkServer.stopAndWait(); } }
/** * Returns the number of client connections to the zk server */ private int getZKConnections() throws IOException { InetSocketAddress zkAddr = zkServer.getLocalAddress(); try (Socket socket = new Socket(zkAddr.getAddress(), zkAddr.getPort())) { socket.getOutputStream().write("cons".getBytes(StandardCharsets.ISO_8859_1)); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.ISO_8859_1)); String line = reader.readLine(); int count = 0; while (line != null) { count++; line = reader.readLine(); } return count; } }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); zkServer.startAndWait(); }
inMemoryZKServer.startAndWait(); zkClientService = getZKService(inMemoryZKServer.getConnectionStr());
@Test public void testClientConnectionPoolMaximumNumberOfClients() throws Exception { InMemoryZKServer zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); zkServer.startAndWait(); conf.set(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM, zkServer.getConnectionStr()); conf.set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, tmpFolder.newFolder().getAbsolutePath()); conf.set("data.tx.client.count", Integer.toString(MAX_CLIENT_COUNT)); zkServer.stopAndWait();
public String getZKConnectionString() { return zkServer.getConnectionStr(); }
@Override public void init(String[] args) { try { conf = Configuration.create(); cConf = CConfiguration.create(); cConf.addResource("coopr-default.xml"); cConf.addResource("coopr-site.xml"); securityEnabled = conf.getBoolean(co.cask.cdap.common.conf.Constants.Security.ENABLED); if (securityEnabled) { // Enable Kerberos login SecurityUtil.enableKerberosLogin(cConf); } String zkQuorum = conf.get(Constants.ZOOKEEPER_QUORUM); if (zkQuorum == null) { String dataPath = conf.get(Constants.LOCAL_DATA_DIR) + "/zookeeper"; inMemoryZKServer = InMemoryZKServer.builder().setDataDir(new File(dataPath)).setTickTime(2000).build(); LOG.warn(Constants.ZOOKEEPER_QUORUM + " not specified, defaulting to in memory zookeeper with data dir " + dataPath); } else { zkClientService = getZKService(conf.get(Constants.ZOOKEEPER_QUORUM)); } solverNumThreads = conf.getInt(Constants.SOLVER_NUM_THREADS); } catch (Exception e) { LOG.error("Exception initializing server", e); } }
@Test public void testClientServer() throws Exception { InMemoryZKServer zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build(); zkServer.startAndWait(); conf.set(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM, zkServer.getConnectionStr()); conf.set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, tmpFolder.newFolder().getAbsolutePath()); zkServer.stopAndWait();
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); }
private Properties generateKafkaConfig() throws IOException { Properties properties = new Properties(); properties.setProperty("broker.id", "1"); properties.setProperty("host.name", InetAddress.getLoopbackAddress().getHostAddress()); properties.setProperty("port", "0"); properties.setProperty("num.network.threads", "2"); properties.setProperty("num.io.threads", "2"); properties.setProperty("socket.send.buffer.bytes", "1048576"); properties.setProperty("socket.receive.buffer.bytes", "1048576"); properties.setProperty("socket.request.max.bytes", "104857600"); properties.setProperty("log.dir", tmpFolder.newFolder().getAbsolutePath()); properties.setProperty("num.partitions", String.valueOf(numPartitions)); properties.setProperty("log.flush.interval.messages", "10000"); properties.setProperty("log.flush.interval.ms", "1000"); properties.setProperty("log.retention.hours", "1"); properties.setProperty("log.segment.bytes", "536870912"); properties.setProperty("log.cleanup.interval.mins", "1"); properties.setProperty("zookeeper.connect", zkServer.getConnectionStr()); properties.setProperty("zookeeper.connection.timeout.ms", "1000000"); return properties; }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath()); }
@Test (timeout = 10000) public void testDisconnect() throws IOException, InterruptedException { File zkDataDir = tmpFolder.newFolder(); InMemoryZKServer ownZKServer = InMemoryZKServer.builder().setDataDir(zkDataDir).build(); ownZKServer.startAndWait(); try { ZKClientService zkClient = ZKClientService.Builder.of(ownZKServer.getConnectionStr()).build(); zkClient.startAndWait(); int zkPort = ownZKServer.getLocalAddress().getPort(); ownZKServer.stopAndWait(); ownZKServer = InMemoryZKServer.builder().setDataDir(zkDataDir).setPort(zkPort).build(); ownZKServer.startAndWait(); ownZKServer.stopAndWait(); ownZKServer = InMemoryZKServer.builder().setDataDir(zkDataDir).setPort(zkPort).build(); ownZKServer.startAndWait(); ownZKServer.stopAndWait();
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); }
/** * Creates a topic with the given number of partitions. */ public void createTopic(String topic, int partitions) { AdminUtils.createTopic(new ZkClient(zkServer.getConnectionStr(), 20000, 2000, ZKStringSerializer$.MODULE$), topic, partitions, 1, new Properties()); } }
@AfterClass public static void finish() { zkServer.stopAndWait(); } }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); CConfiguration cConf = CConfiguration.create(); cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr()); Injector injector = Guice.createInjector(new ConfigModule(cConf), new ZKClientModule()); zkClientService = injector.getInstance(ZKClientService.class); zkClientService.startAndWait(); }
@BeforeClass public static void init() throws IOException { zkServer = InMemoryZKServer.builder().setDataDir(TMP_FOLDER.newFolder()).build(); zkServer.startAndWait(); }
@Override protected void startUp() throws Exception { ZooKeeperServer zkServer = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, dataDir); zkServer.setTxnLogFactory(ftxn); zkServer.setTickTime(tickTime); factory = ServerCnxnFactory.createFactory(); factory.configure(getAddress(port), -1); factory.startup(zkServer); LOG.info("In memory ZK started: " + getConnectionStr()); }
@AfterClass public static void finish() { zkServer.stopAndWait(); }