You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by es...@apache.org on 2019/08/21 23:48:33 UTC

[geode] branch feature/GEODE-7112 created (now 6ed1c7f)

This is an automated email from the ASF dual-hosted git repository.

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


      at 6ed1c7f  GEODE-7112: add wait until user transaction is timed out.

This branch includes the following new commits:

     new 6ed1c7f  GEODE-7112: add wait until user transaction is timed out.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[geode] 01/01: GEODE-7112: add wait until user transaction is timed out.

Posted by es...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6ed1c7fd90a26efbf95ec3e025c64a0135ec4191
Author: eshu <es...@pivotal.io>
AuthorDate: Wed Aug 21 16:46:25 2019 -0700

    GEODE-7112: add wait until user transaction is timed out.
---
 .../internal/jta/dunit/TxnTimeOutDUnitTest.java    | 25 ++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/jta/dunit/TxnTimeOutDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/jta/dunit/TxnTimeOutDUnitTest.java
index 183349a..7665158 100755
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/jta/dunit/TxnTimeOutDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/jta/dunit/TxnTimeOutDUnitTest.java
@@ -18,6 +18,7 @@ import static org.apache.geode.distributed.ConfigurationProperties.CACHE_XML_FIL
 import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
 import static org.apache.geode.test.dunit.Assert.fail;
 import static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -31,6 +32,7 @@ import java.util.Properties;
 import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.transaction.NotSupportedException;
+import javax.transaction.Status;
 import javax.transaction.SystemException;
 import javax.transaction.UserTransaction;
 
@@ -205,8 +207,11 @@ public class TxnTimeOutDUnitTest extends JUnit4DistributedTestCase {
       Context ctx = cache.getJNDIContext();
       UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
       utx.begin();
+      assertThat(utx.getStatus() == Status.STATUS_ACTIVE);
       utx.setTransactionTimeout(2);
-      Thread.sleep(6000);
+      long start = System.currentTimeMillis();
+      Thread.sleep(2000);
+      waitUntilTransactionTimeout(utx, start);
       try {
         utx.commit();
       } catch (Exception e) {
@@ -223,14 +228,27 @@ public class TxnTimeOutDUnitTest extends JUnit4DistributedTestCase {
     }
   }
 
+  private static void waitUntilTransactionTimeout(UserTransaction utx, long start)
+      throws InterruptedException, SystemException {
+    long waitTime = 30 * 1000; // 30 seconds
+    do {
+      long current = System.currentTimeMillis();
+      assertThat(current - start < waitTime).as("UserTransaction is not timed out for 30 seconds");
+      Thread.sleep(10);
+    } while (utx.getStatus() != Status.STATUS_NO_TRANSACTION);
+  }
+
   public static void runTest2() throws Exception {
     boolean exceptionOccurred = false;
     try {
       Context ctx = cache.getJNDIContext();
       UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
       utx.begin();
+      assertThat(utx.getStatus() == Status.STATUS_ACTIVE);
       utx.setTransactionTimeout(2);
-      Thread.sleep(6000);
+      long start = System.currentTimeMillis();
+      Thread.sleep(2000);
+      waitUntilTransactionTimeout(utx, start);
       try {
         utx.commit();
       } catch (Exception e) {
@@ -251,8 +269,11 @@ public class TxnTimeOutDUnitTest extends JUnit4DistributedTestCase {
     Context ctx = cache.getJNDIContext();
     UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
     utx.begin();
+    assertThat(utx.getStatus() == Status.STATUS_ACTIVE);
     utx.setTransactionTimeout(sleeptime);
+    long start = System.currentTimeMillis();
     Thread.sleep(sleeptime * 2000);
+    waitUntilTransactionTimeout(utx, start);
     try {
       utx.commit();
     } catch (Exception e) {