use of org.apache.zookeeper.server.NIOServerCnxnFactory in project apex-malhar by apache.
the class KafkaOperatorTestBase method startZookeeper.
public static void startZookeeper(final int clusterId) {
try {
int numConnections = 100;
int tickTime = 2000;
File dir = new File(baseDir, zkdir[clusterId]);
zkServer[clusterId] = new TestZookeeperServer(dir, dir, tickTime);
zkFactory[clusterId] = new NIOServerCnxnFactory();
zkFactory[clusterId].configure(new InetSocketAddress(TEST_ZOOKEEPER_PORT[clusterId]), numConnections);
// start the zookeeper server.
zkFactory[clusterId].startup(zkServer[clusterId]);
Thread.sleep(2000);
// kserver.startup();
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
}
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project apex-malhar by apache.
the class KafkaOperatorTestBase method startZookeeper.
public void startZookeeper(final int clusterId) {
try {
// before start, clean the zookeeper files if it exists
FileUtils.deleteQuietly(new File(baseDir, zkBaseDir));
int clientPort = TEST_ZOOKEEPER_PORT[clusterId];
int numConnections = 10;
int tickTime = 2000;
File dir = new File(baseDir, zkdir[clusterId]);
TestZookeeperServer kserver = new TestZookeeperServer(dir, dir, tickTime);
zkFactory[clusterId] = new NIOServerCnxnFactory();
zkFactory[clusterId].configure(new InetSocketAddress(clientPort), numConnections);
// start the zookeeper server.
zkFactory[clusterId].startup(kserver);
Thread.sleep(2000);
kserver.startup();
} catch (Exception ex) {
logger.debug(ex.getLocalizedMessage());
}
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
the class GroupTest method testOrder.
@Test
public void testOrder() throws Exception {
int port = findFreePort();
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
final String path = "/singletons/test/Order" + System.currentTimeMillis();
ArrayList<ZooKeeperGroup> members = new ArrayList<ZooKeeperGroup>();
for (int i = 0; i < 4; i++) {
ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, path, NodeState.class);
group.add(listener);
members.add(group);
}
for (ZooKeeperGroup group : members) {
assertFalse(group.isConnected());
assertFalse(group.isMaster());
}
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
// first to start should be master if members are ordered...
int i = 0;
for (ZooKeeperGroup group : members) {
group.start();
group.update(new NodeState("foo" + i));
i++;
// wait for registration
while (group.getId() == null) {
TimeUnit.MILLISECONDS.sleep(100);
}
}
boolean firsStartedIsMaster = members.get(0).isMaster();
for (ZooKeeperGroup group : members) {
group.close();
}
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
assertTrue("first started is master", firsStartedIsMaster);
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
the class GroupTest method startZooKeeper.
private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), "target/zk/data" });
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
zkServer.setTxnLogFactory(ftxn);
zkServer.setTickTime(cfg.getTickTime());
zkServer.setMinSessionTimeout(6000);
zkServer.setMaxSessionTimeout(9000);
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
return cnxnFactory;
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hadoop by apache.
the class TestZKClient method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
System.setProperty("zookeeper.preAllocSize", "100");
FileTxnLog.setPreallocSize(100 * 1024);
if (!BASETEST.exists()) {
BASETEST.mkdirs();
}
File dataDir = createTmpDir(BASETEST);
zks = new ZooKeeperServer(dataDir, dataDir, 3000);
final int PORT = Integer.parseInt(hostPort.split(":")[1]);
if (factory == null) {
factory = new NIOServerCnxnFactory();
factory.configure(new InetSocketAddress(PORT), maxCnxns);
}
factory.startup(zks);
Assert.assertTrue("waiting for server up", waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
}
Aggregations