[jbosscache-commits] JBoss Cache SVN: r4898 - in core/trunk/src: main/java/org/jboss/cache/factories and 5 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Dec 20 12:14:25 EST 2007


Author: manik.surtani at jboss.com
Date: 2007-12-20 12:14:25 -0500 (Thu, 20 Dec 2007)
New Revision: 4898

Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
   core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
   core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
   core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
   core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java
   core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
   core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
   core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java
   core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
Log:
Optimistic locking fixes

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -3777,7 +3777,7 @@
       if (found)
       {
          componentRegistry.registerComponent(i);
-         interceptors.add(position++, i);
+         interceptors.add(++position, i);
          setInterceptorChain(factory.correctInterceptorChaining(interceptors));
       }
    }

Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -589,8 +589,6 @@
     */
    public Interceptor correctInterceptorChaining(List<Interceptor> interceptors)
    {
-      // re-wire
-      componentRegistry.updateDependencies();
 
       Interceptor first = null, last = null;
 
@@ -608,7 +606,10 @@
       if (last != null) last.setNext(null);
 
       // now set the 'last' pointer.
-      return setLastInterceptorPointer(first, last);
+      Interceptor i = setLastInterceptorPointer(first, last);
+      // re-register this interceptor
+      componentRegistry.registerComponent(Interceptor.class.getName(), i);
+      return i;
    }
 
    /**

Modified: core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -16,6 +16,8 @@
 @DefaultFactoryFor(classes = {TransactionManager.class})
 public class TransactionManagerFactory extends ComponentFactory
 {
+   boolean messageLogged = false;
+
    @Override
    @SuppressWarnings("unchecked")
    protected <T> T construct(String componentName, Class<T> componentType)
@@ -49,14 +51,18 @@
             }
             else
             {
-               if (configuration.getNodeLockingScheme() == Configuration.NodeLockingScheme.OPTIMISTIC)
+               if (!messageLogged)
                {
-                  log.fatal("No transaction manager lookup class has been defined. Transactions cannot be used and thus OPTIMISTIC locking cannot be used");
+                  messageLogged = true;
+                  if (configuration.getNodeLockingScheme() == Configuration.NodeLockingScheme.OPTIMISTIC)
+                  {
+                     log.fatal("No transaction manager lookup class has been defined. Transactions cannot be used and thus OPTIMISTIC locking cannot be used");
+                  }
+                  else
+                  {
+                     log.info("No transaction manager lookup class has been defined. Transactions cannot be used");
+                  }
                }
-               else
-               {
-                  log.info("No transaction manager lookup class has been defined. Transactions cannot be used");
-               }
             }
          }
          catch (Exception e)

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -556,6 +556,10 @@
          workspaceNode.setVersioningImplicit(false);
       }
 
+      // now make sure all parents are in the wsp as well
+      if (workspaceNode != null && !fqn.isRoot())
+         fetchWorkspaceNode(fqn.getParent(), workspace, false, includeInvalidNodes);
+
       return workspaceNode;
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -3,21 +3,18 @@
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.ActivationInterceptor;
+import org.jboss.cache.interceptors.PassivationInterceptor;
 import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.reflect.ReflectionUtil;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
-/**
- * Created by IntelliJ IDEA.
- * User: bela
- * Date: Jun 9, 2004
- * Time: 9:05:19 AM
- */
+ at Test(groups = {"functional"})
 public class LocalDelegatingCacheLoaderTest extends CacheLoaderTestsBase
 {
    CacheSPI delegating_cache;
 
-   @SuppressWarnings("deprecation")
    protected void configureCache() throws Exception
    {
       delegating_cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
@@ -31,8 +28,8 @@
       // force our own cache loader instance
       LocalDelegatingCacheLoader cacheLoader = new LocalDelegatingCacheLoader(delegating_cache);
 
-      // don't actually alter the interceptor chain, but this will force a re-injection of all deps in all components.
-      TestingUtil.replaceInterceptorChain(cache, cache.getInterceptorChain().get(0));
+      ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, PassivationInterceptor.class), "loader", cacheLoader);
+      ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, ActivationInterceptor.class), "loader", cacheLoader);
    }
 
    protected void postConfigure()

Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -17,7 +17,6 @@
 import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
 import org.jboss.cache.loader.CacheLoader;
 import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.util.CachePrinter;
 
 import java.io.File;
 import java.lang.reflect.Field;
