pp.minSize = 0;
pp.maxSize = 6;
pp.blockingTimeout = 100;
pp.idleTimeout = 2000;
final BaseConnectionManager2 cm = getCM(pp, 1, 1000);
assertEquals("Wrong allocation retry value", 1, cm.getAllocationRetry());
assertEquals("Wrong allocation retry wait millis value", 1000, cm.getAllocationRetryWaitMillis());
final int numOfThreads = 2;
final int iterations = pp.maxSize / numOfThreads;
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch cont = new CountDownLatch(1);
final CountDownLatch firstPart = new CountDownLatch(numOfThreads);
final CountDownLatch done = new CountDownLatch(numOfThreads);
failed = false;
failedDescription = null;
failedException = null;
try
{
for (int i = 0; i < numOfThreads; i++)
{
Runnable t = new Runnable()
{
public void run()
{
List cs = new ArrayList();
try
{
start.await();
for (int i = 0; i < iterations; i++)
{
try
{
ConnectionListener cl = cm.getManagedConnection(null, null);
assertTrue("Got a null connection!", cl.getManagedConnection() != null);
cs.add(cl);
}
catch (ResourceException re)
{
failed = true;
failedDescription = "Failed to get a connection";
failedException = re;
}
}
assertEquals("1: Wrong number of connections", iterations, cs.size());
firstPart.countDown();
cont.await();
for (Iterator i = cs.iterator(); i.hasNext();)
{
cm.returnManagedConnection((ConnectionListener)i.next(), true);
}
done.countDown();
}
catch (InterruptedException ie)
{
}
}
};
new Thread(t).start();
}
start.countDown();
firstPart.await();
assertTrue("2: Wrong number of connections counted: " + cm.getConnectionCount(), cm.getConnectionCount() == pp.maxSize);
try
{
ConnectionListener cl = cm.getManagedConnection(null, null);
cm.returnManagedConnection(cl, true);
failedDescription = "Got a connection";
failedException = new Exception(cl.toString());
failed = true;
}
catch (ResourceException ignore)
{
}
cont.countDown();
done.await();
assertTrue("3: Wrong number of connections counted: " + cm.getConnectionCount(), cm.getConnectionCount() == 0);
if (failed)
{
if (failedDescription == null)
{