use of org.apache.zookeeper.server.ZooKeeperServer in project fabric8 by jboss-fuse.
the class ZookeeperServerTestSupport method startZooKeeper.
protected NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), "target/zk/data-" + String.format("%15d", new Date().getTime()) });
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.ZooKeeperServer in project fabric8 by jboss-fuse.
the class GitDataStoreImplTestSupport method startZooKeeper.
private NIOServerCnxnFactory startZooKeeper(int port, String directory) throws Exception {
ServerConfig cfg = new ServerConfig();
cfg.parse(new String[] { Integer.toString(port), directory });
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.ZooKeeperServer in project strimzi by strimzi.
the class EmbeddedZooKeeper method restart.
public void restart() throws IOException, InterruptedException {
if (zk != null) {
zk.shutdown(false);
}
// Reuse the existing port
InetSocketAddress addr = factory.getLocalAddress();
factory.shutdown();
zk = new ZooKeeperServer(dir, dir, 1000);
start(addr);
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class FuzzySnapshotRelatedTest method testMultiOpDigestConsistentDuringSnapshot.
@Test
public void testMultiOpDigestConsistentDuringSnapshot() throws Exception {
ServerMetrics.getMetrics().resetAll();
LOG.info("Create some txns");
final String path = "/testMultiOpDigestConsistentDuringSnapshot";
createEmptyNode(zk[followerA], path, CreateMode.PERSISTENT);
CustomDataTree dt = (CustomDataTree) mt[followerA].main.quorumPeer.getZkDb().getDataTree();
final CountDownLatch setDataLatch = new CountDownLatch(1);
final CountDownLatch continueSetDataLatch = new CountDownLatch(1);
final ZooKeeper followerZk = zk[followerA];
dt.setDigestSerializeListener(new DigestSerializeListener() {
@Override
public void process() {
LOG.info("Trigger a multi op in async");
followerZk.multi(Arrays.asList(Op.create("/multi0", "/multi0".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.setData(path, "new data".getBytes(), -1)), new MultiCallback() {
@Override
public void processResult(int rc, String path, Object ctx, List<OpResult> opResults) {
}
}, null);
LOG.info("Wait for the signal to continue");
try {
setDataLatch.await(3, TimeUnit.SECONDS);
} catch (Exception e) {
LOG.error("Error while waiting for set data txn, {}", e);
}
}
@Override
public void finished() {
LOG.info("Finished writing digest out, continue");
continueSetDataLatch.countDown();
}
});
dt.setDataListener(new SetDataTxnListener() {
@Override
public void process() {
setDataLatch.countDown();
try {
continueSetDataLatch.await(3, TimeUnit.SECONDS);
} catch (Exception e) {
LOG.error("Error while waiting for continue signal, {}", e);
}
}
});
LOG.info("Trigger a snapshot");
ZooKeeperServer zkServer = mt[followerA].main.quorumPeer.getActiveServer();
zkServer.takeSnapshot(true);
checkNoMismatchReported();
LOG.info("Restart the server to load the snapshot again");
mt[followerA].shutdown();
QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTING);
mt[followerA].start();
QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTED);
LOG.info("Make sure there is nothing caught in the digest mismatch");
checkNoMismatchReported();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class FuzzySnapshotRelatedTest method testMultiOpConsistency.
@Test
public void testMultiOpConsistency() throws Exception {
LOG.info("Create a parent node");
final String path = "/testMultiOpConsistency";
createEmptyNode(zk[followerA], path, CreateMode.PERSISTENT);
LOG.info("Hook to catch the 2nd sub create node txn in multi-op");
CustomDataTree dt = (CustomDataTree) mt[followerA].main.quorumPeer.getZkDb().getDataTree();
final ZooKeeperServer zkServer = mt[followerA].main.quorumPeer.getActiveServer();
String node1 = path + "/1";
String node2 = path + "/2";
dt.addNodeCreateListener(node2, new NodeCreateListener() {
@Override
public void process(String path) {
LOG.info("Take a snapshot");
zkServer.takeSnapshot(true);
}
});
LOG.info("Issue a multi op to create 2 nodes");
zk[followerA].multi(Arrays.asList(Op.create(node1, node1.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create(node2, node2.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)));
LOG.info("Restart the server");
mt[followerA].shutdown();
QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTING);
mt[followerA].start();
QuorumPeerMainTest.waitForOne(zk[followerA], States.CONNECTED);
LOG.info("Make sure the node consistent with leader");
assertEquals(new String(zk[leaderId].getData(node2, null, null)), new String(zk[followerA].getData(node2, null, null)));
}
Aggregations