assertEquals(3, ServerManagement.getServer(0).getNodeIDView().size());
ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
//The order here depends on the order the servers were started in
//If any servers get stopped and then started then the order will change
log.info("cf1 serverid=" + cf1.getServerID());
log.info("cf2 serverid=" + cf2.getServerID());
log.info("cf3 serverid=" + cf3.getServerID());
assertEquals(0, cf1.getServerID());
assertEquals(1, cf2.getServerID());
assertEquals(2, cf3.getServerID());
Map failoverMap = delegate.getFailoverMap();
assertEquals(3, delegates.length);
assertEquals(3, failoverMap.size());
// Default failover policy just chooses the node to the right
assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
assertEquals(cf3.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf3.getServerID()))).intValue());
}
//Now cleanly stop one of the servers
log.info("************** STOPPING SERVER 0");
ServerManagement.stop(0);
log.info("server stopped");
assertEquals(2, ServerManagement.getServer(1).getNodeIDView().size());
{
//Lookup another connection factory
JBossConnectionFactory factory = (JBossConnectionFactory )ic[1].lookup("/ConnectionFactory");
log.info("Got connection factory");
ClientClusteredConnectionFactoryDelegate delegate =
(ClientClusteredConnectionFactoryDelegate)factory.getDelegate();
ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
Map failoverMap = delegate.getFailoverMap();
log.info("Got failover map");
assertEquals(2, delegates.length);
ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
//Order here depends on order servers were started in
log.info("cf1 serverid=" + cf1.getServerID());
log.info("cf2 serverid=" + cf2.getServerID());
assertEquals(1, cf1.getServerID());
assertEquals(2, cf2.getServerID());
assertEquals(2, failoverMap.size());
assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
}
//Cleanly stop another server
log.info("Server 1 is started: " + ServerManagement.getServer(1).isServerPeerStarted());
ServerManagement.stop(1);
assertEquals(1, ServerManagement.getServer(2).getNodeIDView().size());
{
//Lookup another connection factory
JBossConnectionFactory factory = (JBossConnectionFactory )ic[2].lookup("/ConnectionFactory");
ClientClusteredConnectionFactoryDelegate delegate =
(ClientClusteredConnectionFactoryDelegate)factory.getDelegate();
ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
Map failoverMap = delegate.getFailoverMap();
assertEquals(1, delegates.length);
ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
assertEquals(2, cf1.getServerID());
assertEquals(1, failoverMap.size());
assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
}
//Restart server 0
ServerManagement.start(0, "all");
{
JBossConnectionFactory factory = (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
log.info("Got connection factory");
ClientClusteredConnectionFactoryDelegate delegate =
(ClientClusteredConnectionFactoryDelegate)factory.getDelegate();
ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
Map failoverMap = delegate.getFailoverMap();
log.info("Got failover map");
assertEquals(2, delegates.length);
ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
log.info("cf1 serverid=" + cf1.getServerID());
log.info("cf2 serverid=" + cf2.getServerID());
assertEquals(0, cf1.getServerID());
assertEquals(2, cf2.getServerID());
assertEquals(2, failoverMap.size());
assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
}
//Restart server 1
ServerManagement.start(1, "all");
{
JBossConnectionFactory factory = (JBossConnectionFactory )ic[1].lookup("/ConnectionFactory");
log.info("Got connection factory");
ClientClusteredConnectionFactoryDelegate delegate =
(ClientClusteredConnectionFactoryDelegate)factory.getDelegate();
ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
Map failoverMap = delegate.getFailoverMap();
log.info("Got failover map");
assertEquals(3, delegates.length);
ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
log.info("cf1 serverid=" + cf1.getServerID());
log.info("cf2 serverid=" + cf2.getServerID());
log.info("cf3 serverid=" + cf3.getServerID());
assertEquals(0, cf1.getServerID());
assertEquals(1, cf2.getServerID());
assertEquals(2, cf3.getServerID());
assertEquals(3, failoverMap.size());
assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
assertEquals(cf3.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf3.getServerID()))).intValue());
}
}