[jboss-cvs] JBossAS SVN: r71455 - in projects/ejb3/branches/cluster-dev/ejb3-cache/src/test: java/org/jboss/ejb3/test/cache/integrated and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 30 23:23:15 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-03-30 23:23:15 -0400 (Sun, 30 Mar 2008)
New Revision: 71455

Modified:
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/distributed/GroupedPassivatingUnitTestCase.java
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/GroupAwareTransactionalCacheUnitTestCase.java
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/TransactionalCacheUnitTestCase.java
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/resources/log4j.xml
Log:
[EJBTHREE-1026] Add some basic tests with transactions in effect

Modified: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/distributed/GroupedPassivatingUnitTestCase.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/distributed/GroupedPassivatingUnitTestCase.java	2008-03-31 01:39:46 UTC (rev 71454)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/distributed/GroupedPassivatingUnitTestCase.java	2008-03-31 03:23:15 UTC (rev 71455)
@@ -44,7 +44,17 @@
    public void testSimpleGroupPassivation() throws Exception
    {      
       log.info("====== testSimpleGroupPassivation() ======");
-      
+      simpleGroupPassivationTest(false);
+   }
+   
+   public void testSimpleGroupPassivationTransactional() throws Exception
+   {      
+      log.info("====== testSimpleGroupPassivationTransactional() ======");
+      simpleGroupPassivationTest(true);
+   }
+   
+   public void simpleGroupPassivationTest(boolean transactional) throws Exception
+   {      
       MockCluster cluster = new MockCluster(false);
       MockClusterMember node0 = cluster.getNode0();
       MockCacheConfig cacheConfig = new MockCacheConfig();
@@ -56,6 +66,11 @@
       node0.setTCCL();
       try
       {
+         if (transactional)
+         {
+            node0.getTransactionManager().begin();
+         }
+         
          Object key1 = container1.getCache().create(null, null);
          MockBeanContext firstCtx1;
          MockBeanContext ctx1 = firstCtx1 = container1.getCache().get(key1);
@@ -69,6 +84,11 @@
          container2.getCache().finished(ctx2);
          container1.getCache().finished(ctx1);
          
+         if (transactional)
+         {
+            node0.getTransactionManager().commit();
+         }
+         
          sleep(2100);
          
          MockPassivationManager pass1 = (MockPassivationManager) container1.getPassivationManager();
@@ -76,6 +96,11 @@
          
          assertEquals("ctx1 should have been passivated", 1, pass1.getPrePassivateCount());
          assertEquals("ctx2 should have been passivated", 1, pass2.getPrePassivateCount());
+
+         if (transactional)
+         {
+            node0.getTransactionManager().begin();
+         }
          
          ctx2 = container2.getCache().get(key2);
          
@@ -97,6 +122,14 @@
          
          assertNotNull(ctx1.getXPC());
          assertSame(ctx1.getXPC(), ctx2.getXPC());
+         
+         container1.getCache().finished(ctx1);
+         container2.getCache().finished(ctx2);
+         
+         if (transactional)
+         {
+            node0.getTransactionManager().commit();
+         }
       }
       finally
       {
@@ -115,7 +148,17 @@
    public void testSimpleGroupReplication() throws Exception
    {      
       log.info("====== testSimpleGroupReplication() ======");
-      
+      simpleGroupReplicationTest(false);
+   }
+   
+   public void testSimpleGroupReplicationTransactional() throws Exception
+   {      
+      log.info("====== testSimpleGroupReplicationTransactional() ======");
+      simpleGroupReplicationTest(true);
+   }
+   
+   public void simpleGroupReplicationTest(boolean transactional) throws Exception
+   {      
       MockCluster cluster = new MockCluster(false);
       MockCacheConfig cacheConfig = new MockCacheConfig();
       cacheConfig.setIdleTimeoutSeconds(1);
@@ -135,6 +178,11 @@
       cluster.getNode0().setTCCL();
       try
       {
+         if (transactional)
+         {
+            cluster.getNode0().getTransactionManager().begin();
+         }
+         
          key1 = container1A.getCache().create(null, null);
          MockBeanContext ctx1A = container1A.getCache().get(key1);
          
@@ -150,11 +198,21 @@
          container2A.getCache().finished(ctx2A);
          container1A.getCache().finished(ctx1A);
          
+         if (transactional)
+         {
+            cluster.getNode0().getTransactionManager().commit();
+         }
+         
          MockPassivationManager pass1A = (MockPassivationManager) container1A.getPassivationManager();
          MockPassivationManager pass2A = (MockPassivationManager) container2A.getPassivationManager();
          
          assertEquals("ctx1 should have been replicated", 1, pass1A.getPreReplicateCount());
          assertEquals("ctx2 should have been passivated", 1, pass2A.getPreReplicateCount());
+
+         if (transactional)
+         {
+            cluster.getNode0().getTransactionManager().begin();
+         }
          
          ctx2A = container2A.getCache().get(key2);
          
@@ -180,6 +238,11 @@
          
          container1A.getCache().finished(ctx1A);         
          container2A.getCache().finished(ctx2A);
+         
+         if (transactional)
+         {
+            cluster.getNode0().getTransactionManager().commit();
+         }
       }
       catch (Exception e)
       {
@@ -196,6 +259,12 @@
       cluster.getNode1().setTCCL();
       try
       {
+
+         if (transactional)
+         {
+            cluster.getNode1().getTransactionManager().begin();
+         }
+         
          MockBeanContext ctx1B = container1B.getCache().get(key1);         
          MockBeanContext ctx2B = container2B.getCache().get(key2);
          
@@ -206,6 +275,11 @@
          
          container2B.getCache().finished(ctx2B);         
          container1B.getCache().finished(ctx1B);
+         
+         if (transactional)
+         {
+            cluster.getNode1().getTransactionManager().commit();
+         }
       }
       catch (Exception e)
       {

Modified: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/GroupAwareTransactionalCacheUnitTestCase.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/GroupAwareTransactionalCacheUnitTestCase.java	2008-03-31 01:39:46 UTC (rev 71454)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/GroupAwareTransactionalCacheUnitTestCase.java	2008-03-31 03:23:15 UTC (rev 71455)
@@ -44,7 +44,7 @@
    @Override
    protected Cache<MockBeanContext> createCache() throws Exception
    {
-      MockEjb3System system = new MockEjb3System(false, CacheType.SIMPLE);
+      MockEjb3System system = new MockEjb3System(tm, false, CacheType.SIMPLE);
       MockBeanContainer ejb = system.deployBeanContainer("test", null, CacheType.SIMPLE);
       return ejb.getCache();
    }
@@ -52,26 +52,51 @@
    public void testNonGroupedPassivation() throws Exception
    {    
       log.info("testNonGroupedPassivation()");
-      
-      MockEjb3System system = new MockEjb3System(false, CacheType.SIMPLE);
+      nonGroupedPassivationTest(false);
+   }
+   
+   public void testNonGroupedPassivationTransactional() throws Exception
+   {    
+      log.info("testNonGroupedPassivationTransactional()");
+      nonGroupedPassivationTest(true);
+   }
+   
+   private void nonGroupedPassivationTest(boolean transactional) throws Exception
+   {    
+      MockEjb3System system = new MockEjb3System(tm, false, CacheType.SIMPLE);
       MockXPC sharedXPC = new MockXPC();
       MockCacheConfig config = new MockCacheConfig();
       config.setIdleTimeoutSeconds(4);
       MockBeanContainer container = system.deployBeanContainer("MockBeanContainer1", null, CacheType.SIMPLE, config, sharedXPC.getName());
       Cache<MockBeanContext> cache = container.getCache();
       
+      if (transactional)
+      {
+         tm.begin();
+      }
+      
       Object key = cache.create(null, null);
       MockBeanContext obj = cache.get(key);
       
-      cache.finished(obj);
+      cache.finished(obj);      
       obj = null;
       
+      if (transactional)
+      {
+         tm.commit();
+      }
+      
       wait(container);
       
       MockPassivationManager pass = (MockPassivationManager) container.getPassivationManager();
       
       assertEquals("MockBeanContext should have been passivated", 1, pass.getPrePassivateCount());
       
+      if (transactional)
+      {
+         tm.begin();
+      }
+      
       obj = cache.get(key);
       assertNotNull(obj);
       
@@ -81,21 +106,34 @@
       
       assertEquals("MockBeanContext should not have been passivated", 1, pass.getPrePassivateCount());
       
-      cache.finished(obj);
+      cache.finished(obj);      
       obj = null;
       
+      if (transactional)
+      {
+         tm.commit();
+      }
+      
       wait(container);
       
       assertEquals("MockBeanContext should have been passivated", 2, pass.getPrePassivateCount());
    }
 
+   public void testSimpleGroupPassivation() throws Exception
+   {    
+      log.info("testSimpleGroupPassivation()");
+      simpleGroupPassivationTest(false);
+   }
 
+   public void testSimpleGroupPassivationTransactional() throws Exception
+   {    
+      log.info("testSimpleGroupPassivationTransactional()");
+      simpleGroupPassivationTest(true);
+   }
 
-   public void testSimpleGroupPassivation() throws Exception
+   public void simpleGroupPassivationTest(boolean transactional) throws Exception
    {    
-      log.info("testSimpleGroupPassivation()");
-      
-      MockEjb3System system = new MockEjb3System(false, CacheType.SIMPLE);
+      MockEjb3System system = new MockEjb3System(tm, false, CacheType.SIMPLE);
       MockXPC sharedXPC = new MockXPC();
       MockCacheConfig config = new MockCacheConfig();
       config.setIdleTimeoutSeconds(1);
@@ -107,7 +145,12 @@
       assertTrue(container1.hasChild(container2));
       
       try
-      {
+      {         
+         if (transactional)
+         {
+            tm.begin();
+         }
+         
          Object key1 = container1.getCache().create(null, null);
          MockBeanContext firstCtx1;
          MockBeanContext ctx1 = firstCtx1 = container1.getCache().get(key1);
@@ -121,6 +164,11 @@
          container2.getCache().finished(ctx2);
          container1.getCache().finished(ctx1);
          
+         if (transactional)
+         {
+            tm.commit();
+         }
+         
          log.info("Finished with contexts");
          
          sleep(2100);
@@ -134,6 +182,11 @@
          
          log.info("Restoring ctx2");
          
+         if (transactional)
+         {
+            tm.begin();
+         }
+         
          ctx2 = container2.getCache().get(key2);
          
          log.info("ctx2 = " + ctx2);
@@ -153,6 +206,11 @@
          container1.getCache().finished(ctx1);         
          container2.getCache().finished(ctx2);
          
+         if (transactional)
+         {
+            tm.commit();
+         }
+         
       }
       finally
       {
@@ -167,8 +225,26 @@
    public void testRecursiveCalls() throws Exception
    {    
       log.info("testRecursiveCalls()");
+      recursiveCallsTest(false);
+   }
+   
+   /**
+    * Test call to bean1 that calls into bean2 that calls back into bean1
+    */
+   public void testRecursiveCallsTransactional() throws Exception
+   {    
+      log.info("testRecursiveCallsTransactional()");
+      recursiveCallsTest(true);
+   }
+   
+   /**
+    * Test call to bean1 that calls into bean2 that calls back into bean1
+    */
+   public void recursiveCallsTest(boolean transactional) throws Exception
+   {    
+      log.info("testRecursiveCalls()");
       
-      MockEjb3System system = new MockEjb3System(false, CacheType.SIMPLE);
+      MockEjb3System system = new MockEjb3System(tm, false, CacheType.SIMPLE);
       MockXPC sharedXPC = new MockXPC();
       MockCacheConfig config = new MockCacheConfig();
       config.setIdleTimeoutSeconds(1);
@@ -180,7 +256,12 @@
       assertTrue(container1.hasChild(container2));
       
       try
-      {
+      {         
+         if (transactional)
+         {
+            tm.begin();
+         }
+         
          Object key1 = container1.getCache().create(null, null);
          MockBeanContext firstCtx1;
          MockBeanContext ctx1 = firstCtx1 = container1.getCache().get(key1);
@@ -199,6 +280,11 @@
          container2.getCache().finished(ctx2);
          container1.getCache().finished(firstCtx1);
          
+         if (transactional)
+         {
+            tm.commit();
+         }
+         
       }
       finally
       {

Modified: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/TransactionalCacheUnitTestCase.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/TransactionalCacheUnitTestCase.java	2008-03-31 01:39:46 UTC (rev 71454)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/cache/integrated/TransactionalCacheUnitTestCase.java	2008-03-31 03:23:15 UTC (rev 71455)
@@ -22,12 +22,14 @@
 package org.jboss.ejb3.test.cache.integrated;
 
 import javax.ejb.NoSuchEJBException;
+import javax.transaction.TransactionManager;
 
 import org.jboss.ejb3.cache.api.Cache;
 import org.jboss.ejb3.test.cache.mock.CacheType;
 import org.jboss.ejb3.test.cache.mock.MockBeanContainer;
 import org.jboss.ejb3.test.cache.mock.MockBeanContext;
 import org.jboss.ejb3.test.cache.mock.MockEjb3System;
+import org.jboss.ejb3.test.cache.mock.tm.MockTransactionManager;
 import org.jboss.logging.Logger;
 
 /**
@@ -41,9 +43,11 @@
 {   
    private static final Logger log = Logger.getLogger(TransactionalCacheUnitTestCase.class);
    
+   protected TransactionManager tm =  MockTransactionManager.getInstance();
+   
    protected Cache<MockBeanContext> createCache() throws Exception
    {
-      MockEjb3System system = new MockEjb3System(false, CacheType.NON_PASSIVATING);
+      MockEjb3System system = new MockEjb3System(tm, false, CacheType.NON_PASSIVATING);
       MockBeanContainer ejb = system.deployBeanContainer("test", null, CacheType.NON_PASSIVATING);
       return ejb.getCache();
    }
@@ -68,9 +72,24 @@
    public void testSimpleLifeCycle() throws Exception
    {
       log.info("testSimpleLifeCycle()");
-      
+      simpleLifeCycleTest(false);
+   }
+   
+   public void testSimpleLifeCycleTransactional() throws Exception
+   {
+      log.info("testSimpleLifeCycleTransactional()");
+      simpleLifeCycleTest(true);
+   }
+   
+   private void simpleLifeCycleTest(boolean transactional) throws Exception
+   {
       Cache<MockBeanContext> cache = createCache();
       
+      if (transactional)
+      {
+         tm.begin();
+      }
+      
       Object key = cache.create(null, null);
       MockBeanContext object = cache.get(key);
       
@@ -78,6 +97,11 @@
       
       cache.remove(key);
       
+      if (transactional)
+      {
+         tm.commit();
+      }
+      
       try
       {
          cache.get(key);
@@ -91,8 +115,25 @@
    
    public void testSequentialGetCalls() throws Exception
    {
+      log.info("testSequentialGetCalls()");
+      sequentialGetCallsTest(false);
+   }
+   
+   public void testSequentialGetCallsTransactional() throws Exception
+   {
+      log.info("testSequentialGetCallsTransactional()");
+      sequentialGetCallsTest(true);
+   }
+   
+   private void sequentialGetCallsTest(boolean transactional) throws Exception
+   {
       Cache<MockBeanContext> cache = createCache();
       
+      if (transactional)
+      {
+         tm.begin();
+      }
+      
       Object key = cache.create(null, null);
       MockBeanContext object = cache.get(key);
       
@@ -106,14 +147,36 @@
       cache.finished(object);
       
       cache.remove(key);
+      
+      if (transactional)
+      {
+         tm.commit();
+      }
    }
    
    public void testExcessFinishedCalls() throws Exception
    {    
       log.info("testExcessFinishedCalls()");
+      excessFinishedCallsTest(false);
+   }
+   
+   public void testExcessFinishedCallsTransactional() throws Exception
+   {    
+      log.info("testExcessFinishedCallsTransactional()");
+      excessFinishedCallsTest(true);
+   }
+   
+   private void excessFinishedCallsTest(boolean transactional) throws Exception
+   {    
+      log.info("testExcessFinishedCalls()");
       
       Cache<MockBeanContext> cache = createCache();
       
+      if (transactional)
+      {
+         tm.begin();
+      }
+      
       Object key = cache.create(null, null);
       MockBeanContext object = cache.get(key);
       
@@ -132,6 +195,11 @@
       }
       finally {
          cache.remove(key);
+         
+         if (transactional)
+         {
+            tm.commit();
+         }
       }
    }
 }

Modified: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/resources/log4j.xml	2008-03-31 01:39:46 UTC (rev 71454)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/resources/log4j.xml	2008-03-31 03:23:15 UTC (rev 71455)
@@ -114,8 +114,26 @@
 
   <!-- Limit JBoss categories to INFO -->
   <category name="org.jboss">
-    <priority value="INFO" class="org.jboss.logging.XLevel"/>
+    <priority value="INFO"/>
   </category>
+  <category name="org.jgroups">
+    <priority value="INFO"/>
+  </category>
+  <category name="org.jboss.cache">
+    <priority value="TRACE"/>
+  </category>
+  <category name="org.jboss.cache.interceptors">
+    <priority value="INFO"/>
+  </category>
+  <category name="org.jboss.cache.lock">
+    <priority value="INFO"/>
+  </category>
+  <category name="org.jboss.cache.RegionManager">
+    <priority value="INFO"/>
+  </category>
+  <category name="org.jboss.cache.interceptors.ReplicationInterceptor">
+    <priority value="TRACE"/>
+  </category>
 
   <!-- Increase the priority threshold for the DefaultDS category
   <category name="DefaultDS">




More information about the jboss-cvs-commits mailing list