pp.maxSize = getBeanCount();
pp.blockingTimeout = (threadsPerConnection) * ((int)sleepTime + 15);
if (pp.blockingTimeout < 1000)
pp.blockingTimeout = 1000;
pp.idleTimeout = idle;
final BaseConnectionManager2 cm = getCM(pp);
try
{
int totalThreads = pp.maxSize * threadsPerConnection;
log.info("ShortBlocking test with connections: " + pp.maxSize + " totalThreads: " + totalThreads + " reps: " + reps);
for (int i = 0; i < totalThreads; i++)
{
Runnable t = new Runnable()
{
int id;
public void run()
{
synchronized (startedLock)
{
id = startedThreadCount;
startedThreadCount++;
startedLock.notify();
}
long duration = 0;
long getConnection = 0;
long returnConnection = 0;
long heldConnection = 0;
for (int j = 0; j < reps; j++)
{
try
{
long startGetConnection = System.currentTimeMillis();
ConnectionListener cl = cm.getManagedConnection(null, null);
long endGetConnection = System.currentTimeMillis();
//maybe should be synchronized
BaseConnectionManagerStressTestCase.this.connectionCount++;
Thread.sleep(sleepTime);
long startReturnConnection = System.currentTimeMillis();
cm.returnManagedConnection(cl, false);
long endReturnConnection = System.currentTimeMillis();
duration += (endReturnConnection - startGetConnection);
getConnection += (endGetConnection - startGetConnection);
returnConnection += (endReturnConnection - startReturnConnection);
heldConnection += (startReturnConnection - endGetConnection);
}
catch (ResourceException re)
{
BaseConnectionManagerStressTestCase.this.log.info("error: iterationCount: " + j + ", connectionCount: " + BaseConnectionManagerStressTestCase.this.connectionCount + " " + re.getMessage());
BaseConnectionManagerStressTestCase.this.errorCount++;
BaseConnectionManagerStressTestCase.this.error = re;
BaseConnectionManagerStressTestCase.this.failed = true;
} // end of try-catch
catch (InterruptedException ie)
{
break;
} // end of catch
}
synchronized (BaseConnectionManagerStressTestCase.this)
{
BaseConnectionManagerStressTestCase.this.elapsed += duration;
BaseConnectionManagerStressTestCase.this.getConnection += getConnection;
BaseConnectionManagerStressTestCase.this.returnConnection += returnConnection;
BaseConnectionManagerStressTestCase.this.held += heldConnection;
}
synchronized (finishedLock)
{
finishedThreadCount++;
finishedLock.notify();
}
}
};
new Thread(t).start();
synchronized (startedLock)
{
while (startedThreadCount < i + 1)
{
startedLock.wait();
} // end of while ()
}
} // end of for ()
synchronized (finishedLock)
{
while (finishedThreadCount < totalThreads)
{
finishedLock.wait();
} // end of while ()
}
// Stop the pool/idle remover, otherwise the following checks will be random
TestPool pool = (TestPool) cm.getPoolingStrategy();
pool.shutdownWithoutClear();
float expected = totalThreads * reps;
float lessWaiting = getConnection - (threadsPerConnection - 1) * held;
log.info("completed " + getName() + " with connectionCount: " + connectionCount + ", expected : " + expected);