Search in sources :

Example 1 with ZooKeeperServer

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);
    }
}
Also used : ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) IOException(java.io.IOException) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.Test)

Example 2 with ZooKeeperServer

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

Example 3 with ZooKeeperServer

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();
}
Also used : ActiveStandbyElectorCallback(org.apache.hadoop.ha.ActiveStandbyElector.ActiveStandbyElectorCallback) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.Test)

Example 4 with ZooKeeperServer

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

Example 5 with ZooKeeperServer

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

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