[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/lock ...

Manik Surtani manik at jboss.org
Mon Jul 30 07:12:47 EDT 2007


  User: msurtani
  Date: 07/07/30 07:12:47

  Added:       tests/functional/org/jboss/cache/lock  Tag:
                        Branch_JBossCache_1_4_0 PessimisticLockTest.java
  Log:
  JBCACHE-1157
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +89 -0     JBossCache/tests/functional/org/jboss/cache/lock/Attic/PessimisticLockTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PessimisticLockTest.java
  ===================================================================
  RCS file: PessimisticLockTest.java
  diff -N PessimisticLockTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ PessimisticLockTest.java	30 Jul 2007 11:12:47 -0000	1.1.2.1
  @@ -0,0 +1,89 @@
  +package org.jboss.cache.lock;
  +
  +import junit.framework.TestCase;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.DummyTransactionManagerLookup;
  +import org.jboss.cache.Node;
  +
  +import javax.transaction.TransactionManager;
  +
  +/**
  + * basic locking test
  + *
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  + * @since 2.0.0
  + */
  +public class PessimisticLockTest extends TestCase
  +{
  +   private TreeCache cache;
  +   private TransactionManager tm;
  +   private Fqn fqn = Fqn.fromString("/a/b/c");
  +
  +   protected void setUp() throws Exception
  +   {
  +      cache = new TreeCache();
  +      cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
  +      cache.start();
  +      tm = cache.getTransactionManager();
  +   }
  +
  +   protected void tearDown()
  +   {
  +      cache.stop();
  +   }
  +
  +   public void testPut() throws Exception
  +   {
  +      cache.put(fqn, "k", "v");
  +
  +      tm.begin();
  +      cache.put(fqn, "k2", "v2");
  +      Node n = cache.get(fqn);
  +
  +      assertFalse(n.getLock().isReadLocked());
  +      assertTrue(n.getLock().isWriteLocked());
  +      assertTrue(n.getParent().getLock().isReadLocked());
  +      assertFalse(n.getParent().getLock().isWriteLocked());
  +      assertTrue(n.getParent().getParent().getLock().isReadLocked());
  +      assertFalse(n.getParent().getParent().getLock().isWriteLocked());
  +
  +      tm.commit();
  +   }
  +
  +   public void testGet() throws Exception
  +   {
  +      cache.put(fqn, "k", "v");
  +
  +      tm.begin();
  +      cache.get(fqn, "k2");
  +      Node n = cache.get(fqn);
  +
  +      assertTrue(n.getLock().isReadLocked());
  +      assertFalse(n.getLock().isWriteLocked());
  +      assertTrue(n.getParent().getLock().isReadLocked());
  +      assertFalse(n.getParent().getLock().isWriteLocked());
  +      assertTrue(n.getParent().getParent().getLock().isReadLocked());
  +      assertFalse(n.getParent().getParent().getLock().isWriteLocked());
  +
  +      tm.commit();
  +   }
  +
  +   public void testRemove() throws Exception
  +   {
  +      cache.put(fqn, "k", "v");
  +      tm.begin();
  +      cache.remove(fqn, "k2");
  +      Node n = cache.get(fqn);
  +
  +      assertFalse(n.getLock().isReadLocked());
  +      assertTrue(n.getLock().isWriteLocked());
  +      assertTrue(n.getParent().getLock().isReadLocked());
  +      assertFalse(n.getParent().getLock().isWriteLocked());
  +      assertTrue(n.getParent().getParent().getLock().isReadLocked());
  +      assertFalse(n.getParent().getParent().getLock().isWriteLocked());
  +
  +      tm.commit();
  +
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list