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

Manik Surtani msurtani at jboss.com
Wed Jan 3 18:45:56 EST 2007


  User: msurtani
  Date: 07/01/03 18:45:56

  Modified:    tests/functional/org/jboss/cache/api      CacheAPITest.java
                        CacheSPITest.java NodeAPITest.java
  Added:       tests/functional/org/jboss/cache/api     
                        NodeAPIOptimisticTest.java
                        CacheAPIOptimisticTest.java
  Log:
  Added optimistic locking specific tests
  
  Revision  Changes    Path
  1.9       +8 -5      JBossCache/tests/functional/org/jboss/cache/api/CacheAPITest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheAPITest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/api/CacheAPITest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- CacheAPITest.java	2 Jan 2007 18:26:05 -0000	1.8
  +++ CacheAPITest.java	3 Jan 2007 23:45:56 -0000	1.9
  @@ -26,11 +26,14 @@
   public class CacheAPITest extends TestCase
   {
      private Cache cache;
  +   protected boolean optimistic;
   
  -   protected void setUp()
  +   protected void setUp() throws Exception
      {
         // start a single cache instance
  -      cache = DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml");
  +      cache = DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml", false);
  +      cache.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
  +      cache.start();
      }
   
      protected void tearDown()
  @@ -277,7 +280,7 @@
      public void testRegion()
      {
         Region rootRegion = cache.getRegion(Fqn.ROOT, true);
  -      assertNotNull(rootRegion);  // guaranteed never to return null if createIfAbsent is true.
  +      assertNotNull(rootRegion);// guaranteed never to return null if createIfAbsent is true.
         assertSame(rootRegion, cache.getRegion(Fqn.ROOT, true));
   
         Region otherRegion = cache.getRegion(Fqn.fromString("/other/region"), true);
  @@ -291,7 +294,7 @@
      public void testParentRegion1()
      {
         Region rootRegion = cache.getRegion(Fqn.ROOT, true);
  -      assertNotNull(rootRegion);  // guaranteed never to return null if createIfAbsent is true.
  +      assertNotNull(rootRegion);// guaranteed never to return null if createIfAbsent is true.
         assertSame(rootRegion, cache.getRegion(Fqn.ROOT, false));
   
         Region otherRegion = cache.getRegion(Fqn.fromString("/other/region"), false);
  @@ -320,7 +323,7 @@
      public void testNullRegion()
      {
         Region myRegion = cache.getRegion(Fqn.fromString("/myregion"), true);
  -      assertNotNull(myRegion);  // guaranteed never to return null if createIfAbsent is true.
  +      assertNotNull(myRegion);// guaranteed never to return null if createIfAbsent is true.
         assertSame(myRegion, cache.getRegion(Fqn.fromString("/myregion"), false));
   
         Region otherRegion = cache.getRegion(Fqn.fromString("/other/region"), false);
  
  
  
  1.4       +5 -0      JBossCache/tests/functional/org/jboss/cache/api/CacheSPITest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheSPITest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/api/CacheSPITest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- CacheSPITest.java	2 Jan 2007 18:26:05 -0000	1.3
  +++ CacheSPITest.java	3 Jan 2007 23:45:56 -0000	1.4
  @@ -13,6 +13,8 @@
      private CacheSPI cache1;
      private CacheSPI cache2;
   
  +   protected boolean optimistic = false;
  +
      protected void setUp() throws Exception
      {
         super.setUp();
  @@ -22,6 +24,9 @@
   
         Configuration conf2 = parser.parseFile("META-INF/replSync-service.xml");
   
  +      conf1.setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
  +      conf2.setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
  +
         cache1 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(conf1, false);
         cache2 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(conf2, false);
      }
  
  
  
  1.12      +41 -8     JBossCache/tests/functional/org/jboss/cache/api/NodeAPITest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeAPITest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/api/NodeAPITest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -b -r1.11 -r1.12
  --- NodeAPITest.java	2 Jan 2007 18:26:05 -0000	1.11
  +++ NodeAPITest.java	3 Jan 2007 23:45:56 -0000	1.12
  @@ -4,6 +4,7 @@
   import org.jboss.cache.CacheImpl;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  +import org.jboss.cache.config.Configuration;
   import org.jboss.cache.factories.DefaultCacheFactory;
   
   import javax.transaction.TransactionManager;
  @@ -26,10 +27,14 @@
      private static final Fqn A = Fqn.fromString("/a"), B = Fqn.fromString("/b"), C = Fqn.fromString("/c"), D = Fqn
              .fromString("/d");
   
  -   protected void setUp()
  +   protected boolean optimistic = false;
  +
  +   protected void setUp() throws Exception
      {
         // start a single cache instance
  -      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml");
  +      cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml", false);
  +      cache.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
  +      cache.start();
         rootNode = cache.getRoot();
         tm = cache.getTransactionManager();
      }
  @@ -37,10 +42,33 @@
      protected void tearDown()
      {
         if (cache != null)
  +      {
            cache.stop();
  +      }
         if (rootNode != null)
  +      {
            rootNode = null;
      }
  +   }
  +
  +   public void testAddingData()
  +   {
  +      Node nodeA = rootNode.addChild(A);
  +      nodeA.put("key", "value");
  +
  +      assertEquals("value", nodeA.get("key"));
  +   }
  +
  +   public void testAddingDataTx() throws Exception
  +   {
  +      tm.begin();
  +      Node nodeA = rootNode.addChild(A);
  +      nodeA.put("key", "value");
  +
  +      assertEquals("value", nodeA.get("key"));
  +      tm.commit();
  +   }
  +
   
      /**
       * Remember, Fqns are relative!!
  @@ -91,14 +119,17 @@
         Node nodeB = nodeA.addChild(B);
         Node nodeC = nodeB.addChild(C);
   
  +      if (!optimistic)
  +      {
         assertEquals(3, cache.getNumberOfNodes());
         assertEquals(4, cache.getNumberOfLocksHeld());
  +      }
         tm.commit();
   
         tm.begin();
         assertEquals(0, cache.getNumberOfLocksHeld());
         nodeC.put("key", "value");
  -      assertEquals(4, cache.getNumberOfLocksHeld());
  +      if (!optimistic) assertEquals(4, cache.getNumberOfLocksHeld());
         tm.commit();
      }
   
  @@ -148,9 +179,11 @@
         cache.put(new Fqn(A, B), "1", "1");
         cache.put(new Fqn(A, C), "2", "2");
   
  +      if (!optimistic)
  +      {
         assertEquals(3, cache.getNumberOfNodes());
         assertEquals(4, cache.getNumberOfLocksHeld());
  -
  +      }
         assertEquals("Number of child", 2, cache.getRoot().getChild(A).getChildren().size());
         tm.commit();
      }
  
  
  
  1.1      date: 2007/01/03 23:45:56;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/api/NodeAPIOptimisticTest.java
  
  Index: NodeAPIOptimisticTest.java
  ===================================================================
  package org.jboss.cache.api;
  
  /**
   * An optimistic version of {@link org.jboss.cache.api.NodeAPITest}
   */
  public class NodeAPIOptimisticTest extends NodeAPITest
  {
  
     public NodeAPIOptimisticTest()
     {
        optimistic = true;
     }
  }
  
  
  
  1.1      date: 2007/01/03 23:45:56;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/api/CacheAPIOptimisticTest.java
  
  Index: CacheAPIOptimisticTest.java
  ===================================================================
  package org.jboss.cache.api;
  
  /**
   * Optimistically locked version of {@link org.jboss.cache.api.CacheAPITest}
   */
  public class CacheAPIOptimisticTest extends CacheAPITest
  {
  
     public CacheAPIOptimisticTest()
     {
        optimistic = true;
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list