@Test
public void testLearnerSessionTracker() throws Exception {
Expirer expirer = new Expirer(1);
// With local session on
LearnerSessionTracker tracker = new LearnerSessionTracker(expirer,
sessionsWithTimeouts, TICK_TIME, expirer.sid, true);
// Unknown session
long sessionId = 0xb100ded;
try {
tracker.checkSession(sessionId, null);
Assert.fail("Unknown session should have failed");
} catch (SessionExpiredException e) {
// Get expected exception
}
// Global session
sessionsWithTimeouts.put(sessionId, CONNECTION_TIMEOUT);
try {
tracker.checkSession(sessionId, null);
} catch (Exception e) {
Assert.fail("Global session should not fail");
}
// Local session
sessionId = 0xf005ba11;
tracker.addSession(sessionId, CONNECTION_TIMEOUT);
try {
tracker.checkSession(sessionId, null);
} catch (Exception e) {
Assert.fail("Local session should not fail");
}
// During session upgrade
sessionsWithTimeouts.put(sessionId, CONNECTION_TIMEOUT);
try {
tracker.checkSession(sessionId, null);
} catch (Exception e) {
Assert.fail("Session during upgrade should not fail");
}
// With local session off
tracker = new LearnerSessionTracker(expirer, sessionsWithTimeouts,
TICK_TIME, expirer.sid, false);
// Should be noop
sessionId = 0xdeadbeef;
try {
tracker.checkSession(sessionId, null);
} catch (Exception e) {
Assert.fail("Should not get any exception");
}
}