use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestZK method testLeaderFailover.
@Test
public void testLeaderFailover() throws Exception {
ZooKeeper zk = getClient(0);
ZooKeeper zk2 = getClient(1);
ZooKeeper zk3 = getClient(2);
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) {
}
};
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);
elector1.start(true);
elector2.start(true);
elector3.start(true);
assertTrue(elector1.isLeader());
assertFalse(elector2.isLeader());
assertFalse(elector3.isLeader());
// 2 should become the leader
elector1.shutdown();
zk.close();
assertTrue(sem2.tryAcquire(5, TimeUnit.SECONDS));
assertTrue(elector2.isLeader());
assertEquals(0, sem3.availablePermits());
// 3 should become the leader now
elector2.shutdown();
zk2.close();
assertTrue(sem3.tryAcquire(5, TimeUnit.SECONDS));
assertTrue(elector3.isLeader());
elector3.shutdown();
zk3.close();
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestZK method testSessionExpireAndRecovery.
@Test
public void testSessionExpireAndRecovery() throws Exception {
ZooKeeper zk = getClient(0);
zk.create("/foo", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
failSite(1);
recoverSite(1);
for (int ii = 2; ii < 8; ii++) {
failSite(ii);
}
failSite(0);
zk = getClient(1);
assertNull(zk.exists("/foo", false));
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestZK method testFailure.
@Test
public void testFailure() throws Exception {
ZooKeeper zk = getClient(1);
zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
assertEquals(zk.getData("/foo", false, null).length, 0);
System.out.println("Created node");
failSite(0);
Thread.sleep(1000);
assertEquals(zk.getData("/foo", false, null).length, 0);
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestZK method testRecovery.
@Test
public void testRecovery() throws Exception {
ZooKeeper zk = getClient(0);
zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
failSite(0);
recoverSite(0);
for (int ii = 1; ii < NUM_AGREEMENT_SITES; ii++) {
zk = getClient(ii);
assertEquals(zk.getData("/foo", false, null).length, 0);
}
zk = getClient(0);
assertEquals(zk.getData("/foo", false, null).length, 0);
}
use of org.apache.zookeeper_voltpatches.ZooKeeper in project voltdb by VoltDB.
the class TestZK method testCAS.
@Test
public void testCAS() throws Exception {
ZooKeeper zk = getClient(0);
ZooKeeper zk2 = getClient(1);
ZooKeeper zk3 = getClient(2);
ZooKeeper zk4 = getClient(3);
zk2.create("/foo", new byte[4], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final int count = 100;
Thread t1 = getThread(zk, count);
Thread t2 = getThread(zk2, count);
Thread t3 = getThread(zk3, count);
Thread t4 = getThread(zk4, count);
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();
ByteBuffer buf = ByteBuffer.wrap(zk.getData("/foo", false, null));
assertEquals(count * 4, buf.getInt());
}
Aggregations