Search in sources :

Example 26 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project apex-malhar by apache.

the class KafkaOperatorTestBase method startZookeeper.

public static void startZookeeper(final int clusterId) {
    try {
        int numConnections = 100;
        int tickTime = 2000;
        File dir = new File(baseDir, zkdir[clusterId]);
        zkServer[clusterId] = new TestZookeeperServer(dir, dir, tickTime);
        zkFactory[clusterId] = new NIOServerCnxnFactory();
        zkFactory[clusterId].configure(new InetSocketAddress(TEST_ZOOKEEPER_PORT[clusterId]), numConnections);
        // start the zookeeper server.
        zkFactory[clusterId].startup(zkServer[clusterId]);
        Thread.sleep(2000);
    // kserver.startup();
    } catch (Exception ex) {
        logger.error(ex.getLocalizedMessage());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) IOException(java.io.IOException)

Example 27 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project apex-malhar by apache.

the class KafkaOperatorTestBase method startZookeeper.

public void startZookeeper(final int clusterId) {
    try {
        // before start, clean the zookeeper files if it exists
        FileUtils.deleteQuietly(new File(baseDir, zkBaseDir));
        int clientPort = TEST_ZOOKEEPER_PORT[clusterId];
        int numConnections = 10;
        int tickTime = 2000;
        File dir = new File(baseDir, zkdir[clusterId]);
        TestZookeeperServer kserver = new TestZookeeperServer(dir, dir, tickTime);
        zkFactory[clusterId] = new NIOServerCnxnFactory();
        zkFactory[clusterId].configure(new InetSocketAddress(clientPort), numConnections);
        // start the zookeeper server.
        zkFactory[clusterId].startup(kserver);
        Thread.sleep(2000);
        kserver.startup();
    } catch (Exception ex) {
        logger.debug(ex.getLocalizedMessage());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) IOException(java.io.IOException)

Example 28 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.

the class GroupTest method testOrder.

@Test
public void testOrder() throws Exception {
    int port = findFreePort();
    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();
    final String path = "/singletons/test/Order" + System.currentTimeMillis();
    ArrayList<ZooKeeperGroup> members = new ArrayList<ZooKeeperGroup>();
    for (int i = 0; i < 4; i++) {
        ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, path, NodeState.class);
        group.add(listener);
        members.add(group);
    }
    for (ZooKeeperGroup group : members) {
        assertFalse(group.isConnected());
        assertFalse(group.isMaster());
    }
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    // first to start should be master if members are ordered...
    int i = 0;
    for (ZooKeeperGroup group : members) {
        group.start();
        group.update(new NodeState("foo" + i));
        i++;
        // wait for registration
        while (group.getId() == null) {
            TimeUnit.MILLISECONDS.sleep(100);
        }
    }
    boolean firsStartedIsMaster = members.get(0).isMaster();
    for (ZooKeeperGroup group : members) {
        group.close();
    }
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
    assertTrue("first started is master", firsStartedIsMaster);
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ArrayList(java.util.ArrayList) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.Test)

Example 29 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project camel by apache.

the class GroupTest method startZooKeeper.

private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), "target/zk/data" });
    ZooKeeperServer zkServer = new ZooKeeperServer();
    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(cfg.getTickTime());
    zkServer.setMinSessionTimeout(6000);
    zkServer.setMaxSessionTimeout(9000);
    NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
    cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
    return cnxnFactory;
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 30 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hadoop by apache.

the class TestZKClient method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    System.setProperty("zookeeper.preAllocSize", "100");
    FileTxnLog.setPreallocSize(100 * 1024);
    if (!BASETEST.exists()) {
        BASETEST.mkdirs();
    }
    File dataDir = createTmpDir(BASETEST);
    zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = Integer.parseInt(hostPort.split(":")[1]);
    if (factory == null) {
        factory = new NIOServerCnxnFactory();
        factory.configure(new InetSocketAddress(PORT), maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up", waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Before(org.junit.Before)

Aggregations

NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)55 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)24 IOException (java.io.IOException)22 InetSocketAddress (java.net.InetSocketAddress)19 File (java.io.File)16 Test (org.junit.Test)13 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 RetryNTimes (org.apache.curator.retry.RetryNTimes)12 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)10 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)6 ZooKeeperGroup (org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup)6 ServerConfig (org.apache.zookeeper.server.ServerConfig)5 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)3 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)3 Field (java.lang.reflect.Field)2 SelectionKey (java.nio.channels.SelectionKey)2 ServerSocketChannel (java.nio.channels.ServerSocketChannel)2 SocketChannel (java.nio.channels.SocketChannel)2 ArrayList (java.util.ArrayList)2