@@ -90,20 +89,7 @@
     */
    public static void injectInterceptor(CacheSPI<?, ?> cache, Interceptor interceptorToInject, Class<? extends Interceptor> interceptorAfterWhichToInject)
    {
-      System.out.println("Old interceptor chain: " + CachePrinter.printCacheInterceptors(cache));
-      // make sure the new interceptor is wired
-      ComponentRegistry cr = extractComponentRegistry(cache);
-      cr.registerComponent(interceptorToInject);
-      interceptorToInject.setCache(cache);
-      int index = -1;
-      for (Interceptor i : cache.getInterceptorChain())
-      {
-         index++;
-         if (interceptorAfterWhichToInject.isInstance(i)) break;
-      }
-
-      cache.addInterceptor(interceptorToInject, index + 1);
-      System.out.println("New interceptor chain: " + CachePrinter.printCacheInterceptors(cache));
+      cache.addInterceptor(interceptorToInject, interceptorAfterWhichToInject);
    }
 
    /**

Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -12,7 +12,6 @@
 import org.jboss.cache.VersionedNode;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.invocation.NodeInvocationDelegate;
-import org.jboss.cache.loader.SamplePojo;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodCallFactory;
 import org.jboss.cache.marshall.MethodDeclarations;
@@ -100,7 +99,6 @@
                }
                catch (Exception e)
                {
-                  log.fatal("*** Thew an exception!!", e);
                   setException(e);
                }
             }
@@ -141,10 +139,8 @@
       assertEquals(0, c.getTransactionTable().getNumGlobalTransactions());
       assertEquals(0, c.getTransactionTable().getNumLocalTransactions());
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+      c.put("/one/two", "key1", "value");
 
-      c.put("/one/two", "key1", pojo);
-
       mgr.commit();
 
       assertNull(mgr.getTransaction());
@@ -174,9 +170,8 @@
       assertEquals(0, c.getTransactionTable().getNumGlobalTransactions());
       assertEquals(0, c.getTransactionTable().getNumLocalTransactions());
 
-      SamplePojo pojo = new SamplePojo(21, "test");
       mgr.begin();
-      c.put("/one/two", "key1", pojo);
+      c.put("/one/two", "key1", "value");
       mgr.rollback();
       assertNull(mgr.getTransaction());
       assertEquals(0, c.getTransactionTable().getNumGlobalTransactions());
@@ -207,10 +202,8 @@
       //this sets
       c.getCurrentTransaction(tx, true);
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+      c.put("/one/two", "key1", "value");
 
-      c.put("/one/two", "key1", pojo);
-
       GlobalTransaction gtx = c.getCurrentTransaction(tx, true);
       TransactionTable table = c.getTransactionTable();
       OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
@@ -263,10 +256,8 @@
       mgr.begin();
 
       //this sets
-      SamplePojo pojo = new SamplePojo(21, "test");
+      cache.put("/one/two", "key1", "value");
 
-      cache.put("/one/two", "key1", pojo);
-
       //GlobalTransaction gtx = cache.getCurrentTransaction(tx);
       assertNotNull(mgr.getTransaction());
       mgr.commit();
@@ -279,14 +270,14 @@
 
       assertTrue(cache.exists(Fqn.fromString("/one/two")));
       assertTrue(cache.exists(Fqn.fromString("/one")));
-      assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));
+      assertEquals("value", cache.get(Fqn.fromString("/one/two"), "key1"));
 
       assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
       assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
 
       assertTrue(cache2.exists(Fqn.fromString("/one/two")));
       assertTrue(cache2.exists(Fqn.fromString("/one")));
-      assertEquals(pojo, cache2.get(Fqn.fromString("/one/two"), "key1"));
+      assertEquals("value", cache2.get(Fqn.fromString("/one/two"), "key1"));
 
       destroyCache(cache);
       destroyCache(cache2);
@@ -310,10 +301,8 @@
       //this sets
       cache.getCurrentTransaction(tx, true);
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+      cache.put("/one/two", "key1", "value");
 
-      cache.put("/one/two", "key1", pojo);
-
       assertNotNull(mgr.getTransaction());
       mgr.commit();
 
@@ -325,7 +314,7 @@
 
       assertTrue(cache.exists(Fqn.fromString("/one/two")));
       assertTrue(cache.exists(Fqn.fromString("/one")));
-      assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));
+      assertEquals("value", cache.get(Fqn.fromString("/one/two"), "key1"));
 
       assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
       assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
@@ -333,41 +322,13 @@
       assertTrue(cache2.exists(Fqn.fromString("/one/two")));
       assertTrue(cache2.exists(Fqn.fromString("/one")));
 
-      assertEquals(pojo, cache2.get(Fqn.fromString("/one/two"), "key1"));
+      assertEquals("value", cache2.get(Fqn.fromString("/one/two"), "key1"));
 
       destroyCache(cache);
       destroyCache(cache2);
 
    }
 
-   //   public void testRemotePessCacheBroadcast() throws Exception
-   //   {
-   //      destroyCache(c);
-   //
-   //      CacheSPI cache = createPessimisticCache();
-   //      CacheSPI cache2 = createPessimisticCache();
-   //
-   //      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
-   //
-   //      //start local transaction
-   //      mgr.begin();
-   //      Transaction tx = mgr.getTransaction();
-   //
-   //      //this sets
-   //      cache.getCurrentTransaction(tx);
-   //
-   //      SamplePojo pojo = new SamplePojo(21, "test");
-   //
-   //      cache.put("/one/two", "key1", pojo);
-   //
-   //
-   //      mgr.commit();
-   //
-   //      destroyCache(cache);
-   //      destroyCache(cache2);
-   //
-   //   }
-
    public void testConcurrentNodeRemoval() throws Exception
    {
       c.put(fqn, "key", "value");

Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -2,6 +2,7 @@
 
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.ComponentRegistry;
 import org.jboss.cache.interceptors.Interceptor;
 import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
 import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
@@ -11,6 +12,8 @@
 import org.jboss.cache.transaction.OptimisticTransactionEntry;
 import org.jboss.cache.transaction.TransactionTable;
 import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import javax.transaction.Transaction;
@@ -23,23 +26,42 @@
 @Test(groups = {"functional"})
 public class NodeInterceptorGetChildrenNamesTest extends AbstractOptimisticTestCase
 {
-   public void testTransactionGetNamesMethod() throws Exception
+   TestListener listener;
+   CacheSPI<Object, Object> cache;
+   MockInterceptor dummy;
+   TransactionManager mgr;
+
+   @BeforeMethod
+   public void setUp() throws Exception
    {
+      listener = new TestListener();
+      cache = createCacheWithListener(listener);
 
-      TestListener listener = new TestListener();
-      final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+      ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
 
       Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
+      cr.registerComponent(interceptor);
       Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
-      MockInterceptor dummy = new MockInterceptor();
+      cr.registerComponent(nodeInterceptor);
+      dummy = new MockInterceptor();
+      cr.registerComponent(dummy);
 
       interceptor.setNext(nodeInterceptor);
       nodeInterceptor.setNext(dummy);
 
       TestingUtil.replaceInterceptorChain(cache, interceptor);
 
-//		 first set up a node with a pojo
-      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+      mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+   }
+
+   @AfterMethod
+   public void tearDown()
+   {
+      TestingUtil.killCaches(cache);
+   }
+
+   public void testTransactionGetNamesMethod() throws Exception
+   {
       mgr.begin();
       Transaction tx = mgr.getTransaction();
 
@@ -87,27 +109,11 @@
 
       assertEquals(0, cache.getRoot().getChildrenNames().size());
       mgr.commit();
-      cache.stop();
    }
 
 
    public void testTransactionGetNoNamesMethod() throws Exception
    {
-
-      TestListener listener = new TestListener();
-      final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
-      Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
-      Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
-      MockInterceptor dummy = new MockInterceptor();
-
-      interceptor.setNext(nodeInterceptor);
-      nodeInterceptor.setNext(dummy);
-
-      TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-//		 first set up a node with a pojo
-      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
       mgr.begin();
       Transaction tx = mgr.getTransaction();
 
@@ -132,29 +138,11 @@
       assertEquals(0, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
       assertEquals(null, dummy.getCalled());
-
-
-      cache.stop();
    }
 
 
    public void testTransactionGetNamesIteratorMethod() throws Exception
    {
-
-      TestListener listener = new TestListener();
-      final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
-      Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
-      Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
-      MockInterceptor dummy = new MockInterceptor();
-
-      interceptor.setNext(nodeInterceptor);
-      nodeInterceptor.setNext(dummy);
-
-      TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-//		 first set up a node with a pojo
-      TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
       mgr.begin();
       Transaction tx = mgr.getTransaction();
 
@@ -204,8 +192,5 @@
       assertEquals(1, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
       assertEquals(null, dummy.getCalled());
-
-
-      cache.stop();
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -9,10 +9,8 @@
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
-import org.jboss.cache.factories.InterceptorChainFactory;
 import org.jboss.cache.interceptors.CallInterceptor;
-import org.jboss.cache.interceptors.Interceptor;
-import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.marshall.MethodDeclarations;
 import org.jboss.cache.transaction.GlobalTransaction;
 import org.jboss.cache.transaction.OptimisticTransactionEntry;
 import org.jboss.cache.transaction.TransactionTable;
@@ -31,7 +29,7 @@
 /**
  * @author xenephon
  */
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 @SuppressWarnings("unchecked")
 public class NodeInterceptorRemoveNodeTest extends AbstractOptimisticTestCase
 {
@@ -49,19 +47,9 @@
       dummy = new MockInterceptor();
       dummy.setCache(cache);
 
-      Interceptor interceptor = cache.getInterceptorChain().get(0); // get the first interceptor
-      // replace the last (call) interceptor with the mock interceptor.
-      Interceptor next = interceptor, prev = interceptor;
-      while (!(next instanceof CallInterceptor))
-      {
-         prev = next;
-         next = next.getNext();
-      }
+      cache.addInterceptor(dummy, CallInterceptor.class);
+      cache.removeInterceptor(CallInterceptor.class);
 
-      prev.setNext(dummy);
-
-      InterceptorChainFactory.setLastInterceptorPointer(interceptor, dummy);
-
       mgr = cache.getTransactionManager();
    }
 
