public void testCacheContentionOnNode() throws Exception
{
final int threads = 10, loops = 100;
TreeCache cache = null;
try
{
cache = new TreeCache();
cache.startService();
cache.put("/test/node", null);
final DataNode node = cache.get("/test/node");
final List exceptions = new ArrayList();
final List timeouts = new ArrayList();
// get a hold of the WL first
node.acquire(Thread.currentThread(), 10, DataNode.LOCK_TYPE_WRITE);
Thread[] t = new Thread[threads];
for (int i=0; i<t.length; i++)
{
t[i] = new Thread()
{
public void run()
{
for (int i=0; i<loops; i++)
{
try
{
node.acquire(Thread.currentThread(), 10, DataNode.LOCK_TYPE_WRITE);
}
catch (TimeoutException te)
{
// expected
timeouts.add( te );
}
catch (Exception ex)
{
ex.printStackTrace();
exceptions.add(ex);
}
}
}
};
t[i].start();
}
for (int i=0; i<t.length; i++) t[i].join();
node.releaseAll(Thread.currentThread());
// we should have 0 exceptions
assertEquals(0, exceptions.size());
}
finally
{
if (cache != null) cache.stopService();
}
}