incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r963787 - in /incubator/aries/trunk/transaction: transaction-blueprint/src/main/java/org/apache/aries/transaction/ transaction-itests/src/test/java/org/apache/aries/transaction/itests/
Date Tue, 13 Jul 2010 16:33:31 GMT
Author: linsun
Date: Tue Jul 13 16:33:30 2010
New Revision: 963787

URL: http://svn.apache.org/viewvc?rev=963787&view=rev
Log:
ARIES-354 Update tranaction strategy to transaction attribute in blueprint transaction project

Added:
    incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
  (with props)
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
  (with props)
Removed:
    incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionStrategy.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranStrategyTest.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranStrategyTest.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranStrategyTest.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranStrategyTest.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranStrategyTest.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranStrategyTest.java
    incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranStrategyTest.java

Added: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
(added)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.transaction;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+public enum TransactionAttribute {
+    MANDATORY
+    {
+      public TransactionToken begin(TransactionManager man) throws SystemException
+      {
+        if (man.getStatus() == Status.STATUS_NO_TRANSACTION) {
+          throw new IllegalStateException("No transaction on the thread");
+        }
+
+        return new TransactionToken(man.getTransaction(), null, MANDATORY);
+      }
+    },
+    NEVER
+    {
+      public TransactionToken begin(TransactionManager man) throws SystemException
+      {
+        if (man.getStatus() == Status.STATUS_ACTIVE) {
+          throw new IllegalStateException("Transaction on the thread");
+        }
+
+        return new TransactionToken(null, null, NEVER);
+      }
+    },
+    NOTSUPPORTED
+    {
+      public TransactionToken begin(TransactionManager man) throws SystemException
+      {
+        if (man.getStatus() == Status.STATUS_ACTIVE) {
+          return new TransactionToken(null, man.suspend(), this);
+        }
+
+        return new TransactionToken(null, null, NOTSUPPORTED);
+      }
+
+      public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
+          InvalidTransactionException, IllegalStateException
+      {
+        Transaction tran = tranToken.getSuspendedTransaction();
+        if (tran != null) {
+          man.resume(tran);
+        }
+      }
+    },
+    REQUIRED
+    {
+      public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException
+      {
+        if (man.getStatus() == Status.STATUS_NO_TRANSACTION) {
+          man.begin();
+          return new TransactionToken(man.getTransaction(), null, REQUIRED, true);
+        }
+
+        return new TransactionToken(man.getTransaction(), null, REQUIRED);
+      }
+
+      public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
+          InvalidTransactionException, IllegalStateException, SecurityException, RollbackException,
+          HeuristicMixedException, HeuristicRollbackException
+      {
+        if (tranToken.isCompletionAllowed()) {
+          if (man.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
+            man.rollback();
+          } else {
+            man.commit();
+          }
+        }
+      }
+    },
+    REQUIRESNEW
+    {
+      public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException,
+          InvalidTransactionException, IllegalStateException
+      {
+        TransactionToken tranToken;
+        if (man.getStatus() == Status.STATUS_ACTIVE) {
+          tranToken = new TransactionToken(null, man.suspend(), REQUIRESNEW);
+        } else {
+          tranToken = new TransactionToken(null, null, REQUIRESNEW);
+        }
+
+        try {
+          man.begin();
+        } catch (SystemException e) {
+          man.resume(tranToken.getSuspendedTransaction());
+          throw e;
+        } catch (NotSupportedException e) {
+          man.resume(tranToken.getSuspendedTransaction());
+          throw e;
+        }
+        
+        tranToken.setActiveTransaction(man.getTransaction());
+        tranToken.setCompletionAllowed(true);
+        
+        return tranToken;
+      }
+
+      public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
+          InvalidTransactionException, IllegalStateException, SecurityException, RollbackException,
+          HeuristicMixedException, HeuristicRollbackException
+      {
+        if (tranToken.isCompletionAllowed()) {
+          if (man.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
+            man.rollback();
+          } else {
+            man.commit();
+          }
+        }
+
+        Transaction tran = tranToken.getSuspendedTransaction();
+        if (tran != null) {
+          man.resume(tran);
+        }
+      }
+    },
+    SUPPORTS
+    {
+      public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException,
+          InvalidTransactionException, IllegalStateException
+      {
+          if (man.getStatus() == Status.STATUS_ACTIVE) {
+              return new TransactionToken(man.getTransaction(), null, SUPPORTS);
+          }
+
+          return new TransactionToken(null, null, SUPPORTS);
+      }
+    };
+
+    public static TransactionAttribute fromValue(String value)
+    {
+      return valueOf(value.toUpperCase());
+    }
+
+    public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException,
+        InvalidTransactionException, IllegalStateException
+    {
+      return null;
+    }
+
+    public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
+        InvalidTransactionException, IllegalStateException, SecurityException, RollbackException,
+        HeuristicMixedException, HeuristicRollbackException
+    {
+
+    }
+}

