// Simple connection count stress test
PooledInvokerProxy.clearStats();
PooledInvokerProxy.clearPools();
for(int n = 0; n < 100; n ++)
{
StatelessSession tmp = homeHA.create();
StatelessSession tmp2 = home.create();
tmp.getCallCount();
tmp2.getCallCount();
tmp.getCallCount();
tmp2.getCallCount();
int totalCount = PooledInvokerProxy.getTotalPoolCount();
// N cluster nodes + 1 for unclustered
int expectedCount = urls.length + 1;
assertEquals("TotalPoolCount", expectedCount, totalCount);
long usedPooled = PooledInvokerProxy.getUsedPooled();
// iter * Ncalls - expectedCount (for the initial conn creation)
int expectedUsedPooled = (n+1) * 6 - expectedCount;
assertEquals("UsedPooled", expectedUsedPooled, usedPooled);
}
long inUseCount = PooledInvokerProxy.getInUseCount();
assertEquals("InUseCount", 0, inUseCount);
log.debug("Calling create on StatelessSessionHome...");
StatelessSession statelessSession = homeHA.create();
assertTrue("homeHA.create() != null", statelessSession != null);
log.debug("Calling getEJBHome() on StatelessSession...");
assertTrue("statelessSession.getEJBHome() != null", statelessSession.getEJBHome() != null);
log.debug("Reseting the number of calls made on beans (making 2 calls)... ");
for (int i=0; i<6; i++)
{
log.debug("Reseting number... ");
statelessSession.resetNumberOfCalls ();
}
log.debug("- "+"Now making 20 calls on this remote... ");
for (int i=0; i<20; i++)
{
log.debug("- "+" Calling remote... ");
statelessSession.makeCountedCall ();
}
log.debug("- "+"Getting the number of calls that have been performed on each bean... ");
long node1 = statelessSession.getCallCount();
log.debug("- "+"One node has received: " + node1);
long node2 = statelessSession.getCallCount();
log.debug("- "+"The other node has received: " + node2);
if (node1 == node2 && node1 == 10)
{
log.debug("- "+"Test is ok.");
}
else if( urls.length > 1 )
{
log.debug("- "+"Something wrong has happened! Calls seems not to have been load-balanced.");
fail ("call count mismatch: "+node1+" != "+node2);
}
statelessSession.remove();
log.debug("ok");
}