@Test public void directCheckUpgradeSessionTest() throws IOException, InterruptedException, KeeperException { final ZooKeeper zk = createClient(); String path = "/directcheckupgradesession"; zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId()); Assert.assertNotNull("unable to find server interlocutor", server); Request readRequest = makeGetDataRequest(path, zk.getSessionId()); Request createRequest = makeCreateRequest(path + "/e", zk.getSessionId()); Assert.assertNull("tried to upgrade on a read", server.checkUpgradeSession(readRequest)); Assert.assertNotNull("failed to upgrade on a create", server.checkUpgradeSession(createRequest)); Assert.assertNull("tried to upgrade after successful promotion", server.checkUpgradeSession(createRequest)); }
@Test public void testOnlyUpgradeSessionOnce() throws IOException, InterruptedException, KeeperException { // create a client, and create an ephemeral node to trigger the // upgrading process final String node = "/node-1"; ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0], ClientBase.CONNECTION_TIMEOUT, this); waitForOne(zk, States.CONNECTED); long sessionId = zk.getSessionId(); QuorumZooKeeperServer server = (QuorumZooKeeperServer) mt[0].main.quorumPeer.getActiveServer(); Request create1 = createEphemeralRequest("/data-1", sessionId); Request create2 = createEphemeralRequest("/data-2", sessionId); Assert.assertNotNull("failed to upgrade on a ephemeral create", server.checkUpgradeSession(create1)); Assert.assertNull("tried to upgrade again", server.checkUpgradeSession(create2)); // clean al the setups and close the zk zk.close(); }