[jbosscache-commits] JBoss Cache SVN: r4637 - core/trunk/src/test/java/org/jboss/cache/optimistic.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Oct 17 14:55:32 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-10-17 14:55:32 -0400 (Wed, 17 Oct 2007)
New Revision: 4637

Modified:
   core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
Log:
[JBCACHE-1201] Add test of SyncCommitPhase=false

Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java	2007-10-17 16:32:01 UTC (rev 4636)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java	2007-10-17 18:55:32 UTC (rev 4637)
@@ -12,6 +12,7 @@
 import javax.transaction.TransactionManager;
 
 import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -653,6 +654,16 @@
    {
       return createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_SYNC);
    }
+   
+   protected CacheImpl<Object, Object> createSyncReplicatedCacheAsyncCommit() throws Exception
+   {
+      CacheImpl<Object, Object> cache = createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_SYNC, false);
+      cache.getConfiguration().setSyncCommitPhase(false);
+      cache.getConfiguration().setSyncRollbackPhase(false);
+      cache.create();
+      cache.start();
+      return cache;
+   }
 
    public void testPuts() throws Exception
    {
@@ -773,5 +784,59 @@
          throw e;
       }
    }
+   
+   /**
+    * Tests that if synchronous commit messages are not used, the proper
+    * data is returned from remote nodes after a tx that does a local
+    * put returns.
+    * 
+    * @throws Exception
+    */
+   public void testAsynchronousCommit() throws Exception 
+   {
+      CacheImpl<Object, Object> cache1 = createSyncReplicatedCacheAsyncCommit();
+      CacheImpl<Object, Object> cache2 = createSyncReplicatedCacheAsyncCommit();
+      // Test will pass if we set up the caches with SyncCommitPhaseTrue
+//      CacheImpl<Object, Object> cache1 = createSyncReplicatedCache();
+//      CacheImpl<Object, Object> cache2 = createSyncReplicatedCache();
+      
+      TransactionManager tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
+      
+      Fqn<String> fqn = Fqn.fromString("/test/node");
+      String KEY = "key";
+      String VALUE1 = "value1";
+      
+      tm1.begin();
+      cache1.put(fqn, KEY, VALUE1);
+      tm1.commit();
+      
+      // A simple sleep will also make this test pass
+//      try { Thread.sleep(100); } catch (InterruptedException e) {}
+      
+      assertEquals("Known issue JBCACHE-1201: Correct node2 value", VALUE1, cache2.get(fqn, KEY));
+      assertEquals("Correct node1 value", VALUE1, cache1.get(fqn, KEY));
+      
+      destroyCache(cache1);
+      destroyCache(cache2);
+  }
+   
+   private void rollback(TransactionManager tm) {
+       try {
+           tm.rollback();
+       }
+       catch (Exception e) {
+           log.error(e.getMessage(), e);
+       }
+       
+   }
+   
+  private class ExceptionHolder
+  {
+     Exception node1Exception;
+     Exception node2Exception;
+     
+     AssertionFailedError node1Failure;
+     AssertionFailedError node2Failure;
+  }
 
 }




More information about the jbosscache-commits mailing list