Repository: tomee
Updated Branches:
  refs/heads/master 456a16d56 -> 186404f67


requires new test


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/186404f6
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/186404f6
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/186404f6

Branch: refs/heads/master
Commit: 186404f67de8b1c1758dc15f7afc9656346c5057
Parents: 456a16d
Author: Romain Manni-Bucau <[email protected]>
Authored: Thu Nov 19 07:57:29 2015 -0800
Committer: Romain Manni-Bucau <[email protected]>
Committed: Thu Nov 19 07:57:29 2015 -0800

----------------------------------------------------------------------
 .../cdi/transactional/TransactionalTest.java    | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/186404f6/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
index 9bce175..611aaa1 100644
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/cdi/transactional/TransactionalTest.java
@@ -31,16 +31,20 @@ import javax.transaction.RollbackException;
 import javax.transaction.Status;
 import javax.transaction.Synchronization;
 import javax.transaction.SystemException;
+import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import javax.transaction.Transactional;
 import javax.transaction.TransactionalException;
 import javax.transaction.UserTransaction;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 
 import static javax.transaction.Transactional.TxType.MANDATORY;
 import static javax.transaction.Transactional.TxType.NOT_SUPPORTED;
 import static javax.transaction.Transactional.TxType.REQUIRED;
+import static javax.transaction.Transactional.TxType.REQUIRES_NEW;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.fail;
 
 @RunWith(ApplicationComposer.class)
@@ -263,11 +267,31 @@ public class TransactionalTest {
         }
     }
 
+    @Test
+    public void requiresNew() {
+        final AtomicReference<Transaction> tx2 = new AtomicReference<>();
+        final Transaction tx1 = bean.defaultTx(new Runnable() {
+            @Override
+            public void run() {
+                tx2.set(bean.newTx(new Runnable() {
+                    @Override
+                    public void run() {
+                      // no-op
+                    }
+                }));
+            }
+        });
+        assertNotSame(tx1, tx2.get());
+    }
+
     @Transactional(value = REQUIRED, rollbackOn = AnCheckedException.class)
     public static class TxBean {
         @Resource
         private UserTransaction ut;
 
+        @Resource
+        private TransactionManager txMgr;
+
         @Transactional(value = REQUIRED)
         public void required() {
             assertHasTx();
@@ -324,6 +348,16 @@ public class TransactionalTest {
             throw new AnCheckedException();
         }
 
+        @Transactional
+        public Transaction defaultTx(final Runnable runnable) {
+            runnable.run();
+            try {
+                return txMgr.getTransaction();
+            } catch (SystemException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
         @Transactional(REQUIRED)
         public void checked(Runnable runnable) throws AnCheckedException {
             runnable.run();
@@ -336,6 +370,16 @@ public class TransactionalTest {
             throw new AnException();
         }
 
+        @Transactional(REQUIRES_NEW)
+        public Transaction newTx(final Runnable runnable) {
+            runnable.run();
+            try {
+                return txMgr.getTransaction();
+            } catch (SystemException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
         @Transactional(value = REQUIRED, dontRollbackOn = 
AnotherException.class)
         public void anotherException(final AtomicInteger status) {
             try {

Reply via email to