Package org.jboss.cache.invocation

Examples of org.jboss.cache.invocation.InvocationContextContainer


@Test(groups = {"unit", "mvcc"}, testName = "util.concurrent.locks.OwnableReentrantLockTest")
public class OwnableReentrantLockTest
{
   private InvocationContextContainer getInvocationContextContainer()
   {
      InvocationContextContainer icc = new InvocationContextContainer();
      icc.injectContextFactory(new MVCCContextFactory());
      return icc;
   }
View Full Code Here


      return icc;
   }

   public void testReentrancyThread()
   {
      InvocationContextContainer icc = getInvocationContextContainer();
      OwnableReentrantLock lock = new OwnableReentrantLock(icc);

      lock.lock(); // locked by current thread
      assert lock.getOwner().equals(Thread.currentThread());
      assert lock.getHoldCount() == 1;
View Full Code Here

      assert lock.getHoldCount() == 0;
   }

   public void testReentrancyGtx()
   {
      InvocationContextContainer icc = getInvocationContextContainer();
      OwnableReentrantLock lock = new OwnableReentrantLock(icc);

      // create and set a gtx
      GlobalTransaction gtx = new GlobalTransaction();
      gtx.setId(10);
      icc.get().setGlobalTransaction(gtx);

      lock.lock(); // locked by current thread
      assert lock.getOwner().equals(gtx);
      assert lock.getHoldCount() == 1;
View Full Code Here

      assert lock.getHoldCount() == 0;
   }

   public void testReentrancyNotSameGtx()
   {
      InvocationContextContainer icc = getInvocationContextContainer();
      OwnableReentrantLock lock = new OwnableReentrantLock(icc);

      // create and set a gtx
      GlobalTransaction gtx = new GlobalTransaction();
      gtx.setId(10);
      icc.get().setGlobalTransaction(gtx);

      GlobalTransaction gtx2 = new GlobalTransaction();
      gtx2.setId(10);

      assert gtx != gtx2;

      lock.lock(); // locked by current thread
      assert lock.getOwner().equals(gtx);
      assert lock.getHoldCount() == 1;

      icc.get().setGlobalTransaction(gtx2);
      lock.lock();
      assert lock.getOwner().equals(gtx2);
      assert lock.getHoldCount() == 2;

      lock.unlock();
      assert lock.getOwner().equals(gtx2);
      assert lock.getHoldCount() == 1;

      icc.get().setGlobalTransaction(gtx);
      lock.unlock();
      assert lock.getOwner() == null;
      assert lock.getHoldCount() == 0;
   }
View Full Code Here

      assert lock.getHoldCount() == 0;
   }

   public void testThreadLockedByThread() throws InterruptedException
   {
      InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      final AtomicBoolean acquired = new AtomicBoolean(false);
      final AtomicBoolean threwExceptionOnRelease = new AtomicBoolean(false);

View Full Code Here

      assert !lock.isLocked();
   }

   public void testThreadLockedByGtx() throws InterruptedException
   {
      InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      GlobalTransaction gtx = new GlobalTransaction();
      gtx.setId(10);
      icc.get().setGlobalTransaction(gtx);
      final AtomicBoolean acquired = new AtomicBoolean(false);
      final AtomicBoolean threwExceptionOnRelease = new AtomicBoolean(false);

      lock.lock();
      assert lock.getOwner().equals(gtx);
View Full Code Here

      assert !lock.isLocked();
   }

   public void testGtxLockedByThread() throws InterruptedException
   {
      final InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      final AtomicBoolean acquired = new AtomicBoolean(false);
      final AtomicBoolean threwExceptionOnRelease = new AtomicBoolean(false);

      lock.lock();
      assert lock.getOwner().equals(Thread.currentThread());
      assert lock.getHoldCount() == 1;

      Thread t = new Thread()
      {
         public void run()
         {
            try
            {
               GlobalTransaction gtx = new GlobalTransaction();
               gtx.setId(10);
               icc.get().setGlobalTransaction(gtx);
               acquired.set(lock.tryLock(10, TimeUnit.MILLISECONDS));
            }
            catch (InterruptedException e)
            {
               // do nothing
View Full Code Here

      assert !lock.isLocked();
   }

   public void testGtxLockedByGtxFail() throws InterruptedException
   {
      final InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      final AtomicBoolean acquired = new AtomicBoolean(false);
      final AtomicBoolean threwExceptionOnRelease = new AtomicBoolean(false);
      GlobalTransaction gtx = new GlobalTransaction();
      gtx.setId(10);
      icc.get().setGlobalTransaction(gtx);

      lock.lock();
      assert lock.getOwner().equals(gtx);
      assert lock.getHoldCount() == 1;

      Thread t = new Thread()
      {
         public void run()
         {
            try
            {
               GlobalTransaction gtx = new GlobalTransaction();
               gtx.setId(20);
               icc.get().setGlobalTransaction(gtx);
               acquired.set(lock.tryLock(10, TimeUnit.MILLISECONDS));
            }
            catch (InterruptedException e)
            {
               // do nothing
View Full Code Here

      assert !lock.isLocked();
   }

   public void testGtxLockedByGtxSuccess() throws InterruptedException
   {
      final InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      final AtomicBoolean acquired = new AtomicBoolean(false);
      GlobalTransaction gtx = new GlobalTransaction();
      gtx.setId(10);
      icc.get().setGlobalTransaction(gtx);

      lock.lock();
      assert lock.getOwner().equals(gtx);
      assert lock.getHoldCount() == 1;

      Thread t = new Thread()
      {
         public void run()
         {
            try
            {
               GlobalTransaction gtx = new GlobalTransaction();
               gtx.setId(10);
               icc.get().setGlobalTransaction(gtx);
               acquired.set(lock.tryLock(10, TimeUnit.MILLISECONDS));
            }
            catch (InterruptedException e)
            {
               // do nothing
View Full Code Here

      assert !lock.isLocked();
   }

   public void satisfyCodeCoverage() throws InterruptedException
   {
      final InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      lock.lockInterruptibly();

      try
      {
View Full Code Here

TOP

Related Classes of org.jboss.cache.invocation.InvocationContextContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.