@@ -90,15 +78,17 @@
       TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 
       mgr.commit();
-      assertEquals(null, dummy.getCalled());
 
+      assert 2 == dummy.getAllCalled().size();
+      assert dummy.getAllCalled().contains(MethodDeclarations.commitMethod);
+      assert dummy.getAllCalled().contains(MethodDeclarations.optimisticPrepareMethod);
+
       //assert what should be the results of our call
       assertEquals(0, workspace.getNodes().size());
 
       assertTrue(entry.getLocks().isEmpty());
       assertEquals(1, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
-      assertEquals(null, dummy.getCalled());
       assertEquals(0, listener.getNodesAdded());
    }
 
@@ -111,13 +101,15 @@
       cache.getInvocationContext().setTransaction(tx);
       cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+
       Map temp = new HashMap();
-      temp.put("key1", pojo);
+      temp.put("key1", "value");
       cache.put("/one/two", temp);
 
       cache.removeNode("/one/two");
-      assertEquals(null, dummy.getCalled());
+
+      assert dummy.getAllCalled().isEmpty();
+
       TransactionTable table = cache.getTransactionTable();
 
       GlobalTransaction gtx = table.get(tx);
@@ -140,7 +132,6 @@
       System.out.println(entry.getModifications());
       assertEquals(2, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
-      assertEquals(null, dummy.getCalled());
    }
 
    public void testTransactionRemoveIntermediateNodeMethod() throws Exception
