geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esh...@apache.org
Subject [geode] branch feature/GEODE-3521 updated: Add a test case for testing pause unpause.
Date Tue, 17 Oct 2017 17:22:37 GMT
This is an automated email from the ASF dual-hosted git repository.

eshu11 pushed a commit to branch feature/GEODE-3521
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3521 by this push:
     new 982e30e  Add a test case for testing pause unpause.
982e30e is described below

commit 982e30eafb136c61433af32e41dd3b142e0dda64
Author: eshu <eshu@pivotal.io>
AuthorDate: Tue Oct 17 10:20:09 2017 -0700

    Add a test case for testing pause unpause.
    
      Do not allow a thread to start a new transaction when it paused another transaction.
      Use public supsend resume when same thread need to start a new transaction.
---
 .../apache/geode/internal/cache/TXManagerImpl.java |  7 ++++
 .../test/java/org/apache/geode/TXJUnitTest.java    | 49 +++++++++++++++++-----
 .../cache/execute/MyTransactionFunction.java       |  6 ++-
 3 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java
index 9d35938..06aac77 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java
@@ -316,6 +316,13 @@ public class TXManagerImpl implements CacheTransactionManager, MembershipListene
                 .toLocalizedString(tid));
       }
     }
+    {
+      TXStateProxy curProxy = txContext.get();
+      if (curProxy == PAUSED) {
+        throw new java.lang.IllegalStateException(
+            "Currend thread is in a paused state, it can not start a new transaction");
+      }
+    }
     TXId id = new TXId(this.distributionMgrId, this.uniqId.incrementAndGet());
     TXStateProxyImpl proxy = null;
     if (isDistributed()) {
diff --git a/geode-core/src/test/java/org/apache/geode/TXJUnitTest.java b/geode-core/src/test/java/org/apache/geode/TXJUnitTest.java
index 1c060a7..8f36a9a 100644
--- a/geode-core/src/test/java/org/apache/geode/TXJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/TXJUnitTest.java
@@ -15,6 +15,7 @@
 package org.apache.geode;
 
 import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.*;
 
 import java.util.ArrayList;
@@ -92,6 +93,7 @@ import org.apache.geode.internal.cache.PartitionedRegion;
 import org.apache.geode.internal.cache.TXManagerImpl;
 import org.apache.geode.internal.cache.TXStateProxy;
 import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.internal.util.StopWatch;
 import org.apache.geode.test.junit.categories.IntegrationTest;
 
@@ -4397,10 +4399,10 @@ public class TXJUnitTest {
     // TX load conflict: no-inital state, tx load->update, committed update
     {
       final TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
-      TXStateProxy tx;
+      TransactionId txId = null;
       this.txMgr.begin();
       reg1.create("key1", "txValue");
-      tx = txMgrImpl.pauseTransaction();
+      txId = txMgrImpl.suspend();
       assertTrue(!reg1.containsKey("key1"));
       // new transaction, load(create) + put
       this.txMgr.begin();
@@ -4413,7 +4415,7 @@ public class TXJUnitTest {
       assertTrue(reg1.containsKey("key1"));
       assertEquals("txValue2", reg1.get("key1"));
       assertEquals("txValue2", reg1.getEntry("key1").getValue());
-      txMgrImpl.unpauseTransaction(tx);
+      txMgrImpl.resume(txId);
       assertEquals("txValue", reg1.getEntry("key1").getValue());
       assertEquals("txValue", reg1.get("key1"));
       try {
@@ -4905,7 +4907,7 @@ public class TXJUnitTest {
   }
 
   @Test
-  public void testSuspendResume() {
+  public void testPauseUnpause() {
     TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
     assertTrue(!this.txMgr.exists());
     assertEquals(null, txMgrImpl.pauseTransaction());
@@ -4919,15 +4921,40 @@ public class TXJUnitTest {
     {
       TXStateProxy tx = txMgrImpl.pauseTransaction();
       assertTrue(!this.txMgr.exists());
+      assertThatThrownBy(() -> this.txMgr.begin()).isInstanceOf(IllegalStateException.class);
+      assertTrue(!this.txMgr.exists());
+      txMgrImpl.unpauseTransaction(tx);
+    }
+    assertTrue(this.txMgr.exists());
+    assertEquals(origId, this.txMgr.getTransactionId());
+    this.txMgr.rollback();
+  }
+
+  @Test
+  public void testSuspendResume() {
+    TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
+    assertTrue(!this.txMgr.exists());
+    assertEquals(null, txMgrImpl.pauseTransaction());
+    TXStateProxy txProxy = null;
+    txMgrImpl.unpauseTransaction(txProxy);
+    assertTrue(!this.txMgr.exists());
+
+    this.txMgr.begin();
+    TransactionId origId = this.txMgr.getTransactionId();
+    assertTrue(this.txMgr.exists());
+    {
+      TXStateProxy tx = txMgrImpl.internalSuspend();
+      assertTrue(!this.txMgr.exists());
       this.txMgr.begin();
       try {
-        txMgrImpl.unpauseTransaction(tx);
+        txMgrImpl.internalResume(tx);
         fail("expected IllegalStateException");
       } catch (IllegalStateException expected) {
+        LogService.getLogger().info("expected ", expected);
       }
       this.txMgr.rollback();
       assertTrue(!this.txMgr.exists());
-      txMgrImpl.unpauseTransaction(tx);
+      txMgrImpl.internalResume(tx);
     }
     assertTrue(this.txMgr.exists());
     assertEquals(origId, this.txMgr.getTransactionId());
@@ -5868,7 +5895,7 @@ public class TXJUnitTest {
     // eviction, force TX eviction
     {
       final TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
-      TXStateProxy tx1, tx2;
+      TransactionId txId1, txId2;
       numToPut = lruSize + 4;
       assertEquals(0, lruRegion.entrySet(false).size());
       // Create entries
@@ -5884,7 +5911,7 @@ public class TXJUnitTest {
         lruRegion.put("key" + i, new Long(i));
       }
       assertLRUEntries(lruRegion.entrySet(false), numToPut, "key", LRUENTRY_LONG);
-      tx1 = txMgrImpl.pauseTransaction();
+      txId1 = txMgrImpl.suspend();
 
       this.txMgr.begin();
       assertLRUEntries(lruRegion.entrySet(false), lruSize, "key", LRUENTRY_INTEGER);
@@ -5893,7 +5920,7 @@ public class TXJUnitTest {
         lruRegion.put("key" + i, new Double(i));
       }
       assertLRUEntries(lruRegion.entrySet(false), numToPut, "key", LRUENTRY_DOUBLE);
-      tx2 = txMgrImpl.pauseTransaction();
+      txId2 = txMgrImpl.suspend();
 
       assertLRUEntries(lruRegion.entrySet(false), lruSize, "key", LRUENTRY_INTEGER);
 
@@ -5906,13 +5933,13 @@ public class TXJUnitTest {
       assertNull(lruRegion.get("non-tx key0"));
       assertLRUEntries(lruRegion.entrySet(false), lruSize, "key", LRUENTRY_INTEGER);
 
-      txMgrImpl.unpauseTransaction(tx1);
+      txMgrImpl.resume(txId1);
       assertLRUEntries(lruRegion.entrySet(false), numToPut, "key", LRUENTRY_LONG);
       // Check to make sure no conflict was caused by non-TX put evictions
       // This should remove all references for each committed entry
       this.txMgr.commit();
       assertLRUEntries(lruRegion.entrySet(false), lruSize, "key", LRUENTRY_LONG);
-      txMgrImpl.unpauseTransaction(tx2);
+      txMgrImpl.resume(txId2);
       assertLRUEntries(lruRegion.entrySet(false), numToPut, "key", LRUENTRY_DOUBLE);
       this.txMgr.rollback();
       assertLRUEntries(lruRegion.entrySet(false), lruSize, "key", LRUENTRY_LONG);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/execute/MyTransactionFunction.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/execute/MyTransactionFunction.java
index d11c82b..bd023eb 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/execute/MyTransactionFunction.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/execute/MyTransactionFunction.java
@@ -25,6 +25,7 @@ import org.apache.geode.cache.EntryNotFoundException;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.TransactionDataNotColocatedException;
 import org.apache.geode.cache.TransactionDataRebalancedException;
+import org.apache.geode.cache.TransactionId;
 import org.apache.geode.cache.execute.Execution;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionContext;
@@ -425,7 +426,8 @@ public class MyTransactionFunction implements Function {
     TXEntryState txEntry = txRegion.readEntry(txRegion.getEntryKeys().iterator().next());
     mImp.unpauseTransaction(txState);
     orderPR.put(vOrderId, new Order("foo"));
-    txState = mImp.pauseTransaction();
+    TransactionId txId = null;
+    txId = mImp.suspend();
     // since both puts were on same key, verify that
     // TxRegionState and TXEntryState are same
     LocalRegion lr1 = (LocalRegion) txState.getRegions().iterator().next();
@@ -439,7 +441,7 @@ public class MyTransactionFunction implements Function {
     orderPR.put(vOrderId, new Order("foobar"));
     mImp.commit();
     // now begin the first
-    mImp.unpauseTransaction(txState);
+    mImp.resume(txId);
     boolean caughtException = false;
     try {
       mImp.commit();

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message