use of org.apache.zookeeper.server.quorum.UpgradeableSessionTracker in project zookeeper by apache.
the class MultiOpSessionUpgradeTest method ephemeralCreateMultiOpTest.
@Test
public void ephemeralCreateMultiOpTest() throws KeeperException, InterruptedException, IOException {
final ZooKeeper zk = createClient();
String data = "test";
String path = "/ephemeralcreatemultiop";
zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId());
assertNotNull(server, "unable to find server interlocutor");
UpgradeableSessionTracker sessionTracker = (UpgradeableSessionTracker) server.getSessionTracker();
assertFalse(sessionTracker.isGlobalSession(zk.getSessionId()), "session already global");
List<OpResult> multi = null;
try {
multi = zk.multi(Arrays.asList(Op.setData(path, data.getBytes(), 0), Op.create(path + "/e", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL), Op.create(path + "/p", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.create(path + "/q", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL)));
} catch (KeeperException.SessionExpiredException e) {
// the scenario that inspired this unit test
fail("received session expired for a session promotion in a multi-op");
}
assertNotNull(multi);
assertEquals(4, multi.size());
assertEquals(data, new String(zk.getData(path + "/e", false, null)));
assertEquals(data, new String(zk.getData(path + "/p", false, null)));
assertEquals(data, new String(zk.getData(path + "/q", false, null)));
assertTrue(sessionTracker.isGlobalSession(zk.getSessionId()), "session not promoted");
}
Aggregations