@@ -152,9 +143,9 @@
       cache.getInvocationContext().setTransaction(tx);
       cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+
       Map temp = new HashMap();
-      temp.put("key1", pojo);
+      temp.put("key1", "value");
       cache.put("/one/two", temp);
 
       cache.removeNode("/one");
@@ -179,7 +170,10 @@
       assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(0).size());
       assertEquals(2, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
-      assertEquals(null, dummy.getCalled());
+      assert 2 == dummy.getAllCalled().size();
+      assert dummy.getAllCalled().contains(MethodDeclarations.commitMethod);
+      assert dummy.getAllCalled().contains(MethodDeclarations.optimisticPrepareMethod);
+
    }
 
    public void testTransactionRemoveTwiceMethod() throws Exception
@@ -191,9 +185,9 @@
       cache.getInvocationContext().setTransaction(tx);
       cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+
       Map temp = new HashMap();
-      temp.put("key1", pojo);
+      temp.put("key1", "value");
       cache.put("/one/two", temp);
 
       // get the transaction stuff
@@ -234,7 +228,9 @@
 
       assertEquals(3, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
-      assertEquals(null, dummy.getCalled());
+      assert 2 == dummy.getAllCalled().size();
+      assert dummy.getAllCalled().contains(MethodDeclarations.commitMethod);
+      assert dummy.getAllCalled().contains(MethodDeclarations.optimisticPrepareMethod);
    }
 
 
