i'm trying to test SessionExpired based on the FAQ (
http://wiki.apache.org/hadoop/ZooKeeper/FAQ) can anyone point out why i'm
getting ConnectionLoss exceptions instead of SessionExpiredExceptions based
on the unit test below:
@Test
public void testSimpleConnection() throws Exception {
String hostPort = "localhost:9999";
ZooKeeper zoo1 = new ZooKeeper(hostPort, 1000, null);
// just make sure we can talk to zookeeper
Assert.assertNull(zoo1.exists("/foo", false));
zoo1.create("/foo", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
Assert.assertNotNull(zoo1.exists("/foo", false));
// construct another client with the same id
ZooKeeper zoo2 = new ZooKeeper(hostPort, zoo1.getSessionTimeout(), null,
zoo1.getSessionId(), null);
// closing this session should invalidate the first:
http://wiki.apache.org/hadoop/ZooKeeper/FAQ
zoo2.close();
// sleep just to make sure everything gets evicted
Thread.sleep(zoo1.getSessionTimeout() * 2);
// closing this session should invalidate the first:
http://wiki.apache.org/hadoop/ZooKeeper/FAQ
// this is where i always get ConnectionLoss instead of SessionExpired
Assert.assertNull(zoo1.exists("/foo", false));
}