use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class RepeatStartupTest method testFail.
/**
* bring up 5 quorum peers and then shut them down
* and then bring one of the nodes as server
*
* @throws Exception might be thrown here
*/
@Test
public void testFail() throws Exception {
QuorumBase qb = new QuorumBase();
qb.setUp();
System.out.println("Comment: the servers are at " + qb.hostPort);
ZooKeeper zk = qb.createClient();
zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
QuorumBase.shutdown(qb.s1);
QuorumBase.shutdown(qb.s2);
QuorumBase.shutdown(qb.s3);
QuorumBase.shutdown(qb.s4);
QuorumBase.shutdown(qb.s5);
String hp = qb.hostPort.split(",")[0];
ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(), qb.s1.getTxnFactory().getDataDir(), 3000);
final int PORT = Integer.parseInt(hp.split(":")[1]);
ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1);
factory.startup(zks);
System.out.println("Comment: starting factory");
assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + PORT, QuorumTest.CONNECTION_TIMEOUT), "waiting for server up");
factory.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + PORT, QuorumTest.CONNECTION_TIMEOUT), "waiting for server down");
System.out.println("Comment: shutting down standalone");
}
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
*/
private void testRestoreCommittedLog(int totalTransactions, byte[] data, int minExpectedSnapshots) throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up ");
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
for (int i = 0; i < totalTransactions; i++) {
zk.create("/invalidsnap-" + i, data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} finally {
zk.close();
}
final int numSnaps = zks.getTxnLogFactory().findNRecentSnapshots(10 * minExpectedSnapshots).size();
LOG.info("number of snapshots taken {}", numSnaps);
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server to shutdown");
assertTrue(numSnaps > minExpectedSnapshots, "too few snapshot files");
assertTrue(numSnaps <= minExpectedSnapshots * 2, "too many snapshot files");
// start server again
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
zks.startdata();
Collection<Proposal> committedLog = zks.getZKDatabase().getCommittedLog();
int logsize = committedLog.size();
LOG.info("committedLog size = {}", logsize);
assertTrue((logsize != 0), "log size != 0");
zks.shutdown();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class SessionTest method setUp.
@BeforeEach
public void setUp() throws Exception {
if (tmpDir == null) {
tmpDir = ClientBase.createTmpDir();
}
ClientBase.setupTestEnv();
zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
serverFactory.startup(zs);
assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server up");
}
use of org.apache.zookeeper.server.ZooKeeperServer in project ignite by apache.
the class ZookeeperDiscoverySpiSaslAuthAbstractTest method shutdownServerInstance.
/**
*/
private void shutdownServerInstance(ServerCnxnFactory factory) {
if (factory != null) {
ZKDatabase zkDb = null;
{
ZooKeeperServer zs = getServer(factory);
if (zs != null)
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
if (zkDb != null)
zkDb.close();
} catch (IOException ie) {
// ignore
}
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project ignite by apache.
the class ZookeeperDiscoverySpiSaslAuthAbstractTest method startServerInstance.
/**
*/
private void startServerInstance(File dataDir, ServerCnxnFactory factory) throws IOException, InterruptedException {
ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
factory.startup(zks);
}
Aggregations