@@ -247,9 +243,9 @@
       cache.getInvocationContext().setTransaction(tx);
       cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+
       Map temp = new HashMap();
-      temp.put("key1", pojo);
+      temp.put("key1", "value");
       cache.put("/one/two", temp);
 
       // get the transaction stuff
@@ -292,7 +288,9 @@
 
 
       assertEquals(3, entry.getModifications().size());
-      assertEquals(null, dummy.getCalled());
+      assert 2 == dummy.getAllCalled().size();
+      assert dummy.getAllCalled().contains(MethodDeclarations.commitMethod);
+      assert dummy.getAllCalled().contains(MethodDeclarations.optimisticPrepareMethod);
       assertEquals(2, listener.getNodesAdded());
    }
 
@@ -306,9 +304,9 @@
       cache.getInvocationContext().setTransaction(tx);
       cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+
       Map temp = new HashMap();
-      temp.put("key1", pojo);
+      temp.put("key1", "value");
       cache.put("/one/two", temp);
 
       // get the transaction stuff
@@ -331,8 +329,7 @@
       assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
 
       //now put /one back in
-      SamplePojo pojo2 = new SamplePojo(21, "test");
-      cache.put(new Fqn("one"), "key1", pojo2);
+      cache.put(new Fqn("one"), "key1", "value2");
 
       WorkspaceNode oneAfter = workspace.getNode(Fqn.fromString("/one"));
       WorkspaceNode twoAfter = workspace.getNode(Fqn.fromString("/one/two"));
@@ -346,14 +343,17 @@
 
       mgr.commit();
 
-      assertEquals(pojo2, workspace.getNode(Fqn.fromString("/one")).get("key1"));
+      assertEquals("value2", workspace.getNode(Fqn.fromString("/one")).get("key1"));
       //assert what should be the results of our call
       assertEquals(3, workspace.getNodes().size());
 
 
       assertEquals(3, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
-      assertEquals(null, dummy.getCalled());
+      assert 2 == dummy.getAllCalled().size();
+      assert dummy.getAllCalled().contains(MethodDeclarations.commitMethod);
+      assert dummy.getAllCalled().contains(MethodDeclarations.optimisticPrepareMethod);
+
       assertEquals(2, listener.getNodesAdded());
    }
 
@@ -366,9 +366,9 @@
       cache.getInvocationContext().setTransaction(tx);
       cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
 
