getLog().debug("Test Stateless Bean loadbalancing after topology change");
getLog().debug("==================================");
getLog().debug(++StatelessUnitTestCase.test +"- "
+"Looking up clusteredStateless/remote...");
ClusteredStatelessRemote stateless = (ClusteredStatelessRemote) ctx.lookup("clusteredStateless/remote");
confirmTargetCount(2, true);
NodeAnswer node1 = stateless.getNodeState();
getLog ().debug ("Node 1 ID: " +node1);
confirmTargetCount(2, true);
NodeAnswer node2 = stateless.getNodeState();
getLog ().debug ("Node 2 ID : " +node2);
assertFalse(node1.nodeId.equals(node2.nodeId));
confirmTargetCount(2, false);
MBeanServerConnection[] adaptors = getAdaptors();
deployed0 = false;
undeploy(adaptors[0], DEPLOYMENT);
NodeAnswer call3 = stateless.getNodeState();
getLog ().debug ("Call 3 ID : " +call3);
confirmTargetCount(1, true);
assertTrue("Call 3 hit existing node", node1.nodeId.equals(call3.nodeId) || node2.nodeId.equals(call3.nodeId));
NodeAnswer call4 = stateless.getNodeState();
getLog ().debug ("Call 4 ID : " +call4);
assertEquals("Call 3 and Call 4 hit the same node", call3.nodeId, call4.nodeId);
deploy(adaptors[0], DEPLOYMENT);
deployed0 = true;
// Call once to get the new topology. The next call after this
// might go to the same node if the topology change means the node
// that handled this call moves in the target list to the next position
NodeAnswer call5 = stateless.getNodeState();
getLog ().debug ("Call 5 ID : " +call5);
Map<VMID, Integer> callCount = new HashMap<VMID, Integer>();
validateBalancing(stateless, callCount, 4, 2, 0);
deployed1 = false;
undeploy(adaptors[1], DEPLOYMENT);
NodeAnswer call6 = stateless.getNodeState();
getLog ().debug ("Call 6 ID : " +call6);
confirmTargetCount(1, true);
assertTrue("Call 6 hit existing node", callCount.containsKey(call6.nodeId));
NodeAnswer call7 = stateless.getNodeState();
getLog ().debug ("Call 7 ID : " +call7);
assertEquals("Call 6 and Call 7 hit the same node", call6.nodeId, call7.nodeId);
deploy(adaptors[1], DEPLOYMENT);
deployed1 = true;
// Call once to get the new topology. The next call after this
// might go to the same node if the topology change means the node
// that handled this call moves in the target list to the next position
NodeAnswer call8 = stateless.getNodeState();
getLog ().debug ("Call 8 ID : " +call8);
callCount = new HashMap<VMID, Integer>();
validateBalancing(stateless, callCount, 4, 2, 0);
}