Package org.apache.zookeeper.server.quorum

Examples of org.apache.zookeeper.server.quorum.LeaderSessionTracker


    @Test
    public void testLeaderSessionTracker() throws Exception {
        Expirer expirer = new Expirer(2);
        // With local session on
        LeaderSessionTracker tracker = new LeaderSessionTracker(expirer,
                sessionsWithTimeouts, TICK_TIME, expirer.sid, true);

        // Local session from other server
        long sessionId = ((expirer.sid + 1) << 56) + 1;
        try {
            tracker.checkSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("local session from other server should not fail");
        }

        // Global session
        tracker.addGlobalSession(sessionId, CONNECTION_TIMEOUT);
        try {
            tracker.checkSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Global session should not fail");
        }
        try {
            tracker.checkGlobalSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Global session should not fail " + e);
        }

        // Local session from the leader
        sessionId = (expirer.sid << 56) + 1;
        ;
        tracker.addSession(sessionId, CONNECTION_TIMEOUT);
        try {
            tracker.checkSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Local session on the leader should not fail");
        }

        // During session upgrade
        tracker.addGlobalSession(sessionId, CONNECTION_TIMEOUT);
        try {
            tracker.checkSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Session during upgrade should not fail");
        }
        try {
            tracker.checkGlobalSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Global session should not fail " + e);
        }

        // With local session off
        tracker = new LeaderSessionTracker(expirer, sessionsWithTimeouts,
                TICK_TIME, expirer.sid, false);

        // Global session
        sessionId = 0xdeadbeef;
        tracker.addSession(sessionId, CONNECTION_TIMEOUT);
        try {
            tracker.checkSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Global session should not fail");
        }
        try {
            tracker.checkGlobalSession(sessionId, null);
        } catch (Exception e) {
            Assert.fail("Global session should not fail");
        }

        // Local session from other server
        sessionId = ((expirer.sid + 1) << 56) + 2;
        try {
            tracker.checkSession(sessionId, null);
            Assert.fail("local session from other server should fail");
        } catch (SessionExpiredException e) {
            // Got expected exception
        }

        // Local session from the leader
        sessionId = ((expirer.sid) << 56) + 2;
        try {
            tracker.checkSession(sessionId, null);
            Assert.fail("local session from the leader should fail");
        } catch (SessionExpiredException e) {
            // Got expected exception
        }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.server.quorum.LeaderSessionTracker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.