use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.
the class GroupTest method testAddFieldIgnoredOnParse.
@Test
public void testAddFieldIgnoredOnParse() throws Exception {
int port = findFreePort();
NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
String groupNode = "/singletons/test" + System.currentTimeMillis();
curator.create().creatingParentsIfNeeded().forPath(groupNode);
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
final ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, groupNode, NodeState.class);
group.add(listener);
group.start();
GroupCondition groupCondition = new GroupCondition();
group.add(groupCondition);
group.update(new NodeState("foo"));
assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
ChildData currentData = group.getCurrentData().get(0);
final int version = currentData.getStat().getVersion();
NodeState lastState = group.getLastState();
String json = lastState.toString();
System.err.println("JSON:" + json);
String newValWithNewField = json.substring(0, json.lastIndexOf('}')) + ",\"Rubbish\":\"Rubbish\"}";
curator.getZookeeperClient().getZooKeeper().setData(group.getId(), newValWithNewField.getBytes(), version);
assertTrue(group.isMaster());
int attempts = 0;
while (attempts++ < 5 && version == group.getCurrentData().get(0).getStat().getVersion()) {
TimeUnit.SECONDS.sleep(1);
}
assertNotEquals("We see the updated version", version, group.getCurrentData().get(0).getStat().getVersion());
System.err.println("CurrentData:" + group.getCurrentData());
group.close();
curator.close();
cnxnFactory.shutdown();
cnxnFactory.join();
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project pulsar by yahoo.
the class ZookeeperServerTest method start.
public void start() throws IOException {
try {
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);
}
LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000);
log.info("ZooKeeper started at {}", hostPort);
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project fabric8 by jboss-fuse.
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 fabric8 by jboss-fuse.
the class ZookeeperPortServiceTest method startZooKeeper.
private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
String testDirectory = "target/zk-ports/data" + System.currentTimeMillis();
FileUtils.deleteDirectory(new File(testDirectory));
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), testDirectory });
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(cfg.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
cnxnFactory.startup(zkServer);
return cnxnFactory;
}
use of org.apache.zookeeper.server.NIOServerCnxnFactory in project bookkeeper by apache.
the class ZooKeeperUtil method restartServer.
public void restartServer() throws Exception {
zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(zkaddr, 100);
serverFactory.startup(zks);
if (0 == zooKeeperPort) {
zooKeeperPort = serverFactory.getLocalPort();
zkaddr = new InetSocketAddress(zkaddr.getHostName(), zooKeeperPort);
connectString = zkaddr.getHostName() + ":" + zooKeeperPort;
}
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()).sessionTimeoutMs(10000).build();
}
Aggregations