-      SamplePojo pojo = new SamplePojo(21, "test");
+
       Map temp = new HashMap();
-      temp.put("key1", pojo);
+      temp.put("key1", "value");
       cache.put("/one/two", temp);
 
       // get the transaction stuff
@@ -401,7 +401,10 @@
 
       assertEquals(2, entry.getModifications().size());
       assertTrue(!cache.exists("/one/two"));
-      assertEquals(null, dummy.getCalled());
+      assert 2 == dummy.getAllCalled().size();
+      assert dummy.getAllCalled().contains(MethodDeclarations.commitMethod);
+      assert dummy.getAllCalled().contains(MethodDeclarations.optimisticPrepareMethod);
+
       assertEquals(2, listener.getNodesAdded());
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -21,9 +21,11 @@
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 import javax.transaction.RollbackException;
 import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.ObjectInput;
@@ -35,6 +37,7 @@
  * @author xenephon
  */
 @SuppressWarnings("unchecked")
+ at Test(groups = "functional")
 public class OptimisticReplicationInterceptorTest extends AbstractOptimisticTestCase
 {
    private CacheSPI cache;
@@ -459,10 +462,10 @@
 
       CacheSPI cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
       MockInterceptor dummy2 = new MockInterceptor();
-      setAlteredInterceptorChain(dummy, cache);
+      setAlteredInterceptorChain(dummy2, cache2);
 
 
-      DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+      TransactionManager mgr = cache.getTransactionManager();
 
       //start local transaction
       mgr.begin();
@@ -478,7 +481,6 @@
       assertNotNull(mgr.getTransaction());
       mgr.commit();
 
-
       assertNull(mgr.getTransaction());
 
       //assert that the local cache is in the right state
@@ -491,6 +493,7 @@
 
 
       List calls = dummy.getAllCalled();
+
       assertEquals(MethodDeclarations.optimisticPrepareMethod, calls.get(0));
       assertEquals(MethodDeclarations.commitMethod, calls.get(1));
 
@@ -515,7 +518,7 @@
       List failures = new ArrayList();
       failures.add(MethodDeclarations.optimisticPrepareMethod);
       dummy2.setFailurelist(failures);
-      setAlteredInterceptorChain(dummy, cache);
+      setAlteredInterceptorChain(dummy2, cache2);
 
       DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 

Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -9,12 +9,14 @@
 import static org.testng.AssertJUnit.assertNull;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 import javax.transaction.TransactionManager;
 
 /**
  * Tests removal of a node before the node is even created.
  */
+ at Test(groups = "functional")
 public class RemoveBeforeCreateTest extends AbstractOptimisticTestCase
 {
    CacheSPI<Object, Object>[] c = null;

Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java	2007-12-20 17:09:38 UTC (rev 4897)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java	2007-12-20 17:14:25 UTC (rev 4898)
@@ -3,10 +3,14 @@
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.ActivationInterceptor;
+import org.jboss.cache.interceptors.PassivationInterceptor;
 import org.jboss.cache.loader.CacheLoader;
 import org.jboss.cache.loader.LocalDelegatingCacheLoader;
 import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.reflect.ReflectionUtil;
 import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
 
 /**
  * Runs a test against using delegated cache loader
@@ -14,6 +18,7 @@
  * @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
  * @version $Id$
  */
+ at Test(groups = "functional")
 public class PassivationToLocalDelegatingCacheLoaderTest extends PassivationTestsBase
 {
    CacheSPI delegating_cache;
@@ -31,8 +36,8 @@
       cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig("", "org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false));
       cache.getCacheLoaderManager().setCacheLoader(cache_loader);
 
-      // don't actually alter the interceptor chain, but this will force a re-injection of all deps in all components.
-      TestingUtil.replaceInterceptorChain(cache, cache.getInterceptorChain().get(0));
+      ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, PassivationInterceptor.class), "loader", cache_loader);
+      ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, ActivationInterceptor.class), "loader", cache_loader);
    }
 
    @AfterMethod(alwaysRun = true)




More information about the jbosscache-commits mailing list