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

Galder Zamarreno galder.zamarreno at jboss.com
Tue Feb 27 11:22:49 EST 2007


  User: gzamarreno
  Date: 07/02/27 11:22:49

  Added:       tests/functional/org/jboss/cache/optimistic  Tag:
                        Branch_JBossCache_1_4_0 RemoveAfterPutTest.java
  Log:
  Unit test replicating issue explained in SF case 00014268
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +72 -0     JBossCache/tests/functional/org/jboss/cache/optimistic/Attic/RemoveAfterPutTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RemoveAfterPutTest.java
  ===================================================================
  RCS file: RemoveAfterPutTest.java
  diff -N RemoveAfterPutTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ RemoveAfterPutTest.java	27 Feb 2007 16:22:49 -0000	1.1.2.1
  @@ -0,0 +1,72 @@
  +/*
  + * JBoss, the OpenSource J2EE webOS
  + * 
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.cache.optimistic;
  +
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.transaction.DummyTransactionManager;
  +
  +import javax.transaction.Transaction;
  +
  +import junit.framework.TestCase;
  +
  +/**
  + * Tests a remove call followed by a put withing the same transaction for optimistic cache instance 
  + *
  + * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  + */
  +public class RemoveAfterPutTest extends TestCase
  +{
  +   private TreeCache treeCache;
  +
  +   protected void setUp() throws Exception
  +   {
  +      treeCache = new TreeCache();
  +      treeCache.setNodeLockingScheme("OPTIMISTIC");
  +      treeCache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
  +      treeCache.setCacheMode("LOCAL");
  +      treeCache.setUseRegionBasedMarshalling(false);
  +
  +      treeCache.startService();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      treeCache.stopService();
  +   }
  +
  +   public void testRemoveAfterPutInTx() throws Exception
  +   {
  +      DummyTransactionManager mgr = DummyTransactionManager.getInstance();
  +
  +      /* Put data in the cache within a transaction */
  +      mgr.begin();
  +      Transaction tx = mgr.getTransaction();
  +      assertNull(treeCache.get("/a"));
  +      Long nextId = new Long(0L);
  +      treeCache.put("/a", "key", nextId);
  +      tx.commit();
  +
  +      /* Start a new transaction, retrieve the value from the cache and remove the original node.
  +      * Update the value from the cache and put it again in the previously remove node */
  +      try
  +      {
  +         mgr.begin();
  +         tx = mgr.getTransaction();
  +         nextId = (Long)treeCache.get("/a", "key");
  +         treeCache.remove("/a");
  +         nextId = new Long(nextId.longValue() +1);
  +         treeCache.put("/a", "key", nextId);
  +         tx.commit();
  +      }
  +      finally
  +      {
  +         tx.rollback();
  +      }
  +
  +      assertEquals(nextId, treeCache.get("/a", "key"));
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list