Propchange: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionAttribute.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,39 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.fail;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class InvalidTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testInvalid() throws Exception {
+      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Invalid)", DEFAULT_TIMEOUT);
+      
+      //Test without client transaction - an exception is thrown because the bean is not
+      //configured correctly, i.e. multiple transaction elements match to the same method
+      //name.
+      try {
+          bean.insertRow("testWithoutClientTran", 1);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,93 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.SQLException;
+
+import javax.transaction.RollbackException;
+import javax.transaction.UserTransaction;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class MandatoryTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testMandatory() throws Exception {
+      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Mandatory)", DEFAULT_TIMEOUT);
+      UserTransaction tran = getOsgiService(UserTransaction.class);
+      
+      //Test with client transaction - the user transaction is used to insert a row
+      int initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTran", 1);
+      tran.commit();
+      
+      int finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+  
+      //Test with client transaction and application exception - the user transaction is
not rolled back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTranAndWithAppException", 1);
+      
+      try {
+          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy
exception"));
+      } catch (SQLException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 2);
+      
+      //Test with client transaction and runtime exception - the user transaction is rolled
back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+      
+      try {
+          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy
exception"));
+      } catch (RuntimeException e) {
+          e.printStackTrace();
+      }
+      
+      try {
+          tran.commit();
+          fail("RollbackException not thrown");
+      } catch (RollbackException e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+      
+      //Test without client transaction - an exception is thrown because a transaction is
mandatory
+      try {
+          bean.insertRow("testWithoutClientTran", 1);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,64 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.transaction.UserTransaction;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class NeverTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testNever() throws Exception {
+      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Never)", DEFAULT_TIMEOUT);
+      UserTransaction tran = getOsgiService(UserTransaction.class);
+      
+      //Test with client transaction - an exception is thrown because transactions are not
allowed
+      int initialRows = bean.countRows();
+      
+      tran.begin();
+      
+      try {
+          bean.insertRow("testWithClientTran", 1);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      int finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+      
+      //Test without client transaction - the insert fails because the bean delegates to
another
+      //bean with a transaction strategy of Mandatory, and no transaction is available
+      initialRows = bean.countRows();
+
+      try {
+          bean.insertRow("testWithoutClientTran", 1, true);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,105 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.SQLException;
+
+import javax.transaction.UserTransaction;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class NotSupportedTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testNotSupported() throws Exception {
+      TestBean nsBean = getOsgiService(TestBean.class, "(tranAttribute=NotSupported)", DEFAULT_TIMEOUT);
+      TestBean rBean = getOsgiService(TestBean.class, "(tranAttribute=Required)", DEFAULT_TIMEOUT);
+      UserTransaction tran = getOsgiService(UserTransaction.class);
+      
+      //Test with client transaction - the insert fails because the bean delegates to another
+      //bean with a transaction strategy of Mandatory, and no transaction is available, i.e.
+      //the user transaction is not propagated, and there is no container transaction.
+      int initialRows = nsBean.countRows();
+      
+      tran.begin();
+      
+      try {
+          nsBean.insertRow("testWithClientTran", 1, true);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      int finalRows = nsBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+      
+      //Test with client transaction and with application exception - the user transaction
is not
+      //marked for rollback and can still be committed
+      initialRows = nsBean.countRows();
+      
+      tran.begin();
+      rBean.insertRow("testWithClientTranAndWithAppException", 1);
+      
+      try {
+          nsBean.throwApplicationException();
+      } catch (SQLException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = nsBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test with client transaction and with runtime exception - the user transaction is
not
+      //marked for rollback and can still be committed
+      initialRows = nsBean.countRows();
+      
+      tran.begin();
+      rBean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+      
+      try {
+          nsBean.throwRuntimeException();
+      } catch (RuntimeException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = nsBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test without client transaction - the insert fails because the bean delegates to
another
+      //bean with a transaction strategy of Mandatory, and no transaction is available
+      initialRows = nsBean.countRows();
+      
+      try {
+          nsBean.insertRow("testWithoutClientTran", 1, true);
+          fail("IllegalStateException not thrown");
+      } catch (IllegalStateException e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = nsBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,117 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.SQLException;
+
+import javax.transaction.RollbackException;
+import javax.transaction.UserTransaction;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class RequiredTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testRequired() throws Exception {
+      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Required)", DEFAULT_TIMEOUT);
+      UserTransaction tran = getOsgiService(UserTransaction.class);
+      
+      //Test with client transaction - the user transaction is used to insert a row
+      int initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTran", 1);
+      tran.commit();
+      
+      int finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test with client transaction and application exception - the user transaction is
not rolled back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTranAndWithAppException", 1);
+      
+      try {
+          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException());
+      } catch (SQLException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 2);
+       
+      //Test with client transaction and runtime exception - the user transaction is rolled
back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+      
+      try {
+          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException());
+      } catch (RuntimeException e) {
+          e.printStackTrace();
+      }
+      
+      try {
+          tran.commit();
+          fail("RollbackException not thrown");
+      } catch (RollbackException e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+      
+      //Test without client exception - a container transaction is used to insert the row
+      initialRows = bean.countRows();
+      
+      bean.insertRow("testWithoutClientTran", 1);
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test without client exception and with application exception - the container transaction
is not rolled back
+      initialRows = bean.countRows();
+      
+      try {
+          bean.insertRow("testWithoutClientTranAndWithAppException", 1, new SQLException("Dummy
exception"));
+      } catch (Exception e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test without client transaction and with runtime exception - the container transaction
is rolled back
+      initialRows = bean.countRows();
+      
+      try {
+          bean.insertRow("testWithoutClientTranAndWithRuntimeException", 1, new RuntimeException("Dummy
exception"));
+      } catch (Exception e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,113 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.assertTrue;
+
+import java.sql.SQLException;
+
+import javax.transaction.UserTransaction;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class RequiresNewTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testRequiresNew() throws Exception {
+      TestBean rnBean = getOsgiService(TestBean.class, "(tranAttribute=RequiresNew)", DEFAULT_TIMEOUT);
+      TestBean rBean = getOsgiService(TestBean.class, "(tranAttribute=Required)", DEFAULT_TIMEOUT);
+      UserTransaction tran = getOsgiService(UserTransaction.class);
+      
+      //Test with client transaction - a container transaction is used to insert the row
+      int initialRows = rnBean.countRows();
+      
+      tran.begin();
+      rnBean.insertRow("testWithClientTran", 1);
+      tran.rollback();
+      
+      int finalRows = rnBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test with client transaction and application exception - the container transaction
is committed,
+      //the user transaction is not affected.
+      initialRows = rnBean.countRows();
+      
+      tran.begin();
+      rBean.insertRow("testWithClientTranAndWithAppException", 1);
+      
+      try {
+          rnBean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy
exception"));
+      } catch (SQLException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = rnBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 2);
+      
+      //Test with client transaction and runtime exception - the container transaction is
rolled back,
+      //the user transaction is not affected
+      initialRows = rnBean.countRows();
+      
+      tran.begin();
+      rBean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+      
+      try {
+          rnBean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy
exception"));
+      } catch (RuntimeException e) {
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = rnBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test without client transaction - a container transaction is used to insert the row
+      initialRows = rnBean.countRows();
+      
+      rnBean.insertRow("testWithoutClientTran", 1);
+      
+      finalRows = rnBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test without client transaction and with application exception - the container transaction
is committed
+      initialRows = rnBean.countRows();
+      
+      try {
+          rnBean.insertRow("testWithoutClientTranAndWithAppException", 1, new SQLException("Dummy
exception"));
+      } catch (Exception e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = rnBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test without client transaction and with runtime exception - the container transaction
is rolled back
+      initialRows = rnBean.countRows();
+      
+      try {
+          rnBean.insertRow("testWithoutClientTranAndWithRuntimeException", 1, new RuntimeException("Dummy
exception"));
+      } catch (Exception e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = rnBean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java?rev=963787&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
(added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
Tue Jul 13 16:33:30 2010
@@ -0,0 +1,102 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.transaction.itests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.SQLException;
+
+import javax.transaction.RollbackException;
+import javax.transaction.UserTransaction;
+
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Test;
+
+public class SupportsTranAttributeTest extends AbstractIntegrationTest {
+  
+  @Test
+  public void testSupports() throws Exception {
+      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Supports)", DEFAULT_TIMEOUT);
+      UserTransaction tran = getOsgiService(UserTransaction.class);
+      
+      //Test with client transaction - the insert succeeds because the bean delegates to
+      //another bean with a transaction strategy of Mandatory, and the user transaction
+      //is delegated
+      int initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTran", 1, true);
+      tran.commit();
+      
+      int finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 1);
+      
+      //Test with client transaction and application exception - the user transaction is
not rolled back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTranAndWithAppException", 1);
+      
+      try {
+          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException());
+      } catch (SQLException e) {
+          // TODO Auto-generated catch block
+          e.printStackTrace();
+      }
+      
+      tran.commit();
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 2);
+      
+      //Test with client transaction and runtime exception - the user transaction is rolled
back
+      initialRows = bean.countRows();
+      
+      tran.begin();
+      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+      
+      try {
+          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException());
+      } catch (RuntimeException e) {
+          e.printStackTrace();
+      }
+      
+      try {
+          tran.commit();
+          fail("RollbackException not thrown");
+      } catch (RollbackException e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+      
+      //Test without client transaction - the insert fails because the bean delegates to
+      //another bean with a transaction strategy of Mandatory, and no transaction is available
+      initialRows = bean.countRows();
+      
+      try {
+          bean.insertRow("testWithoutClientTran", 1, true);
+          fail("Exception not thrown");
+      } catch (Exception e) {
+          e.printStackTrace();
+      }
+      
+      finalRows = bean.countRows();
+      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows
- initialRows == 0);
+  }
+}

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message