ClientConnectionRequest connRequest = mgr.requestConnection(ROUTE, null);
ManagedClientConnection conn = connRequest.getConnection(0, null);
Assert.assertNotNull(conn);
// send a thread waiting
GetConnThread gct = new GetConnThread(mgr, ROUTE, 0L);
gct.start();
Thread.sleep(100); // give extra thread time to block
Assert.assertEquals("thread not waiting",
Thread.State.WAITING, gct.getState());
// get access to the objects we need
Lock lck = mgr.extendedCPBR.getLock();
Condition cnd = mgr.extendedCPBR.newestWT.getCondition();
// Now trigger spurious wakeups. We'll do it several times
// in a loop, just to be sure the connection manager has a
// fair chance of misbehaving, and the gct to register it.
for (int i=0; i<3; i++) {
if (i > 0)
Thread.sleep(333); // don't go too fast
try {
lck.lock();
cnd.signalAll(); // this is the spurious wakeup
} finally {
lck.unlock();
}
// now give the waiting thread some time to register a wakeup
Thread.sleep(100);
Assert.assertEquals("thread no longer waiting, iteration " + i,
Thread.State.WAITING, gct.getState());
}
} finally {
// don't worry about releasing the connection, just shut down
mgr.shutdown();
}