You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2016/03/02 21:54:45 UTC

incubator-geode git commit: Added a test for JTA rollback

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1040 [created] f70646af0


Added a test for JTA rollback


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f70646af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f70646af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f70646af

Branch: refs/heads/feature/GEODE-1040
Commit: f70646af0e33ffcd1899cf5f3323624e53e68473
Parents: e1a0830
Author: Sai Boorlagadda <sb...@pivotal.io>
Authored: Wed Mar 2 12:54:15 2016 -0800
Committer: Sai Boorlagadda <sb...@pivotal.io>
Committed: Wed Mar 2 12:54:15 2016 -0800

----------------------------------------------------------------------
 .../cache/ClientServerTransactionDUnitTest.java | 56 ++++++++++++++------
 1 file changed, 39 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f70646af/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
index add43a0..50a198b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
@@ -388,22 +388,26 @@ public class ClientServerTransactionDUnitTest extends RemoteTransactionDUnitTest
   }
 
   public void testBasicCommitOnEmpty() {
-    doBasicCommit(false, false);
+    doBasicTransaction(false, false, true);
   }
   
   public void testBasicCommitOnEmptyUsingJTA() {
-    doBasicCommit(false, true);
+    doBasicTransaction(false, true, true);
   }
 
   public void testBasicCommit() {
-    doBasicCommit(true, false);
+    doBasicTransaction(true, false, true);
   }
   
   public void testBasicCommitUsingJTA() {
-    doBasicCommit(true, true);
+    doBasicTransaction(true, true, true);
   }
   
-  private void doBasicCommit(final boolean prePopulateData, final boolean useJTA) {
+  public void testBasicRollbackUsingJTA() {
+    doBasicTransaction(true, true, false);
+  }
+  
+  private void doBasicTransaction(final boolean prePopulateData, final boolean useJTA, final boolean isCommit) {
     Host host = Host.getHost(0);
     VM server = host.getVM(0);
     VM client = host.getVM(1);
@@ -473,18 +477,28 @@ public class ClientServerTransactionDUnitTest extends RemoteTransactionDUnitTest
             "pr sized should be " + MAX_ENTRIES + " but it is:" + pr.size(),
             MAX_ENTRIES, pr.size());
         com.gemstone.gemfire.test.dunit.LogWriterUtils.getLogWriter().info("committing transaction");
-        if (useJTA) {
-          utx.commit();
+        if (isCommit) {
+          if (useJTA) {
+            utx.commit();
+          } else {
+            getCache().getCacheTransactionManager().commit();
+          }
         } else {
-          getCache().getCacheTransactionManager().commit();
+          if (useJTA) {
+            utx.rollback();
+          } else {
+            getCache().getCacheTransactionManager().rollback();
+          }
         }
-        com.gemstone.gemfire.test.dunit.LogWriterUtils.getLogWriter().info("done committing transaction");
+        com.gemstone.gemfire.test.dunit.LogWriterUtils. getLogWriter().info("done " + (isCommit ? "committing" : "rollingback") + "transaction");
+        int expectedRegionSize = isCommit ? MAX_ENTRIES : 5;
+
         assertEquals(
-            "r sized should be " + MAX_ENTRIES + " but it is:" + r.size(),
-            MAX_ENTRIES, r.size());
+            "r sized should be " + expectedRegionSize + " but it is:" + r.size(),
+            expectedRegionSize, r.size());
         assertEquals(
-            "pr sized should be " + MAX_ENTRIES + " but it is:" + pr.size(),
-            MAX_ENTRIES, pr.size());
+            "pr sized should be " + expectedRegionSize + " but it is:" + pr.size(),
+            expectedRegionSize, pr.size());
 
         return null;
       }
@@ -494,12 +508,13 @@ public class ClientServerTransactionDUnitTest extends RemoteTransactionDUnitTest
       public Object call() throws Exception {
         Region<Integer, String> r = getGemfireCache().getRegion(D_REFERENCE);
         Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
+        int expectedRegionSize = isCommit ? MAX_ENTRIES : 5;
         assertEquals(
-            "r sized should be " + MAX_ENTRIES + " but it is:" + r.size(),
-            MAX_ENTRIES, r.size());
+            "r sized should be " + expectedRegionSize + " but it is:" + r.size(),
+            expectedRegionSize, r.size());
         assertEquals(
-            "pr sized should be " + MAX_ENTRIES + " but it is:" + pr.size(),
-            MAX_ENTRIES, pr.size());
+            "pr sized should be " + expectedRegionSize + " but it is:" + pr.size(),
+            expectedRegionSize, pr.size());
         return null;
       }
     });
@@ -514,6 +529,13 @@ public class ClientServerTransactionDUnitTest extends RemoteTransactionDUnitTest
           Customer cust = new Customer("name"+suffix+i, "address"+suffix+i);
           assertEquals(cust, r.get(custId));
           assertEquals(cust, pr.get(custId));
+          if (isCommit) {
+            assertEquals(cust, r.get(custId));
+            assertEquals(cust, pr.get(custId));
+          } else {
+            assertNotSame(cust, r.get(custId));
+            assertNotSame(cust, pr.get(custId));
+          }
         }
         return null;
       }