use of org.apache.zookeeper.WatchedEvent in project zookeeper by apache.
the class ReconfigTest method createHandles.
public static ZooKeeper[] createHandles(QuorumUtil qu) throws IOException {
// create an extra handle, so we can index the handles from 1 to qu.ALL
// using the server id.
ZooKeeper[] zkArr = new ZooKeeper[qu.ALL + 1];
// not used.
zkArr[0] = null;
for (int i = 1; i <= qu.ALL; i++) {
// server ids are 1, 2 and 3
zkArr[i] = new ZooKeeper("127.0.0.1:" + qu.getPeer(i).peer.getClientPort(), ClientBase.CONNECTION_TIMEOUT, new Watcher() {
public void process(WatchedEvent event) {
}
});
}
return zkArr;
}
use of org.apache.zookeeper.WatchedEvent in project zookeeper by apache.
the class QuorumTest method testLeaderShutdown.
@Test
public void testLeaderShutdown() throws IOException, InterruptedException, KeeperException {
ZooKeeper zk = new DisconnectableZooKeeper(qb.hostPort, ClientBase.CONNECTION_TIMEOUT, new Watcher() {
public void process(WatchedEvent event) {
}
});
zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/blah/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Leader leader = qb.s1.leader;
if (leader == null)
leader = qb.s2.leader;
if (leader == null)
leader = qb.s3.leader;
if (leader == null)
leader = qb.s4.leader;
if (leader == null)
leader = qb.s5.leader;
Assert.assertNotNull(leader);
for (int i = 0; i < 5000; i++) {
zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
public void processResult(int rc, String path, Object ctx, Stat stat) {
counter++;
if (rc != 0) {
errors++;
}
}
}, null);
}
for (LearnerHandler f : leader.getForwardingFollowers()) {
f.getSocket().shutdownInput();
}
for (int i = 0; i < 5000; i++) {
zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
public void processResult(int rc, String path, Object ctx, Stat stat) {
counter++;
if (rc != 0) {
errors++;
}
}
}, null);
}
// check if all the followers are alive
Assert.assertTrue(qb.s1.isAlive());
Assert.assertTrue(qb.s2.isAlive());
Assert.assertTrue(qb.s3.isAlive());
Assert.assertTrue(qb.s4.isAlive());
Assert.assertTrue(qb.s5.isAlive());
zk.close();
}
use of org.apache.zookeeper.WatchedEvent in project zookeeper by apache.
the class QuorumZxidSyncTest method testLateLogs.
/**
* find out what happens when the latest state is in the snapshots not
* the logs.
*/
@Test
public void testLateLogs() throws Exception {
// crank up the epoch numbers
ClientBase.waitForServerUp(qb.hostPort, 10000);
ClientBase.waitForServerUp(qb.hostPort, 10000);
ZooKeeper zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() {
public void process(WatchedEvent event) {
}
});
zk.create("/0", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
qb.shutdownServers();
qb.startServers();
ClientBase.waitForServerUp(qb.hostPort, 10000);
qb.shutdownServers();
qb.startServers();
ClientBase.waitForServerUp(qb.hostPort, 10000);
zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() {
public void process(WatchedEvent event) {
}
});
zk.create("/1", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
qb.shutdownServers();
qb.startServers();
ClientBase.waitForServerUp(qb.hostPort, 10000);
qb.shutdownServers();
deleteLogs(qb.s1dir);
deleteLogs(qb.s2dir);
deleteLogs(qb.s3dir);
deleteLogs(qb.s4dir);
deleteLogs(qb.s5dir);
qb.startServers();
ClientBase.waitForServerUp(qb.hostPort, 10000);
zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() {
public void process(WatchedEvent event) {
}
});
zk.create("/2", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
qb.shutdownServers();
qb.startServers();
ClientBase.waitForServerUp(qb.hostPort, 10000);
zk = new ZooKeeper(qb.hostPort, 10000, new Watcher() {
public void process(WatchedEvent event) {
}
});
boolean saw2 = false;
for (String child : zk.getChildren("/", false)) {
if (child.equals("2")) {
saw2 = true;
}
}
zk.close();
Assert.assertTrue("Didn't see /2 (went back in time)", saw2);
}
use of org.apache.zookeeper.WatchedEvent in project zookeeper by apache.
the class WatchedEventTest method testCreatingWatchedEvent.
@Test
public void testCreatingWatchedEvent() {
// EventWatch is a simple, immutable type, so all we need to do
// is make sure we can create all possible combinations of values.
EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
WatchedEvent we;
for (EventType et : allTypes) {
for (KeeperState ks : allStates) {
we = new WatchedEvent(et, ks, "blah");
Assert.assertEquals(et, we.getType());
Assert.assertEquals(ks, we.getState());
Assert.assertEquals("blah", we.getPath());
}
}
}
use of org.apache.zookeeper.WatchedEvent in project zookeeper by apache.
the class WatchedEventTest method testCreatingWatchedEventFromInvalidWrapper.
@Test
public void testCreatingWatchedEventFromInvalidWrapper() {
try {
WatcherEvent wep = new WatcherEvent(-2342, -252352, "foo");
new WatchedEvent(wep);
Assert.fail("Was able to create WatchedEvent from bad wrapper");
} catch (RuntimeException re) {
// we're good
}
}
Aggregations