use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.
the class LeaderElectUtils 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) {
}
};
LOG.info("Starting local zookeeper on port=" + port + "; dataPath=" + dataPath);
ZkServer zkServer = new ZkServer(dataPath, logPath, mockDefaultNameSpace, port, tickTime);
zkServer.start();
return zkServer;
}
use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.
the class LeaderElectUtils method startLocalZookeeper.
public static List<ZkServer> startLocalZookeeper(List<Integer> localPortsList, String zkTestDataRootDir, int tickTime) throws IOException {
List<ZkServer> localZkServers = new ArrayList<ZkServer>();
int count = 0;
for (int port : localPortsList) {
ZkServer zkServer = startZkServer(zkTestDataRootDir, count++, port, tickTime);
localZkServers.add(zkServer);
}
return localZkServers;
}
use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.
the class TestDatabusClientNode method testZkTempIsolation.
@Test
public void testZkTempIsolation() throws DummyClientException, InterruptedException, IOException {
//zk is up;
Integer totalCountExpected = 5000;
int numNodes = 2;
int delayMs = 10;
int interruptCount = 1000;
Integer expectedWorkLoad = totalCountExpected / numNodes;
long updateTimestamp = System.currentTimeMillis();
List<ZkServer> localZkServers = startZk(8100);
try {
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);
threads[i] = new Thread(nodes[i]);
}
for (int i = 0; i < threads.length; ++i) {
threads[i].start();
Thread.sleep(10);
}
Thread.sleep(2000);
DummyClient origLeader = findLeader(nodes);
AssertJUnit.assertTrue(origLeader != null);
System.out.printf("Current leader=%s\n", origLeader.getName());
//Threads have started; and are writing to shared storage; now kill zookeeper
Thread.sleep(interruptCount * delayMs);
origLeader.leaveGroup();
Thread.sleep(1000);
origLeader.joinGroup();
DummyClient newLeader = findLeader(nodes);
AssertJUnit.assertTrue(newLeader != null);
System.out.printf("New leader=%s\n", newLeader.getName());
for (int i = 0; i < threads.length; ++i) {
//wait for 1000ms - protect against hung processes
threads[i].join(10L * expectedWorkLoad * delayMs);
}
AssertJUnit.assertFalse(origLeader.getName().equals(newLeader.getName()));
AssertJUnit.assertTrue(origLeader.getSharedWorkCounter() < expectedWorkLoad);
AssertJUnit.assertTrue(newLeader.getSharedWorkCounter() < totalCountExpected);
AssertJUnit.assertTrue(newLeader.getSharedWorkCounter().equals(expectedWorkLoad));
} finally {
stopZk(localZkServers);
}
}
use of org.I0Itec.zkclient.ZkServer in project databus by linkedin.
the class TestDatabusCluster method startZookeeper.
@BeforeClass
public void startZookeeper() throws IOException {
TestUtil.setupLogging(true, null, Level.WARN);
File zkroot = FileUtils.createTempDir("TestDatabusCluster_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);
}
}
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);
}
}
Aggregations