Search in sources :

Example 6 with ZkServer

use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.

the class TestUtil method startZkServer.

public static ZkServer startZkServer(String zkTestDataRootDir, int machineId, int port, int tickTime) throws IOException {
    File zkTestDataRootDirFile = new File(zkTestDataRootDir);
    zkTestDataRootDirFile.mkdirs();
    String dataPath = zkTestDataRootDir + "/" + machineId + "/" + port + "/data";
    String logPath = zkTestDataRootDir + "/" + machineId + "/" + port + "/log";
    FileUtils.deleteDirectory(new File(dataPath));
    FileUtils.deleteDirectory(new File(logPath));
    IDefaultNameSpace mockDefaultNameSpace = new IDefaultNameSpace() {

        @Override
        public void createDefaultNameSpace(ZkClient zkClient) {
        }
    };
    ZkServer zkServer = new ZkServer(dataPath, logPath, mockDefaultNameSpace, port, tickTime);
    zkServer.start();
    return zkServer;
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) File(java.io.File) ZkServer(org.I0Itec.zkclient.ZkServer)

Example 7 with ZkServer

use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.

the class TestClusterCheckpointPersistenceProvider method startZookeeper.

@BeforeClass
public void startZookeeper() throws IOException {
    TestUtil.setupLoggingWithTimestampedFile(true, "/tmp/TestClusterCheckpointPersistenceProvider_", ".log", Level.WARN);
    File zkroot = FileUtils.createTempDir("TestClusterCheckpointPersistenceProvider_zkroot");
    LOG.info("starting ZK on port " + localZkPort + " and datadir " + zkroot.getAbsolutePath());
    ZkServer zkServer = TestUtil.startZkServer(zkroot.getAbsolutePath(), 0, localZkPort, 2000);
    if (zkServer != null) {
        _localZkServers = new Vector<ZkServer>(1);
        _localZkServers.add(zkServer);
    }
}
Also used : File(java.io.File) ZkServer(org.I0Itec.zkclient.ZkServer) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with ZkServer

use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.

the class TestDatabusClientNode method testMasterSlave.

@Test
public void testMasterSlave() throws InterruptedException, DummyClientException, IOException {
    List<ZkServer> localZkServers = startZk(8100);
    try {
        Integer totalCountExpected = 100;
        int numNodes = 10;
        int delayMs = 10;
        int numIter = 1;
        Integer expectedWorkLoad = totalCountExpected / numNodes;
        long updateTimestamp = System.currentTimeMillis();
        for (int iter = 0; iter < numIter; ++iter) {
            DummyClient[] nodes = new DummyClient[numNodes];
            Thread[] threads = new Thread[numNodes];
            for (int i = 0; i < numNodes; ++i) {
                nodes[i] = new DummyClient(expectedWorkLoad, "counters", "worker_" + (int) (Math.random() * 1000), totalCountExpected, delayMs, updateTimestamp);
                // nodes[i] =  new DummyClient(expectedWorkLoad,"counters","worker_"  ,totalCountExpected,delayMs);
                threads[i] = new Thread(nodes[i]);
            }
            for (int i = 0; i < threads.length; ++i) {
                threads[i].start();
                Thread.sleep(i * (iter * 2 + 20));
            }
            for (int i = 0; i < threads.length; ++i) {
                //wait for 1000ms  - protect against hung processes
                threads[i].join(1000);
            }
            boolean exhausted = false;
            boolean tsExhausted = false;
            for (DummyClient w1 : nodes) {
                System.err.printf("Worker =%s\n", w1.toString());
                AssertJUnit.assertTrue(w1.getActualWorkCount().intValue() == expectedWorkLoad.intValue());
                if (w1.getSharedWorkCounter().intValue() == totalCountExpected.intValue()) {
                    exhausted = true;
                }
                long diff = w1.getDSCTimestamp() - updateTimestamp;
                if (diff == totalCountExpected) {
                    tsExhausted = true;
                }
                System.err.println("Timestamp Diff=" + diff);
            }
            AssertJUnit.assertTrue(exhausted);
            AssertJUnit.assertTrue(tsExhausted);
        }
    } finally {
        stopZk(localZkServers);
    }
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) ZkServer(org.I0Itec.zkclient.ZkServer) Test(org.testng.annotations.Test)

Example 9 with ZkServer

use of org.I0Itec.zkclient.ZkServer in project pinot by linkedin.

the class ZookeeperLauncher method start.

public boolean start(int zkPort) {
    IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {

        @Override
        public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient) {
        // init any zk paths if needed
        }
    };
    LOGGER.info("Starting zookeeper at localhost:{} in thread: {}", zkPort, Thread.currentThread().getName());
    _zkServer = new ZkServer(_dataDir, _logDir, defaultNameSpace, zkPort, 30000, 60000);
    _zkServer.start();
    return true;
}
Also used : IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) ZkServer(org.I0Itec.zkclient.ZkServer)

Aggregations

ZkServer (org.I0Itec.zkclient.ZkServer)9 File (java.io.File)4 IDefaultNameSpace (org.I0Itec.zkclient.IDefaultNameSpace)3 Checkpoint (com.linkedin.databus.core.Checkpoint)2 ArrayList (java.util.ArrayList)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 BeforeClass (org.testng.annotations.BeforeClass)2 Test (org.testng.annotations.Test)2