use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class LoadFromLogTest method testDatadirAutocreate.
/**
* Verify snap/log dir create with/without autocreate enabled.
*/
@Test
public void testDatadirAutocreate() throws Exception {
ClientBase.setupTestEnv();
final String hostPort = HOST + PortAssignment.unique();
// first verify the default (autocreate on) works
File tmpDir = ClientBase.createTmpDir();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
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));
zks.shutdown();
f.shutdown();
Assert.assertTrue("waiting for server being down ", ClientBase.waitForServerDown(hostPort, CONNECTION_TIMEOUT));
try {
// now verify autocreate off works
System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "false");
tmpDir = ClientBase.createTmpDir();
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
Assert.assertTrue("waiting for server being up ", ClientBase.waitForServerUp(hostPort, CONNECTION_TIMEOUT));
Assert.fail("Server should not have started without datadir");
} catch (IOException e) {
LOG.info("Server failed to start - correct behavior " + e);
} finally {
System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE_DEFAULT);
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project hadoop by apache.
the class ClientBaseWithFixes method shutdownServerInstance.
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) {
if (factory != null) {
ZKDatabase zkDb;
{
ZooKeeperServer zs = getServer(factory);
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
final int PORT = getPort(hostPort);
Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project hadoop by apache.
the class TestActiveStandbyElectorRealZK method testHandleSessionExpiration.
@Test(timeout = 15000)
public void testHandleSessionExpiration() throws Exception {
ActiveStandbyElectorCallback cb = cbs[0];
byte[] appData = appDatas[0];
ActiveStandbyElector elector = electors[0];
// Let the first elector become active
elector.ensureParentZNode();
elector.joinElection(appData);
ZooKeeperServer zks = getServer(serverFactory);
ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zks, PARENT_DIR, appData);
Mockito.verify(cb, Mockito.timeout(1000)).becomeActive();
checkFatalsAndReset();
LOG.info("========================== Expiring session");
zks.closeSession(elector.getZKSessionIdForTests());
// Should enter neutral mode when disconnected
Mockito.verify(cb, Mockito.timeout(1000)).enterNeutralMode();
// Should re-join the election and regain active
ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zks, PARENT_DIR, appData);
Mockito.verify(cb, Mockito.timeout(1000)).becomeActive();
checkFatalsAndReset();
LOG.info("========================== Quitting election");
elector.quitElection(false);
ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zks, PARENT_DIR, null);
// Double check that we don't accidentally re-join the election
// due to receiving the "expired" event.
Thread.sleep(1000);
Mockito.verify(cb, Mockito.never()).becomeActive();
ActiveStandbyElectorTestUtil.waitForActiveLockData(null, zks, PARENT_DIR, null);
checkFatalsAndReset();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project deeplearning4j 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);
}
}
use of org.apache.zookeeper.server.ZooKeeperServer 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);
}
Aggregations