/*
 * JBoss, the OpenSource J2EE webOS
 * 
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.test.jca.test;

import javax.resource.cci.Connection;
import javax.transaction.Transaction;

/**
 * Contentious pooling stress test.
 * 
 * @author <a href="adrian@jboss.com">Adrian Brock</a>
 * @version $Revision: 1.1.2.3 $
 */
public class ContentiousStickyStressTestCase extends AbstractContentiousPoolingStressTest
{
   public boolean isSticky()
   {
      return true;
   }
   
   public void testContentiousInterleavingStressTestcase() throws Throwable
   {
      tm.setTransactionTimeout(0);
      tm.begin();
      final Transaction tx = tm.suspend();
      ContentiousPoolingRunnable[] runnables = new ContentiousPoolingRunnable[getThreadCount()];
      for (int i = 0; i < runnables.length; ++i)
      {
         runnables[i] = new ContentiousPoolingRunnable(tx)
         {
            public void doRun() throws Throwable
            {
               Connection c = cf.getConnection();
               c.close();
            }
         };
      }

      runConcurrentTest(runnables, new ConcurrentTestCallback()
            {
               public void finished() throws Throwable
               {
                  tm.resume(tx);
                  tm.commit();
               }
            });
   }
   
   public ContentiousStickyStressTestCase(String name)
   {
      super(name);
   }
}
