@Test
  public void basics() throws Exception {
    TestFactory f = new TestFactory();
    SessionManager<Integer> s = new SessionManager<Integer>(f);
    assertSame(f, s.getSessionFactory());
    assertEquals(SessionManager.INFINITE_SESSION_LIFESPAN, s.getLifespan());

    assertNull(s.getServerId());
    s.setServerId(TEST_SERVER_ID);
    assertEquals(TEST_SERVER_ID, s.getServerId());
    s.setServerId(null);
    assertNull(s.getServerId());

    assertNull(s.get(TEST_SESSION_ID));

    SessionHolder<Integer> hD = new SessionHolder<Integer>(TEST_USER, TEST_CONTEXT);
    long time = hD.getLastAccess();
    Thread.sleep(100);
    s.put(TEST_SESSION_ID, hD);
    assertTrue(hD.getLastAccess() > time);
    assertEquals(TEST_SESSION_ID, f.getLastSessionId());

    time = hD.getLastAccess();
    Thread.sleep(100);
    assertSame(hD, s.get(TEST_SESSION_ID));
    assertTrue(hD.getLastAccess() > time);

    SessionHolder<Integer> h = new SessionHolder<Integer>(TEST_USER, TEST_CONTEXT);
    s.put(TEST_SESSION_ID, h);
    assertSame(h, s.get(TEST_SESSION_ID));

    assertNull(s.get(TEST_SESSION_ID_D));
    s.put(TEST_SESSION_ID_D, hD);
    assertSame(hD, s.get(TEST_SESSION_ID_D));
    assertSame(h, s.get(TEST_SESSION_ID));
    assertEquals(TEST_SESSION_ID_D, f.getLastSessionId());

    s.remove(TEST_SESSION_ID);
    assertNull(s.get(TEST_SESSION_ID));
    assertSame(hD, s.get(TEST_SESSION_ID_D));
    assertEquals(TEST_SESSION, f.getLastRemovedSession());

    // Removal of nonexistent session ID.

    s.remove(TEST_SESSION_ID);
  }