You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ma...@apache.org on 2010/03/04 14:16:21 UTC
svn commit: r918977 [1/2] - in /incubator/aries/trunk/transaction: ./
transaction-blueprint/
transaction-blueprint/src/main/java/org/apache/aries/transaction/
transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/
transaction-bluepri...
Author: mahrwald
Date: Thu Mar 4 13:16:19 2010
New Revision: 918977
URL: http://svn.apache.org/viewvc?rev=918977&view=rev
Log:
ARIES-153: Commit patch
Added:
incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
incubator/aries/trunk/transaction/transaction-itests/
incubator/aries/trunk/transaction/transaction-itests/pom.xml
incubator/aries/trunk/transaction/transaction-itests/src/
incubator/aries/trunk/transaction/transaction-itests/src/test/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/
incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.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
incubator/aries/trunk/transaction/transaction-testbundle/
incubator/aries/trunk/transaction/transaction-testbundle/pom.xml
incubator/aries/trunk/transaction/transaction-testbundle/src/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/TestBean.java
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/TestBeanImpl.java
incubator/aries/trunk/transaction/transaction-testbundle/src/main/resources/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/
incubator/aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
incubator/aries/trunk/transaction/transaction-testds/
incubator/aries/trunk/transaction/transaction-testds/pom.xml
incubator/aries/trunk/transaction/transaction-testds/src/
incubator/aries/trunk/transaction/transaction-testds/src/main/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/apache/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/apache/aries/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/apache/aries/transaction/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/apache/aries/transaction/jdbc/
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/apache/aries/transaction/jdbc/ConnectionWrapper.java
incubator/aries/trunk/transaction/transaction-testds/src/main/java/org/apache/aries/transaction/jdbc/XADatasourceEnlistingWrapper.java
incubator/aries/trunk/transaction/transaction-testds/src/main/resources/
incubator/aries/trunk/transaction/transaction-testds/src/main/resources/OSGI-INF/
incubator/aries/trunk/transaction/transaction-testds/src/main/resources/OSGI-INF/blueprint/
incubator/aries/trunk/transaction/transaction-testds/src/main/resources/OSGI-INF/blueprint/dataSource.xml
Modified:
incubator/aries/trunk/transaction/pom.xml
incubator/aries/trunk/transaction/transaction-blueprint/pom.xml
incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionStrategy.java
incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java
incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java
incubator/aries/trunk/transaction/transaction-manager/pom.xml
Modified: incubator/aries/trunk/transaction/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/pom.xml?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/pom.xml (original)
+++ incubator/aries/trunk/transaction/pom.xml Thu Mar 4 13:16:19 2010
@@ -55,6 +55,18 @@
<artifactId>org.apache.aries.transaction.manager</artifactId>
<version>0.1-incubating-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.testds</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.testbundle</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
<!-- external dependencies -->
<dependency>
@@ -88,12 +100,26 @@
<artifactId>spring-tx</artifactId>
<version>2.5.6</version>
</dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.5.3.0_1</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>transaction-manager</module>
<module>transaction-blueprint</module>
+ <module>transaction-itests</module>
+ <module>transaction-testbundle</module>
+ <module>transaction-testds</module>
</modules>
</project>
Modified: incubator/aries/trunk/transaction/transaction-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/pom.xml?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/pom.xml (original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/pom.xml Thu Mar 4 13:16:19 2010
@@ -82,6 +82,7 @@
<Import-Package>
org.osgi.framework;version="1.5",
org.osgi.service.cm;version="[1.2.0,2.0.0)",
+ javax.transaction*;version="[0.0.0,1.1.0)",
*
</Import-Package>
<Export-Package>
Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionStrategy.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionStrategy.java?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionStrategy.java (original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionStrategy.java Thu Mar 4 13:16:19 2010
@@ -31,40 +31,41 @@
public enum TransactionStrategy {
MANDATORY
{
- public Transaction begin(TransactionManager man) throws SystemException
+ public TransactionToken begin(TransactionManager man) throws SystemException
{
if (man.getStatus() == Status.STATUS_NO_TRANSACTION) {
- throw new IllegalStateException("No tran on thread");
+ throw new IllegalStateException("No transaction on the thread");
}
- return null;
+ return new TransactionToken(man.getTransaction(), null, MANDATORY);
}
},
NEVER
{
- public Transaction begin(TransactionManager man) throws SystemException
+ public TransactionToken begin(TransactionManager man) throws SystemException
{
if (man.getStatus() == Status.STATUS_ACTIVE) {
- throw new IllegalStateException("Tran on thread");
+ throw new IllegalStateException("Transaction on the thread");
}
- return null;
+ return new TransactionToken(null, null, NEVER);
}
},
- NOT_SUPPORTED
+ NOTSUPPORTED
{
- public Transaction begin(TransactionManager man) throws SystemException
+ public TransactionToken begin(TransactionManager man) throws SystemException
{
if (man.getStatus() == Status.STATUS_ACTIVE) {
- return man.suspend();
+ return new TransactionToken(null, man.suspend(), this);
}
- return null;
+ return new TransactionToken(null, null, NOTSUPPORTED);
}
- public void finish(TransactionManager man, Transaction tran) throws SystemException,
+ public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
InvalidTransactionException, IllegalStateException
{
+ Transaction tran = tranToken.getSuspendedTransaction();
if (tran != null) {
man.resume(tran);
}
@@ -72,21 +73,21 @@
},
REQUIRED
{
- public Transaction begin(TransactionManager man) throws SystemException, NotSupportedException
+ public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException
{
if (man.getStatus() == Status.STATUS_NO_TRANSACTION) {
man.begin();
- return man.getTransaction();
+ return new TransactionToken(man.getTransaction(), null, REQUIRED, true);
}
- return null;
+ return new TransactionToken(man.getTransaction(), null, REQUIRED);
}
- public void finish(TransactionManager man, Transaction tran) throws SystemException,
+ public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
InvalidTransactionException, IllegalStateException, SecurityException, RollbackException,
HeuristicMixedException, HeuristicRollbackException
{
- if (tran != null) {
+ if (tranToken.isCompletionAllowed()) {
if (man.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
man.rollback();
} else {
@@ -95,59 +96,77 @@
}
}
},
- REQUIRES_NEW
+ REQUIRESNEW
{
- public Transaction begin(TransactionManager man) throws SystemException, NotSupportedException,
+ public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException,
InvalidTransactionException, IllegalStateException
{
- Transaction result;
+ TransactionToken tranToken;
if (man.getStatus() == Status.STATUS_ACTIVE) {
- result = man.suspend();
+ tranToken = new TransactionToken(null, man.suspend(), REQUIRESNEW);
} else {
- result = null;
+ tranToken = new TransactionToken(null, null, REQUIRESNEW);
}
try {
man.begin();
} catch (SystemException e) {
- man.resume(result);
+ man.resume(tranToken.getSuspendedTransaction());
throw e;
} catch (NotSupportedException e) {
- man.resume(result);
+ man.resume(tranToken.getSuspendedTransaction());
throw e;
}
- return result;
+
+ tranToken.setActiveTransaction(man.getTransaction());
+ tranToken.setCompletionAllowed(true);
+
+ return tranToken;
}
- public void finish(TransactionManager man, Transaction tran) throws SystemException,
+ public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
InvalidTransactionException, IllegalStateException, SecurityException, RollbackException,
HeuristicMixedException, HeuristicRollbackException
{
- if (man.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
- man.rollback();
- } else {
- man.commit();
+ 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;
+ 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 TransactionStrategy fromValue(String value)
{
return valueOf(value.toUpperCase());
}
- public Transaction begin(TransactionManager man) throws SystemException, NotSupportedException,
+ public TransactionToken begin(TransactionManager man) throws SystemException, NotSupportedException,
InvalidTransactionException, IllegalStateException
{
return null;
}
- public void finish(TransactionManager man, Transaction tran) throws SystemException,
+ public void finish(TransactionManager man, TransactionToken tranToken) throws SystemException,
InvalidTransactionException, IllegalStateException, SecurityException, RollbackException,
HeuristicMixedException, HeuristicRollbackException
{
Added: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java (added)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java Thu Mar 4 13:16:19 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.Transaction;
+
+class TransactionToken
+{
+ private Transaction activeTransaction;
+ private Transaction suspendedTransaction;
+ private TransactionStrategy transactionStrategy;
+ private boolean isCompletionAllowed;
+
+ public TransactionToken(Transaction activeTransaction, Transaction suspendedTransaction,
+ TransactionStrategy transactionStrategy)
+ {
+ this(activeTransaction, suspendedTransaction, transactionStrategy, false);
+ }
+
+ TransactionToken(Transaction activeTransaction, Transaction suspendedTransaction,
+ TransactionStrategy transactionStrategy, boolean isCompletionAllowed)
+ {
+ this.activeTransaction = activeTransaction;
+ this.suspendedTransaction = suspendedTransaction;
+ this.transactionStrategy = transactionStrategy;
+ this.isCompletionAllowed = isCompletionAllowed;
+ }
+
+ public Transaction getActiveTransaction() {
+ return activeTransaction;
+ }
+
+ public void setActiveTransaction(Transaction activeTransaction) {
+ this.activeTransaction = activeTransaction;
+ }
+
+ public Transaction getSuspendedTransaction() {
+ return suspendedTransaction;
+ }
+
+ public void setSuspendedTransaction(Transaction suspendedTransaction) {
+ this.suspendedTransaction = suspendedTransaction;
+ }
+
+ public TransactionStrategy getTransactionStrategy() {
+ return transactionStrategy;
+ }
+
+ public void setTransactionStrategy(TransactionStrategy transactionStrategy) {
+ this.transactionStrategy = transactionStrategy;
+ }
+
+ public boolean isCompletionAllowed() {
+ return isCompletionAllowed;
+ }
+
+ public void setCompletionAllowed(boolean isCompletionAllowed) {
+ this.isCompletionAllowed = isCompletionAllowed;
+ }
+}
\ No newline at end of file
Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java (original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java Thu Mar 4 13:16:19 2010
@@ -18,6 +18,10 @@
*/
package org.apache.aries.transaction;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
@@ -30,40 +34,56 @@
private static class TranData
{
- private final String strategy;
- private final Pattern[] methodNames;
+ private final Map<Pattern, String> map;
- public TranData(String s, String m)
- {
- strategy = s;
- String[] names = m.split("[, \t]");
- methodNames = new Pattern[names.length];
-
- for (int i = 0; i < names.length; i++) {
- methodNames[i] = Pattern.compile(names[i].replaceAll("\\*", ".*"));
- }
+ public TranData() {
+ map = new LinkedHashMap<Pattern, String>();
+ }
+
+ public void add(Pattern pattern, String strategy) {
+ map.put(pattern, strategy);
}
- public boolean matches(String name)
+ public String getStrategy(String name)
{
- for (Pattern p : methodNames) {
+ for (Pattern p : map.keySet()) {
if (p.matcher(name).matches()) {
- return true;
+ return map.get(p);
}
}
- return false;
+ return null;
}
}
-
- // TODO cope with having multiple tran data per component.
+
private final Map<ComponentMetadata, TranData> data = new ConcurrentHashMap<ComponentMetadata, TranData>();
private TransactionManager tm;
- public void setComponentTransactionData(ComponentMetadata component, String value, String method)
+ public synchronized void setComponentTransactionData(ComponentMetadata component, String value, String method)
{
- TranData td = new TranData(value, method);
+ TranData td = data.get(component);
+
+ if (td == null) {
+ td = new TranData();
+ data.put(component, td);
+ }
+
+ String[] names = method.split("[, \t]");
- data.put(component, td);
+ for (int i = 0; i < names.length; i++) {
+ Pattern pattern = Pattern.compile(names[i].replaceAll("\\*", ".*"));
+ td.add(pattern, value);
+ }
+ }
+
+ public String getComponentMethodTxStrategy(ComponentMetadata component, String methodName)
+ {
+ TranData td = data.get(component);
+ String result = null;
+
+ if (td != null)
+ result = td.getStrategy(methodName);
+
+ return result;
}
public TransactionManager getTransactionManager()
@@ -75,19 +95,4 @@
{
tm = manager;
}
-
-
- public String getComponentMethodTxStrategy(ComponentMetadata component, String methodName)
- {
- String result = null;
- TranData td = data.get(component);
-
- if (td != null) {
- if (td.matches(methodName)) {
- result = td.strategy;
- }
- }
-
- return result;
- }
}
Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java (original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java Thu Mar 4 13:16:19 2010
@@ -29,10 +29,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class TxInterceptorImpl implements Interceptor {
- private static final Logger _logger =
- LoggerFactory.getLogger("org.apache.aries.transaction");
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(TxInterceptorImpl.class);
private TransactionManager tm;
private TxComponentMetaDataHelper metaDataHelper;
@@ -50,12 +49,28 @@
{
final TransactionToken token = (TransactionToken)preCallToken;
try {
- token.ts.finish(tm, token.t);
+ Transaction tran = token.getActiveTransaction();
+ if (tran != null) {
+ Class<?> exceptionClass = ex.getClass();
+ boolean isAppException = false;
+
+ for (Class<?> cls : m.getExceptionTypes()) {
+ isAppException = cls.isAssignableFrom(exceptionClass);
+
+ if (isAppException)
+ break;
+ }
+
+ if (!isAppException)
+ tran.setRollbackOnly();
+ }
+
+ token.getTransactionStrategy().finish(tm, token);
}
catch (Exception e)
{
// we do not throw the exception since there already is one, but we need to log it
- _logger.error("An exception has occured.", e);
+ LOGGER.error("An exception has occured.", e);
}
} else {
// TODO: what now?
@@ -69,11 +84,11 @@
{
final TransactionToken token = (TransactionToken)preCallToken;
try {
- token.ts.finish(tm, token.t);
+ token.getTransactionStrategy().finish(tm, token);
}
catch (Exception e)
{
- _logger.error("An exception has occured.", e);
+ LOGGER.error("An exception has occured.", e);
throw new TransactionRollbackException(e);
}
}
@@ -93,17 +108,16 @@
final String strategy = metaDataHelper.getComponentMethodTxStrategy(cm, methodName);
- Transaction t;
TransactionStrategy txStrategy = TransactionStrategy.REQUIRED;
if (strategy != null)
{
txStrategy = TransactionStrategy.fromValue(strategy);
}
+
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("Method: " + m + ", has transaction strategy: " + txStrategy);
- t = txStrategy.begin(tm);
-
- // now construct return object from txStrategy and t
- return new TransactionToken(t, txStrategy);
+ return txStrategy.begin(tm);
}
public final void setTransactionManager(TransactionManager manager)
@@ -114,16 +128,5 @@
public final void setTxMetaDataHelper(TxComponentMetaDataHelper transactionEnhancer)
{
this.metaDataHelper = transactionEnhancer;
- }
-
- private static class TransactionToken
- {
- private Transaction t;
- private TransactionStrategy ts;
- private TransactionToken(Transaction t, TransactionStrategy ts)
- {
- this.t = t;
- this.ts = ts;
- }
}
}
Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java (original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/TxElementHandler.java Thu Mar 4 13:16:19 2010
@@ -34,33 +34,33 @@
import org.w3c.dom.Node;
public class TxElementHandler implements NamespaceHandler {
- private static final Logger _logger =
- LoggerFactory.getLogger("org.apache.aries.transaction.parsing");
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(TxElementHandler.class);
private TxComponentMetaDataHelper metaDataHelper;
private Interceptor interceptor = null;
private void parseElement(Element elt, ComponentMetadata cm, ParserContext pc)
{
- if (_logger.isDebugEnabled())
- _logger.debug("parser asked to parse .. " + elt);
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("parser asked to parse .. " + elt);
if ("transaction".equals(elt.getLocalName())) {
- if (_logger.isDebugEnabled())
- _logger.debug("parser adding interceptor for " + elt);
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("parser adding interceptor for " + elt);
ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry();
cdr.registerInterceptorWithComponent(cm, interceptor);
- if (_logger.isDebugEnabled())
- _logger.debug("parser setting comp trans data for " + elt.getAttribute("value") + " "
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("parser setting comp trans data for " + elt.getAttribute("value") + " "
+ elt.getAttribute("method"));
metaDataHelper.setComponentTransactionData(cm, elt.getAttribute("value"), elt
.getAttribute("method"));
}
- if (_logger.isDebugEnabled())
- _logger.debug("parser done with " + elt);
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("parser done with " + elt);
}
public ComponentMetadata decorate(Node node, ComponentMetadata cm, ParserContext pc)
@@ -92,8 +92,8 @@
public final void setTransactionInterceptor(Interceptor itx)
{
- if (_logger.isDebugEnabled())
- _logger.debug("parser having interceptor set " + itx);
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("parser having interceptor set " + itx);
this.interceptor = itx;
}
Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java (original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/TranStrategyTest.java Thu Mar 4 13:16:19 2010
@@ -60,7 +60,7 @@
try {
assertNotNull("TransactionStrategy.MANDATORY.begin(tm) returned null when manager " +
- "status is STATUS_NO_TRANSACTION", TransactionStrategy.MANDATORY.begin(tm));
+ "status is STATUS_NO_TRANSACTION", TransactionStrategy.MANDATORY.begin(tm).getActiveTransaction());
} catch (IllegalStateException ise) {
// Expected to be in here
} catch (Exception e) {
@@ -74,11 +74,13 @@
Status.STATUS_ROLLING_BACK, Status.STATUS_UNKNOWN };
for (int i = 0; i < invalids.length ; i++) {
- skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
try {
- assertNull("TransactionStrategy.MANDATORY.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.MANDATORY.begin(tm));
+ Transaction tran = TransactionStrategy.MANDATORY.begin(tm).getActiveTransaction();
+ assertNull("TransactionStrategy.MANDATORY.begin() did not return null when manager status value is " + invalids[i], tran);
} catch (Exception ise) {
- fail("TransactionStrategy.MANDATORY.begin() threw Exception when manager status value is " + invalids[i]);
+ fail("TransactionStrategy.MANDATORY.begin() threw Exception when manager status value is " + invalids[i]);
}
}
}
@@ -87,7 +89,8 @@
public void testMandatoryFinish()
{
try {
- TransactionStrategy.MANDATORY.finish(tm, t);
+ TransactionToken tranToken = new TransactionToken(t, null, TransactionStrategy.MANDATORY);
+ TransactionStrategy.MANDATORY.finish(tm, tranToken);
} catch (Exception e) {
fail("TransactionStrategy.MANDATORY.finish() threw an unexpected exception");
}
@@ -117,8 +120,9 @@
for (int i = 0; i < invalids.length ; i++) {
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
try {
- assertNull("TransactionStrategy.NEVER.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.NEVER.begin(tm));
+ assertNull("TransactionStrategy.NEVER.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.NEVER.begin(tm).getActiveTransaction());
} catch (Exception ise) {
fail("TransactionStrategy.NEVER.begin() threw unexpected exception when manager status value is " + invalids[i]);
}
@@ -130,7 +134,8 @@
public void testNeverFinish()
{
try {
- TransactionStrategy.NEVER.finish(tm, t);
+ TransactionToken tranToken = new TransactionToken(null, null, TransactionStrategy.NEVER);
+ TransactionStrategy.NEVER.finish(tm, tranToken);
} catch (Exception e) {
fail("TransactionStrategy.NEVER.finish() threw an unexpected exception");
}
@@ -143,7 +148,7 @@
// and _NOT_ begin a new one
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_ACTIVE);
- TransactionStrategy.NOT_SUPPORTED.begin(tm);
+ TransactionStrategy.NOTSUPPORTED.begin(tm);
skel.assertCalled(new MethodCall(TransactionManager.class, "suspend"));
skel.assertNotCalled(new MethodCall(TransactionManager.class, "begin"));
@@ -155,8 +160,9 @@
for (int i = 0; i < invalids.length ; i++) {
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
try {
- assertNull("TransactionStrategy.NOT_SUPPORTED.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.NOT_SUPPORTED.begin(tm));
+ assertNull("TransactionStrategy.NOT_SUPPORTED.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.NOTSUPPORTED.begin(tm).getActiveTransaction());
} catch (Exception ise) {
fail("TransactionStrategy.NOT_SUPPORTED.begin() threw unexpected exception when manager status value is " + invalids[i]);
}
@@ -170,13 +176,15 @@
// If finish is called with a previously active transaction, then
// we expect this transaction to be resumed for a NOT_SUPPORTED strategy
try {
- TransactionStrategy.NOT_SUPPORTED.finish(tm, t);
+ TransactionToken tranToken = new TransactionToken(null, t, TransactionStrategy.NOTSUPPORTED);
+ TransactionStrategy.NOTSUPPORTED.finish(tm, tranToken);
skel.assertCalled(new MethodCall(TransactionManager.class, "resume", t));
skel.clearMethodCalls();
- TransactionStrategy.NOT_SUPPORTED.finish(tm, null);
+ tranToken = new TransactionToken(null, null, TransactionStrategy.NOTSUPPORTED);
+ TransactionStrategy.NOTSUPPORTED.finish(tm, tranToken);
skel.assertNotCalled(new MethodCall(TransactionManager.class, "resume", Transaction.class));
} catch (Exception e) {
- fail("TransactionStrategy.NOT_SUPPORTED.finish() threw unexpected exception");
+ fail("TransactionStrategy.NOT_SUPPORTED.finish() threw unexpected exception, " + e);
}
}
@@ -198,8 +206,9 @@
for (int i = 0; i < invalids.length ; i++) {
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
try {
- assertNull("TransactionStrategy.REQUIRED.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.REQUIRED.begin(tm));
+ assertNull("TransactionStrategy.REQUIRED.begin() did not return null when manager status value is " + invalids[i], TransactionStrategy.REQUIRED.begin(tm).getActiveTransaction());
} catch (Exception ise) {
fail("TransactionStrategy.REQUIRED.begin() threw unexpected exception when manager status value is " + invalids[i]);
}
@@ -214,7 +223,8 @@
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), Status.STATUS_MARKED_ROLLBACK);
try {
- TransactionStrategy.REQUIRED.finish(tm, t);
+ TransactionToken tranToken = new TransactionToken(t, null, TransactionStrategy.REQUIRED, true);
+ TransactionStrategy.REQUIRED.finish(tm, tranToken);
skel.assertCalled(new MethodCall(TransactionManager.class, "rollback"));
skel.assertNotCalled(new MethodCall(TransactionManager.class, "commit"));
@@ -226,14 +236,15 @@
for (int i = 0; i < invalids.length ; i++) {
skel.clearMethodCalls();
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), invalids[i]);
- TransactionStrategy.REQUIRED.finish(tm, t);
+ TransactionStrategy.REQUIRED.finish(tm, tranToken);
skel.assertCalled(new MethodCall(TransactionManager.class, "commit"));
skel.assertNotCalled(new MethodCall(TransactionManager.class, "rollback"));
}
// If null is passed instead of a tran we expect nothing to happen
skel.clearMethodCalls();
- TransactionStrategy.REQUIRED.finish(tm, null);
+ tranToken = new TransactionToken(null, null, TransactionStrategy.REQUIRED);
+ TransactionStrategy.REQUIRED.finish(tm, tranToken);
skel.assertNotCalled(new MethodCall(TransactionManager.class, "commit"));
skel.assertNotCalled(new MethodCall(TransactionManager.class, "rollback"));
@@ -250,7 +261,7 @@
// In the case of the REQUIRES_NEW strategy we expect an active tran to be suspended
// a new new transaction to begin
- TransactionStrategy.REQUIRES_NEW.begin(tm);
+ TransactionStrategy.REQUIRESNEW.begin(tm);
skel.assertCalled(new MethodCall(TransactionManager.class, "suspend"));
skel.assertCalled(new MethodCall(TransactionManager.class, "begin"));
@@ -271,8 +282,9 @@
for (int i = 0; i < manStatus.length ; i++) {
skel.clearMethodCalls();
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), manStatus[i]);
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
try {
- assertNull("TransactionStrategy.REQUIRES_NEW.begin() did not return null when manager status value is " + manStatus[i], TransactionStrategy.REQUIRES_NEW.begin(tm));
+ assertNull("TransactionStrategy.REQUIRES_NEW.begin() did not return null when manager status value is " + manStatus[i], TransactionStrategy.REQUIRESNEW.begin(tm).getActiveTransaction());
skel.assertCalled(new MethodCall(TransactionManager.class, "begin"));
skel.assertNotCalled(new MethodCall(TransactionManager.class, "suspend"));
} catch (Exception ise) {
@@ -323,7 +335,7 @@
// in calls to resume(t)
try {
- TransactionStrategy.REQUIRES_NEW.begin(tm);
+ TransactionStrategy.REQUIRESNEW.begin(tm);
} catch (SystemException se) {
// Expect to be in here
} catch (NotSupportedException nse) {
@@ -356,7 +368,8 @@
skel.setReturnValue(new MethodCall(TransactionManager.class, "getStatus"), allStates[i]);
try {
- TransactionStrategy.REQUIRES_NEW.finish(tm, t);
+ TransactionToken tranToken = new TransactionToken(t, t, TransactionStrategy.REQUIRESNEW, true);
+ TransactionStrategy.REQUIRESNEW.finish(tm, tranToken);
} catch (Exception e) {
fail("TransactionStrategy.REQUIRES_NEW.finish() threw unexpected exception when manager status is " + allStates[i]);
} finally {
@@ -366,7 +379,8 @@
try {
skel.clearMethodCalls();
- TransactionStrategy.REQUIRES_NEW.finish(tm, null);
+ TransactionToken tranToken = new TransactionToken(t, null, TransactionStrategy.REQUIRESNEW, true);
+ TransactionStrategy.REQUIRESNEW.finish(tm, tranToken);
} catch (Exception e) {
fail("TransactionStrategy.REQUIRES_NEW.finish() threw unexpected exception when manager status is " + allStates[i]);
} finally {
@@ -395,7 +409,8 @@
public void testSupports()
{
try {
- assertNull("TransTransactionStrategy.SUPPORTS.begin(tm) did not return null", TransactionStrategy.SUPPORTS.begin(tm));
+ skel.setReturnValue(new MethodCall(TransactionManager.class, "getTransaction"), null);
+ assertNull("TransTransactionStrategy.SUPPORTS.begin(tm) did not return null", TransactionStrategy.SUPPORTS.begin(tm).getActiveTransaction());
} catch (Exception e) {
fail("TransTransactionStrategy.SUPPORTS.begin(tm) threw an unexpected exception");
}
Added: incubator/aries/trunk/transaction/transaction-itests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/pom.xml?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/pom.xml (added)
+++ incubator/aries/trunk/transaction/transaction-itests/pom.xml Thu Mar 4 13:16:19 2010
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>transaction</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.itests</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <name>Apache Aries Transaction Integration Tests</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-service</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-mvn</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.swissbox</groupId>
+ <artifactId>pax-swissbox-tinybundles</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.manager</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.blueprint</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.testds</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.testbundle</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ <excludes>
+ <exclude>**/*$*</exclude>
+ <exclude>**/Abstract*.java</exclude>
+ </excludes>
+ <includes>
+ <include>**/Test*.java</include>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>ci-build-profile</id>
+ <activation>
+ <property>
+ <name>maven.repo.local</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!--
+ when the local repo location has been specified, we need to pass
+ on this information to PAX mvn url
+ -->
+ <argLine>-Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local}</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java Thu Mar 4 13:16:19 2010
@@ -0,0 +1,195 @@
+/*
+ * 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.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.container.def.options.VMOption;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.BootClasspathLibraryOption;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
+import org.ops4j.pax.exam.options.TimeoutOption;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
+import org.osgi.util.tracker.ServiceTracker;
+
+@RunWith(JUnit4TestRunner.class)
+public abstract class AbstractIntegrationTest {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ @Inject
+ protected BundleContext bundleContext;
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ customizer(),
+ bootClasspathLibrary("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
+
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+
+ // this is how you set the default log level when using pax
+ // logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+ mavenBundle("asm", "asm-all"),
+ mavenBundle("org.apache.derby", "derby"),
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+ mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.manager"),
+ mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.blueprint"),
+ mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.testbundle"),
+ mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.testds"),
+
+ //new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
+ //new TimeoutOption( 0 ),
+
+ equinox().version("3.5.0"));
+ options = updateOptions(options);
+ return options;
+ }
+
+ public static Customizer customizer() {
+ return new Customizer()
+ {
+ @Override
+ public InputStream customizeTestProbe( InputStream testProbe )
+ throws IOException
+ {
+ return modifyBundle( testProbe )
+ .set( Constants.IMPORT_PACKAGE, "javax.transaction;version=\"[0.0.0,1.1.0)\"" )
+ .build();
+ }
+ };
+ }
+
+ protected static BootClasspathLibraryOption bootClasspathLibrary(String groupId, String artifactId) {
+ MavenArtifactUrlReference maur =
+ new MavenArtifactUrlReference().groupId(groupId).artifactId(artifactId)
+ .versionAsInProject();
+ return new BootClasspathLibraryOption(maur);
+ }
+
+ protected static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
+ return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId)
+ .versionAsInProject();
+ }
+
+ protected Bundle getBundle(String symbolicName) {
+ return getBundle(symbolicName, null);
+ }
+
+ protected Bundle getBundle(String bundleSymbolicName, String version) {
+ Bundle result = null;
+ for (Bundle b : bundleContext.getBundles()) {
+ if (b.getSymbolicName().equals(bundleSymbolicName)) {
+ if (version == null
+ || b.getVersion().equals(Version.parseVersion(version))) {
+ result = b;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ protected static Option[] updateOptions(Option[] options) {
+ // We need to add pax-exam-junit here when running with the ibm
+ // jdk to avoid the following exception during the test run:
+ // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
+ if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+ Option[] ibmOptions = options(wrappedBundle(mavenBundle(
+ "org.ops4j.pax.exam", "pax-exam-junit")));
+ options = combine(ibmOptions, options);
+ }
+
+ return options;
+ }
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ return getOsgiService(null, type, filter, timeout);
+ }
+
+ protected <T> T getOsgiService(BundleContext bc, Class<T> type, String filter,
+ long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")"
+ + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")("
+ + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter,
+ null);
+ tracker.open();
+ // Note that the tracker is not closed to keep the reference
+ // This is buggy, has the service reference may change i think
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranStrategyTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranStrategyTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranStrategyTest.java Thu Mar 4 13:16:19 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 MandatoryTranStrategyTest extends AbstractIntegrationTest {
+
+ @Test
+ public void testMandatory() throws Exception {
+ TestBean bean = getOsgiService(TestBean.class, "(tranStrategy=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();
+ }
+ }
+}
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranStrategyTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranStrategyTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranStrategyTest.java Thu Mar 4 13:16:19 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 NeverTranStrategyTest extends AbstractIntegrationTest {
+
+ @Test
+ public void testNever() throws Exception {
+ TestBean bean = getOsgiService(TestBean.class, "(tranStrategy=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("Exception not thrown");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ finalRows = bean.countRows();
+ assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
+ }
+}
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranStrategyTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranStrategyTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranStrategyTest.java Thu Mar 4 13:16:19 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 NotSupportedTranStrategyTest extends AbstractIntegrationTest {
+
+ @Test
+ public void testNotSupported() throws Exception {
+ TestBean nsBean = getOsgiService(TestBean.class, "(tranStrategy=NotSupported)", DEFAULT_TIMEOUT);
+ TestBean rBean = getOsgiService(TestBean.class, "(tranStrategy=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("Exception not thrown");
+ } catch (Exception 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("Exception not thrown");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ finalRows = nsBean.countRows();
+ assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
+ }
+}
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranStrategyTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranStrategyTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranStrategyTest.java Thu Mar 4 13:16:19 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 RequiredTranStrategyTest extends AbstractIntegrationTest {
+
+ @Test
+ public void testRequired() throws Exception {
+ TestBean bean = getOsgiService(TestBean.class, "(tranStrategy=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);
+ }
+}
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranStrategyTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranStrategyTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranStrategyTest.java Thu Mar 4 13:16:19 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 RequiresNewTranStrategyTest extends AbstractIntegrationTest {
+
+ @Test
+ public void testRequiresNew() throws Exception {
+ TestBean rnBean = getOsgiService(TestBean.class, "(tranStrategy=RequiresNew)", DEFAULT_TIMEOUT);
+ TestBean rBean = getOsgiService(TestBean.class, "(tranStrategy=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);
+ }
+}
Added: incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranStrategyTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranStrategyTest.java?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranStrategyTest.java (added)
+++ incubator/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranStrategyTest.java Thu Mar 4 13:16:19 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 SupportsTranStrategyTest extends AbstractIntegrationTest {
+
+ @Test
+ public void testSupports() throws Exception {
+ TestBean bean = getOsgiService(TestBean.class, "(tranStrategy=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);
+ }
+}
Modified: incubator/aries/trunk/transaction/transaction-manager/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-manager/pom.xml?rev=918977&r1=918976&r2=918977&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-manager/pom.xml (original)
+++ incubator/aries/trunk/transaction/transaction-manager/pom.xml Thu Mar 4 13:16:19 2010
@@ -70,11 +70,11 @@
javax.resource.spi;version="1.5";resolution:=optional,
org.osgi.framework;version="1.4",
org.osgi.service.cm;version="[1.2.0,2.0.0)",
+ javax.transaction*;version="[0.0.0,1.1.0)",
*
</Import-Package>
<Export-Package>
- org.apache.geronimo.transaction*;version="${geronimo-transaction-version}",
- javax.transaction*;version="1.1"
+ org.apache.geronimo.transaction*;version="${geronimo-transaction-version}"
</Export-Package>
<Private-Package>
org.objectweb.howl.log*,
Added: incubator/aries/trunk/transaction/transaction-testbundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-testbundle/pom.xml?rev=918977&view=auto
==============================================================================
--- incubator/aries/trunk/transaction/transaction-testbundle/pom.xml (added)
+++ incubator/aries/trunk/transaction/transaction-testbundle/pom.xml Thu Mar 4 13:16:19 2010
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>transaction</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction.testbundle</artifactId>
+ <packaging>bundle</packaging>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <name>Apache Aries Transaction Test Bundle</name>
+ <build>
+ <resources>
+ <resource>
+ <targetPath>OSGI-INF/blueprint</targetPath>
+ <filtering>false</filtering>
+ <directory>${basedir}/src/main/resources/OSGI-INF/blueprint</directory>
+ <includes>
+ <include>*.xml</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.0.1</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>