use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class RestoreCommittedLogTest method testRestoreCommittedLog.
/**
* test the purge
* @throws Exception an exception might be thrown here
*/
@Test
public void testRestoreCommittedLog() throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
SyncRequestProcessor.setSnapCount(100);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
Assert.assertTrue("waiting for server being up ", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
for (int i = 0; i < 2000; i++) {
zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} finally {
zk.close();
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server to shutdown", ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
// start server again
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
zks.startdata();
List<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();
int logsize = committedLog.size();
LOG.info("committedLog size = {}", logsize);
Assert.assertTrue("log size != 0", (logsize != 0));
zks.shutdown();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project nifi by apache.
the class ZooKeeperStateServer method startStandalone.
private void startStandalone() throws IOException {
logger.info("Starting Embedded ZooKeeper Server");
final ServerConfig config = new ServerConfig();
config.readFrom(quorumPeerConfig);
try {
transactionLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir()));
embeddedZkServer = new ZooKeeperServer();
embeddedZkServer.setTxnLogFactory(transactionLog);
embeddedZkServer.setTickTime(config.getTickTime());
embeddedZkServer.setMinSessionTimeout(config.getMinSessionTimeout());
embeddedZkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
connectionFactory = ServerCnxnFactory.createFactory();
connectionFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
connectionFactory.startup(embeddedZkServer);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.warn("Embedded ZooKeeper Server interrupted", e);
} catch (final IOException ioe) {
throw new IOException("Failed to start embedded ZooKeeper Server", ioe);
} catch (final Exception e) {
throw new RuntimeException("Failed to start embedded ZooKeeper Server", e);
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project camel by apache.
the class EmbeddedZookeeper method before.
@Override
public void before() throws IOException {
this.snapshotDir = constructTempDir(perTest("zk-snapshot"));
this.logDir = constructTempDir(perTest("zk-log"));
try {
zooKeeperServer = new ZooKeeperServer(snapshotDir, logDir, tickTime);
cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(new InetSocketAddress("localhost", port), 1024);
cnxnFactory.startup(zooKeeperServer);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project bookkeeper by apache.
the class ZooKeeperServerShimImpl method initialize.
@Override
public void initialize(File snapDir, File logDir, int zkPort, int maxCC) throws IOException {
zks = new ZooKeeperServer(snapDir, logDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(zkPort), maxCC);
}
use of org.apache.zookeeper.server.ZooKeeperServer in project nd4j by deeplearning4j.
the class EmbeddedZookeeper method startup.
public void startup() throws IOException {
if (this.port == -1) {
this.port = TestUtils.getAvailablePort();
}
this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot");
this.logDir = TestUtils.constructTempDir("embeeded-zk/log");
try {
factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
} catch (InterruptedException e) {
throw new IOException(e);
}
}
Aggregations