Search in sources :

Example 1 with UpgradeableSessionTracker

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");
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) QuorumZooKeeperServer(org.apache.zookeeper.server.quorum.QuorumZooKeeperServer) OpResult(org.apache.zookeeper.OpResult) UpgradeableSessionTracker(org.apache.zookeeper.server.quorum.UpgradeableSessionTracker) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.jupiter.api.Test)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)1 OpResult (org.apache.zookeeper.OpResult)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 QuorumZooKeeperServer (org.apache.zookeeper.server.quorum.QuorumZooKeeperServer)1 UpgradeableSessionTracker (org.apache.zookeeper.server.quorum.UpgradeableSessionTracker)1 Test (org.junit.jupiter.api.Test)1