BasicThreadPool pool = new BasicThreadPool();
mbeanServer.registerMBean(pool, new ObjectName(JBossCacheSSOClusterManager.DEFAULT_THREAD_POOL_NAME));
}
// Build up an SSO infrastructure based on LOCAL_ADDRESS
JBossCacheSSOClusterManager localSSOManager = new JBossCacheSSOClusterManager();
MockSSOValve localValve = new MockSSOValve(mbeanServer);
localValve.setCacheConfig(ClusteredSingleSignOn.DEFAULT_CACHE_NAME);
localValve.setClusterManager(localSSOManager);
localSSOManager.setSSOLocalManager(localValve);
localSSOManager.start();
assertEquals("Thread pool usage as expected", usePool, localSSOManager.isUsingThreadPool());
// Build up a second SSO infrastructure based on LOCAL_ADDRESS
// It uses the same mock cache, but we change the cache address
// so it thinks it's a different address when it starts
cache.setOurAddress(REMOTE_ADDRESS);
JBossCacheSSOClusterManager remoteSSOManager = new JBossCacheSSOClusterManager();
MockSSOValve remoteValve = new MockSSOValve(mbeanServer);
remoteValve.setCacheConfig(ClusteredSingleSignOn.DEFAULT_CACHE_NAME);
remoteValve.setClusterManager(remoteSSOManager);
remoteSSOManager.setSSOLocalManager(localValve);
remoteSSOManager.start();
// Create an SSO that will have sessions from both valves
localSSOManager.register("1", "FORM", "Brian", "password");
Manager localSessMgr1 = getSessionManager("A");
Session sess1 = new MockSession(localSessMgr1, "1");
localSSOManager.addSession("1", getFullyQualifiedSessionId(sess1));
Manager remoteSessMgr1 = getSessionManager("B");
Session sess2 = new MockSession(remoteSessMgr1, "2");
remoteSSOManager.addSession("1", getFullyQualifiedSessionId(sess2));
// Create another SSO with sessions only from remote
remoteSSOManager.register("2", "FORM", "Brian", "password");
Manager remoteSessMgr2 = getSessionManager("C");
Session sess3 = new MockSession(remoteSessMgr2, "3");
remoteSSOManager.addSession("2", getFullyQualifiedSessionId(sess3));
Manager remoteSessMgr3 = getSessionManager("D");
Session sess4 = new MockSession(remoteSessMgr3, "4");
remoteSSOManager.addSession("2", getFullyQualifiedSessionId(sess4));
// Create a third SSO that will have sessions from both valves
// with the same session id
localSSOManager.register("3", "FORM", "Brian", "password");
Manager localSessMgr2 = getSessionManager("E");
Session sess5 = new MockSession(localSessMgr2, "5");
localSSOManager.addSession("3", getFullyQualifiedSessionId(sess5));
Manager remoteSessMgr4 = getSessionManager("E");
Session sess6 = new MockSession(remoteSessMgr4, "5");
remoteSSOManager.addSession("3", getFullyQualifiedSessionId(sess6));
// Create a fourth SSO that will have two sessions from local valve
localSSOManager.register("4", "FORM", "Brian", "password");
Manager localSessMgr3 = getSessionManager("F");
Session sess7 = new MockSession(localSessMgr3, "7");
localSSOManager.addSession("4", getFullyQualifiedSessionId(sess7));
Manager localSessMgr4 = getSessionManager("G");
Session sess8 = new MockSession(localSessMgr4, "8");
localSSOManager.addSession("4", getFullyQualifiedSessionId(sess8));
// Create a fifth SSO with sessions only from remote, same session id
// but different managers
remoteSSOManager.register("5", "FORM", "Brian", "password");
Manager remoteSessMgr5 = getSessionManager("H");
Session sess9 = new MockSession(remoteSessMgr5, "9");
remoteSSOManager.addSession("5", getFullyQualifiedSessionId(sess9));
Manager remoteSessMgr6 = getSessionManager("I");
Session sess10 = new MockSession(remoteSessMgr6, "9");
remoteSSOManager.addSession("5", getFullyQualifiedSessionId(sess10));
// Confirm that data is cached properly
assertEquals("SSO 1 has correct number of sessions", 2, localSSOManager.getSessionCount("1"));
assertEquals("SSO 1 has correct number of sessions", 2, remoteSSOManager.getSessionCount("1"));
assertEquals("SSO 2 has correct number of sessions", 2, localSSOManager.getSessionCount("2"));
assertEquals("SSO 2 has correct number of sessions", 2, remoteSSOManager.getSessionCount("2"));
assertEquals("SSO 3 has correct number of sessions", 2, localSSOManager.getSessionCount("3"));
assertEquals("SSO 3 has correct number of sessions", 2, remoteSSOManager.getSessionCount("3"));
assertEquals("SSO 4 has correct number of sessions", 2, localSSOManager.getSessionCount("4"));
assertEquals("SSO 4 has correct number of sessions", 2, remoteSSOManager.getSessionCount("4"));
assertEquals("SSO 5 has correct number of sessions", 2, localSSOManager.getSessionCount("5"));
assertEquals("SSO 5 has correct number of sessions", 2, remoteSSOManager.getSessionCount("5"));
// Put in a new view with REMOTE_ADDRESS dead
ViewId viewId = new ViewId(LOCAL_ADDRESS, 1);
Vector v = new Vector();
v.add(LOCAL_ADDRESS);