Search in sources :

Example 76 with ZooKeeperServer

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");
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Example 77 with ZooKeeperServer

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();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Proposal(org.apache.zookeeper.server.quorum.Leader.Proposal)

Example 78 with ZooKeeperServer

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");
}
Also used : ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 79 with ZooKeeperServer

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
        }
    }
}
Also used : IOException(java.io.IOException) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 80 with ZooKeeperServer

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);
}
Also used : ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Aggregations

ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)96 File (java.io.File)39 Test (org.junit.jupiter.api.Test)33 ZooKeeper (org.apache.zookeeper.ZooKeeper)31 InetSocketAddress (java.net.InetSocketAddress)28 IOException (java.io.IOException)27 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)26 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)25 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)10 Stat (org.apache.zookeeper.data.Stat)9 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)8 ArrayList (java.util.ArrayList)6 ServerConfig (org.apache.zookeeper.server.ServerConfig)6 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 KeeperException (org.apache.zookeeper.KeeperException)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)3 ACL (org.apache.zookeeper.data.ACL)3 Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)3