[hibernate-commits] Hibernate SVN: r14253 - in core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2: entity and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Dec 21 14:48:42 EST 2007


Author: bstansberry at jboss.com
Date: 2007-12-21 14:48:42 -0500 (Fri, 21 Dec 2007)
New Revision: 14253

Modified:
   core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
   core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
   core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractReadOnlyAccessTestCase.java
   core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractTransactionalAccessTestCase.java
Log:
Add workaround to avoid delays from concurrent FLUSH calls in JGroups 2.6.1
Use different "entity keys" per test to avoid cross-test pollution

Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java	2007-12-21 19:47:30 UTC (rev 14252)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java	2007-12-21 19:48:42 UTC (rev 14253)
@@ -64,10 +64,12 @@
 public abstract class AbstractCollectionRegionAccessStrategyTestCase extends AbstractJBossCacheTestCase {
 
     public static final String REGION_NAME = "test/com.foo.test";
-    public static final String KEY = "KEY";
+    public static final String KEY_BASE = "KEY";
     public static final String VALUE1 = "VALUE1";
     public static final String VALUE2 = "VALUE2";
     
+    protected static int testCount;
+    
     protected static Configuration localCfg;
     protected static JBossCacheRegionFactory localRegionFactory;
     protected static Cache localCache;
@@ -114,12 +116,18 @@
     protected void setUp() throws Exception {
         super.setUp();
         
+        // Sleep a bit to avoid concurrent FLUSH problem
+        avoidConcurrentFlush();
+        
         invalidation = CacheHelper.isClusteredInvalidation(localCache);
         synchronous = CacheHelper.isSynchronous(localCache);
         optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
         localCollectionRegion = localRegionFactory.buildCollectionRegion(REGION_NAME, localCfg.getProperties(), getCacheDataDescription());
         localAccessStrategy = localCollectionRegion.buildAccessStrategy(getAccessType());
         
+        // Sleep a bit to avoid concurrent FLUSH problem
+        avoidConcurrentFlush();
+        
         remoteCollectionRegion = remoteRegionFactory.buildCollectionRegion(REGION_NAME, remoteCfg.getProperties(), getCacheDataDescription());
         remoteAccessStrategy = remoteCollectionRegion.buildAccessStrategy(getAccessType());
         
@@ -229,6 +237,8 @@
      */
     private void putFromLoadTest(final boolean useMinimalAPI) throws Exception {
         
+        final String KEY = KEY_BASE + testCount++;
+        
         final CountDownLatch writeLatch1 = new CountDownLatch(1);
         final CountDownLatch writeLatch2 = new CountDownLatch(1);
         final CountDownLatch completionLatch = new CountDownLatch(2);
@@ -400,6 +410,9 @@
     }
 
     private void evictOrRemoveTest(boolean evict) {
+       
+        final String KEY = KEY_BASE + testCount++;
+        
         assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
         assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
         
@@ -422,6 +435,8 @@
     }
 
     private void evictOrRemoveAllTest(boolean evict) {
+       
+        final String KEY = KEY_BASE + testCount++;
         
         Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);
         

Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java	2007-12-21 19:47:30 UTC (rev 14252)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java	2007-12-21 19:48:42 UTC (rev 14253)
@@ -64,10 +64,12 @@
 public abstract class AbstractEntityRegionAccessStrategyTestCase extends AbstractJBossCacheTestCase {
 
     public static final String REGION_NAME = "test/com.foo.test";
-    public static final String KEY = "KEY";
+    public static final String KEY_BASE = "KEY";
     public static final String VALUE1 = "VALUE1";
     public static final String VALUE2 = "VALUE2";
     
+    protected static int testCount;
+    
     protected static Configuration localCfg;
     protected static JBossCacheRegionFactory localRegionFactory;
     protected static Cache localCache;
@@ -116,9 +118,15 @@
     protected void setUp() throws Exception {
         super.setUp();
         
+        // Sleep a bit to avoid concurrent FLUSH problem
+        avoidConcurrentFlush();
+        
         localEntityRegion = localRegionFactory.buildEntityRegion(REGION_NAME, localCfg.getProperties(), getCacheDataDescription());
         localAccessStrategy = localEntityRegion.buildAccessStrategy(getAccessType());
         
+        // Sleep a bit to avoid concurrent FLUSH problem
+        avoidConcurrentFlush();
+        
         remoteEntityRegion = remoteRegionFactory.buildEntityRegion(REGION_NAME, remoteCfg.getProperties(), getCacheDataDescription());
         remoteAccessStrategy = remoteEntityRegion.buildAccessStrategy(getAccessType());
                 
@@ -186,6 +194,24 @@
     protected Fqn getRegionFqn(String regionName, String regionPrefix) {
         return BasicRegionAdapter.getTypeLastRegionFqn(regionName, regionPrefix, EntityRegionImpl.TYPE);
     }
+
+    protected void assertThreadsRanCleanly()
+    {
+        if (node1Failure != null)
+            throw node1Failure;
+        if (node2Failure != null)
+            throw node2Failure;
+      
+        if (node1Exception != null) {
+            log.error("node1 saw an exception", node1Exception);
+            assertEquals("node1 saw no exceptions", null, node1Exception);
+        }
+        
+        if (node2Exception != null) {
+            log.error("node2 saw an exception", node2Exception);
+            assertEquals("node2 saw no exceptions", null, node2Exception);
+        }
+    }
     
     /**
      * This is just a setup test where we assert that the cache config is
@@ -220,7 +246,7 @@
      * Second tries to do a putFromLoad with stale data (i.e. it took
      * longer to read from the db).  Both commit their tx. Then
      * both start a new tx and get. First should see the updated data;
-     * second should either see the updated data (isInvalidation()( == false)
+     * second should either see the updated data (isInvalidation() == false)
      * or null (isInvalidation() == true).
      * 
      * @param useMinimalAPI
@@ -228,6 +254,8 @@
      */
     private void putFromLoadTest(final boolean useMinimalAPI) throws Exception {
         
+        final String KEY = KEY_BASE + testCount++;
+        
         final CountDownLatch writeLatch1 = new CountDownLatch(1);
         final CountDownLatch writeLatch2 = new CountDownLatch(1);
         final CountDownLatch completionLatch = new CountDownLatch(2);
@@ -319,14 +347,8 @@
         
         assertTrue("Threads completed", completionLatch.await(2, TimeUnit.SECONDS));
         
-        if (node1Failure != null)
-            throw node1Failure;
-        if (node2Failure != null)
-            throw node2Failure;
+        assertThreadsRanCleanly();
         
-        assertEquals("node1 saw no exceptions", null, node1Exception);
-        assertEquals("node2 saw no exceptions", null, node2Exception);
-        
         long txTimestamp = System.currentTimeMillis();
         assertEquals("Correct node1 value", VALUE2, localAccessStrategy.get(KEY, txTimestamp));
         
@@ -349,6 +371,8 @@
      * Test method for {@link TransactionalAccess#insert(java.lang.Object, java.lang.Object, java.lang.Object)}.
      */
     public void testInsert() throws Exception {
+       
+        final String KEY = KEY_BASE + testCount++;
         
         final CountDownLatch readLatch = new CountDownLatch(1);
         final CountDownLatch commitLatch = new CountDownLatch(1);
@@ -431,14 +455,8 @@
             assertTrue("Threads completed", completionLatch.await(1, TimeUnit.SECONDS));
         }
         
-        if (node1Failure != null)
-            throw node1Failure;
-        if (node2Failure != null)
-            throw node2Failure;
+        assertThreadsRanCleanly();
         
-        assertEquals("node1 saw no exceptions", null, node1Exception);
-        assertEquals("node2 saw no exceptions", null, node2Exception);
-        
         long txTimestamp = System.currentTimeMillis();
         assertEquals("Correct node1 value", VALUE1, localAccessStrategy.get(KEY, txTimestamp));
         Object expected = isUsingInvalidation() ? null : VALUE1;
@@ -449,6 +467,8 @@
      * Test method for {@link TransactionalAccess#update(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)}.
      */
     public void testUpdate() throws Exception {
+       
+        final String KEY = KEY_BASE + testCount++;
         
         // Set up initial state
         localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
@@ -542,14 +562,8 @@
             assertTrue(completionLatch.await(1, TimeUnit.SECONDS));
         }
         
-        if (node1Failure != null)
-            throw node1Failure;
-        if (node2Failure != null)
-            throw node2Failure;
+        assertThreadsRanCleanly();
         
-        assertEquals("node1 saw no exceptions", null, node1Exception);
-        assertEquals("node2 saw no exceptions", null, node2Exception);
-        
         long txTimestamp = System.currentTimeMillis();
         assertEquals("Correct node1 value", VALUE2, localAccessStrategy.get(KEY, txTimestamp));
         Object expected = isUsingInvalidation() ? null : VALUE2;
@@ -591,6 +605,9 @@
     }
 
     private void evictOrRemoveTest(boolean evict) {
+       
+        final String KEY = KEY_BASE + testCount++;
+        
         assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));
         assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
         
@@ -615,6 +632,8 @@
     }
 
     private void evictOrRemoveAllTest(boolean evict) {
+       
+        final String KEY = KEY_BASE + testCount++;
         
         Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);
         
@@ -641,14 +660,16 @@
         
         localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
         assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
+        
+        // Wait for async propagation
+        sleep(250);
+        
         remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
         assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
         
         // Wait for async propagation
         sleep(250);
         
-
-        
         if (isUsingOptimisticLocking()) {
             regionRoot = localCache.getRoot().getChild(regionFqn);
             assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());

Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractReadOnlyAccessTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractReadOnlyAccessTestCase.java	2007-12-21 19:47:30 UTC (rev 14252)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractReadOnlyAccessTestCase.java	2007-12-21 19:48:42 UTC (rev 14253)
@@ -58,6 +58,9 @@
     }
     
     private void putFromLoadTest(boolean minimal) throws Exception {
+       
+        final String KEY = KEY_BASE + testCount++;
+        
         long txTimestamp = System.currentTimeMillis();
         BatchModeTransactionManager.getInstance().begin();
         assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
@@ -77,6 +80,9 @@
 
     @Override
     public void testUpdate() throws Exception {
+       
+        final String KEY = KEY_BASE + testCount++;
+        
         try {
             localAccessStrategy.update(KEY, VALUE2, new Integer(2), new Integer(1));
             fail("Call to update did not throw exception");

Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractTransactionalAccessTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractTransactionalAccessTestCase.java	2007-12-21 19:47:30 UTC (rev 14252)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractTransactionalAccessTestCase.java	2007-12-21 19:48:42 UTC (rev 14253)
@@ -53,6 +53,8 @@
     }
     
     public void testContestedPutFromLoad() throws Exception {
+       
+        final String KEY = KEY_BASE + testCount++;
         
         localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));
                
@@ -129,14 +131,8 @@
         
         assertTrue("Threads completed", completionLatch.await(1, TimeUnit.SECONDS));
         
-        if (node1Failure != null)
-            throw node1Failure;
-        if (node2Failure != null)
-            throw node2Failure;
+        assertThreadsRanCleanly();
         
-        assertEquals("node1 saw no exceptions", null, node1Exception);
-        assertEquals("node2 saw no exceptions", null, node2Exception);
-        
         long txTimestamp = System.currentTimeMillis();
         assertEquals("Correct node1 value", VALUE2, localAccessStrategy.get(KEY, txTimestamp));
     }




More information about the hibernate-commits mailing list