use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class StateMachineSnipits method setUp.
@Before
public void setUp() throws Exception {
setUpZK(NUM_AGREEMENT_SITES);
ZooKeeper zk = m_messengers.get(0).getZK();
ZKUtil.addIfMissing(zk, "/test", CreateMode.PERSISTENT, null);
ZKUtil.addIfMissing(zk, "/test/db", CreateMode.PERSISTENT, null);
ZKUtil.addIfMissing(zk, stateMachineManagerRoot, CreateMode.PERSISTENT, null);
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestBabySitter method testBabySitter.
@Test
public void testBabySitter() throws Exception {
System.out.println("\t\t ***** Starting BabySitter testcase.");
final Semaphore sem = new Semaphore(0);
BabySitter.Callback cb = new BabySitter.Callback() {
@Override
public void run(List<String> children) {
sem.release(1);
}
};
ZooKeeper zk = getClient(0);
zk.create("/babysitterroot", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/babysitterroot/c1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
Pair<BabySitter, List<String>> pair = BabySitter.blockingFactory(zk, "/babysitterroot", cb);
BabySitter bs = pair.getFirst();
sem.acquire();
assertTrue(bs.lastSeenChildren().size() == 1);
assertTrue(pair.getSecond().size() == 1);
zk.create("/babysitterroot/c2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
sem.acquire();
assertTrue(bs.lastSeenChildren().size() == 2);
zk.delete("/babysitterroot/" + bs.lastSeenChildren().get(0), -1);
sem.acquire();
assertTrue(bs.lastSeenChildren().size() == 1);
bs.shutdown();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestBabySitter method testChildrenOrdering.
@Test
public void testChildrenOrdering() throws Exception {
final Semaphore sem = new Semaphore(0);
final AtomicReference<List<String>> latestChildren = new AtomicReference<List<String>>();
BabySitter.Callback cb = new BabySitter.Callback() {
@Override
public void run(List<String> children) {
latestChildren.set(children);
sem.release();
}
};
ZooKeeper zk = getClient(0);
zk.create("/babysitterroot", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final String node6 = zk.create("/babysitterroot/6_", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
zk.create("/babysitterroot/7_", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
zk.create("/babysitterroot/10_", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
Pair<BabySitter, List<String>> pair = BabySitter.blockingFactory(zk, "/babysitterroot", cb);
BabySitter bs = pair.getFirst();
sem.acquire();
assertEquals(Lists.newArrayList(6l, 7l, 10l), VoltZK.childrenToReplicaHSIds(latestChildren.get()));
zk.delete(node6, -1);
sem.acquire();
assertEquals(Lists.newArrayList(7l, 10l), VoltZK.childrenToReplicaHSIds(latestChildren.get()));
bs.shutdown();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestMapCache method testInitialCache.
@Test
public void testInitialCache() throws Exception {
ZooKeeper zk = getClient(0);
configure("/cache01", zk);
MapCache dut = new MapCache(zk, "/cache01");
dut.start(true);
Map<String, JSONObject> cache = dut.pointInTimeCache();
assertEquals("3 items cached.", 3, cache.size());
assertEquals("aaval", cache.get("/cache01/aa").get("key"));
assertEquals("bbval", cache.get("/cache01/bb").get("key"));
assertEquals("ccval", cache.get("/cache01/cc").get("key"));
dut.shutdown();
zk.close();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestZK method testLeaderFailoverHarder.
@Test
public void testLeaderFailoverHarder() throws Exception {
// as above but put multiple failed nodes between the new and previous?
ZooKeeper zk = getClient(0);
ZooKeeper zk2 = getClient(1);
ZooKeeper zk3 = getClient(2);
ZooKeeper zk4 = getClient(3);
zk.create("/election", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final Semaphore sem2 = new Semaphore(0);
LeaderNoticeHandler r2 = new LeaderNoticeHandler() {
@Override
public void becomeLeader() {
sem2.release();
}
@Override
public void noticedTopologyChange(boolean added, boolean removed) {
}
};
final Semaphore sem3 = new Semaphore(0);
LeaderNoticeHandler r3 = new LeaderNoticeHandler() {
@Override
public void becomeLeader() {
sem3.release();
}
@Override
public void noticedTopologyChange(boolean added, boolean removed) {
}
};
final Semaphore sem4 = new Semaphore(0);
LeaderNoticeHandler r4 = new LeaderNoticeHandler() {
@Override
public void becomeLeader() {
sem4.release();
}
@Override
public void noticedTopologyChange(boolean added, boolean removed) {
}
};
LeaderElector elector1 = new LeaderElector(zk, "/election", "node", new byte[0], null);
LeaderElector elector2 = new LeaderElector(zk2, "/election", "node", new byte[0], r2);
LeaderElector elector3 = new LeaderElector(zk3, "/election", "node", new byte[0], r3);
LeaderElector elector4 = new LeaderElector(zk4, "/election", "node", new byte[0], r4);
elector1.start(true);
elector2.start(true);
elector3.start(true);
elector4.start(true);
assertTrue(elector1.isLeader());
assertFalse(elector2.isLeader());
assertFalse(elector3.isLeader());
assertFalse(elector4.isLeader());
// 4 should become the leader
elector3.shutdown();
zk3.close();
elector2.shutdown();
zk2.close();
elector1.shutdown();
zk.close();
assertTrue(sem4.tryAcquire(5, TimeUnit.SECONDS));
assertTrue(elector4.isLeader());
// cleanup.
elector4.shutdown();
zk4.close();
}
Aggregations