aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1796654 - in /aries/trunk/transaction: transaction-itests/src/test/java/org/apache/aries/transaction/itests/ transaction-testbundle/src/main/java/org/apache/aries/transaction/test/ transaction-testbundle/src/main/java/org/apache/aries/tran...
Date Mon, 29 May 2017 15:59:19 GMT
Author: cschneider
Date: Mon May 29 15:59:19 2017
New Revision: 1796654

URL: http://svn.apache.org/viewvc?rev=1796654&view=rev
Log:
ARIES-1690: added itests

Added:
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RollbackOnTest.java
    aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/RollbackOnBean.java
    aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/RollbackOnBeanImpl.java
Modified:
    aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml

Added: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RollbackOnTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RollbackOnTest.java?rev=1796654&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RollbackOnTest.java
(added)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RollbackOnTest.java
Mon May 29 15:59:19 2017
@@ -0,0 +1,341 @@
+package org.apache.aries.transaction.itests;
+
+import org.apache.aries.transaction.test.RollbackOnBean;
+import org.apache.aries.transaction.test.TestBean;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.util.Filter;
+
+import javax.inject.Inject;
+import javax.transaction.Status;
+import java.sql.SQLException;
+
+import static junit.framework.Assert.assertEquals;
+
+public class RollbackOnTest extends AbstractIntegrationTest {
+
+	@Inject
+	@Filter(timeout = 120000, value = "(tranAttribute=Required)")
+	TestBean rBean;
+
+	@Inject
+	RollbackOnBean rollbackOnBean;
+
+	@Before
+	public void setUp() throws Exception {
+		rollbackOnBean.setrBean(rBean);
+	}
+
+	//default behavior, doesn't rollback on application exception
+	@Test
+	public void testNoRollbackOnDefaultAppException() throws Exception {
+		tran.begin();
+		try {
+			rBean.insertRow("test", 1, new SQLException());
+		} catch (SQLException e) {
+			// Ignore expected
+		}
+		int txStatus = tran.getStatus();
+		tran.rollback();
+		Assert.assertEquals("tx was rolled back", Status.STATUS_ACTIVE, txStatus);
+	}
+
+	//default behavior, doesn't rollback on exception
+	@Test
+	public void testNoRollbackOnDefaultException() throws Exception {
+		tran.begin();
+		try {
+			rollbackOnBean.throwException("test", 2);
+		} catch (Exception e) {
+			// Ignore expected
+		}
+		int txStatus = tran.getStatus();
+		tran.rollback();
+		Assert.assertEquals("tx was rolled back", Status.STATUS_ACTIVE, txStatus);
+	}
+
+	@Test
+	public void testExceptionRollbackOnException() throws Exception {
+		tran.begin();
+		try {
+			rollbackOnBean.throwExceptionRollbackOnException("noAnnotationDefaultException", -1);
+		} catch (Exception e) {
+			// Ignore expected
+		}
+		int txStatus = tran.getStatus();
+		tran.rollback();
+		Assert.assertEquals("tx was not rolled back", Status.STATUS_MARKED_ROLLBACK, txStatus);
+	}
+
+	@Test
+	public void testNoRollbackOnDefaultRuntimeException() throws Exception {
+		tran.begin();
+		try {
+			rBean.insertRow("test", 1, new RuntimeException());
+		} catch (Exception e) {
+			// Ignore expected
+		}
+		int txStatus = tran.getStatus();
+		tran.rollback();
+		Assert.assertEquals("tx was not rolled back", Status.STATUS_MARKED_ROLLBACK, txStatus);
+	}
+
+	//throw Runtime / handle Exception
+	@Test
+	public void testDontRollbackOnRuntimeException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwRuntimeExceptionDontRollbackOnException("testDontRollbackOnRuntimeException",
3);
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+	@Test
+	public void testRollbackOnRuntimeException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwRuntimeExceptionRollbackOnException("testRollbackOnRuntimeException",
4);
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+	//throw runtime / handle AppException
+	@Test
+	public void testThrowRuntimeDontRollbackOnAppException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwRuntimeExceptionDontRollbackOnAppException("testThrowRuntimeDontRollbackOnAppException",
5);
+			tran.commit();
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+	@Test
+	public void testThrowRuntimeRollbackOnException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwRuntimeExceptionRollbackOnAppException("testThrowRuntimeRollbackOnException",
6);
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+
+	//throw AppException / handle Exception
+	@Test
+	public void testThrowAppExceptionRollbackOnException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwApplicationExceptionRollbackOnException("testThrowAppExceptionRollbackOnException",
7);
+		} catch (SQLException e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+	@Test
+	public void testThrowAppExceptionDontRollbackOnException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwApplicationExceptionDontRollbackOnException("testThrowAppExceptionDontRollbackOnException",
8);
+		} catch (SQLException e) {
+			//ignore
+		}
+		tran.commit();
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 1, finalRows - initialRows);
+	}
+
+
+	//throw AppException / handle AppException
+	@Test
+	public void testThrowAppExceptionDontRollbackOnAppException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwApplicationExceptionDontRollbackOnAppException("testThrowAppExceptionDontRollbackOnAppException",
9);
+		} catch (SQLException e) {
+			//ignore
+		}
+		tran.commit();
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 1, finalRows - initialRows);
+	}
+
+	@Test
+	public void testThrowAppExceptionRollbackOnAppException() throws Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean.throwApplicationExceptionRollbackOnAppException("testThrowAppExceptionRollbackOnAppException",
10);
+		} catch (SQLException e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+
+	//throw Exception, handle Exception + DontRollBackOn
+	@Test
+	public void testThrowRuntimeExceptionRollbackExceptionDontRollbackOnAppException() throws
Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean
+					.throwExceptionRollbackOnExceptionDontRollbackOnAppException("testThrowRuntimeExceptionRollbackExceptionDontRollbackOnAppException",
11);
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+	@Test
+	public void testThrowRuntimeExceptionDontRollbackExceptionRollbackOnAppException() throws
Exception {
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean
+					.throwExceptionRollbackOnAppExceptionDontRollbackOnException("testThrowRuntimeExceptionDontRollbackExceptionRollbackOnAppException",
12);
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+			//expected
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 0, finalRows - initialRows);
+	}
+
+	@Test
+	public void testThrowAppExceptionDontRollbackExceptionRollbackOnAppException() throws Exception
{
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean
+					.throwAppExceptionRollbackOnAppExceptionDontRollbackOnException("testThrowAppExceptionDontRollbackExceptionRollbackOnAppException",
13);
+		} catch (SQLException e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			//expected
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 1, finalRows - initialRows);
+	}
+
+	@Test
+	public void testThrowAppExceptionRollbackExceptionDontRollbackOnAppException() throws Exception
{
+		int initialRows = counter.countRows();
+		tran.begin();
+		try {
+			rollbackOnBean
+					.throwAppExceptionRollbackOnExceptionDontRollbackOnAppException("testThrowAppExceptionRollbackExceptionDontRollbackOnAppException",
14);
+		} catch (Exception e) {
+			//ignore
+		}
+		try {
+			tran.commit();
+		} catch (Exception e) {
+			//expected
+			if (Status.STATUS_ACTIVE == tran.getStatus()) {
+				tran.rollback();
+			}
+		}
+		int finalRows = counter.countRows();
+		assertEquals("Added rows", 1, finalRows - initialRows);
+	}
+
+
+	@Override
+	protected TestBean getBean() {
+		return rBean;
+	}
+
+}

Added: aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/RollbackOnBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/RollbackOnBean.java?rev=1796654&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/RollbackOnBean.java
(added)
+++ aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/RollbackOnBean.java
Mon May 29 15:59:19 2017
@@ -0,0 +1,36 @@
+package org.apache.aries.transaction.test;
+
+import java.sql.SQLException;
+
+public interface RollbackOnBean {
+
+	void throwException(String name, int value) throws Exception;
+
+	void throwExceptionRollbackOnException(String name, int value) throws Exception;
+
+	void throwRuntimeExceptionRollbackOnException(String name, int value) throws SQLException;
+
+	void throwRuntimeExceptionDontRollbackOnException(String name, int value) throws SQLException;
+
+	void throwRuntimeExceptionDontRollbackOnAppException(String name, int value) throws SQLException;
+
+	void throwRuntimeExceptionRollbackOnAppException(String name, int value) throws SQLException;
+
+	void throwApplicationExceptionRollbackOnException(String name, int value) throws SQLException;
+
+	void throwApplicationExceptionRollbackOnAppException(String name, int value) throws SQLException;
+
+	void throwApplicationExceptionDontRollbackOnException(String name, int value) throws SQLException;
+
+	void throwApplicationExceptionDontRollbackOnAppException(String name, int value) throws
SQLException;
+
+	void throwExceptionRollbackOnExceptionDontRollbackOnAppException(String name, int value)
throws SQLException;
+
+	void throwExceptionRollbackOnAppExceptionDontRollbackOnException(String name, int value)
throws SQLException;
+
+	void throwAppExceptionRollbackOnExceptionDontRollbackOnAppException(String name, int value)
throws SQLException;
+
+	void throwAppExceptionRollbackOnAppExceptionDontRollbackOnException(String name, int value)
throws SQLException;
+
+	void setrBean(TestBean rBean);
+}

Added: aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/RollbackOnBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/RollbackOnBeanImpl.java?rev=1796654&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/RollbackOnBeanImpl.java
(added)
+++ aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/RollbackOnBeanImpl.java
Mon May 29 15:59:19 2017
@@ -0,0 +1,107 @@
+package org.apache.aries.transaction.test.impl;
+
+import org.apache.aries.transaction.test.RollbackOnBean;
+import org.apache.aries.transaction.test.TestBean;
+
+import javax.transaction.Transactional;
+import java.sql.SQLException;
+
+import static javax.transaction.Transactional.TxType;
+
+public class RollbackOnBeanImpl implements RollbackOnBean {
+
+	private TestBean rBean;
+
+	@Override
+	@Transactional(value = TxType.REQUIRED)
+	public void throwException(String name, int value) throws Exception {
+		rBean.insertRow(name, value, null);
+		throw new Exception("Test exception");
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, rollbackOn = Exception.class)
+	public void throwExceptionRollbackOnException(String name, int value) throws Exception {
+		rBean.insertRow(name, value, null);
+		throw new Exception("Test exception");
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, rollbackOn = Exception.class)
+	public void throwRuntimeExceptionRollbackOnException(String name, int value) throws SQLException
{
+		rBean.insertRow(name, value, new RuntimeException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, rollbackOn = SQLException.class)
+	public void throwRuntimeExceptionRollbackOnAppException(String name, int value) throws SQLException
{
+		rBean.insertRow(name, value, new RuntimeException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = Exception.class)
+	public void throwRuntimeExceptionDontRollbackOnException(String name, int value) throws
SQLException {
+		rBean.insertRow(name, value, new RuntimeException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = SQLException.class)
+	public void throwRuntimeExceptionDontRollbackOnAppException(String name, int value) throws
SQLException {
+		rBean.insertRow(name, value, new RuntimeException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, rollbackOn = Exception.class)
+	public void throwApplicationExceptionRollbackOnException(String name, int value) throws
SQLException {
+		rBean.insertRow(name, value, new SQLException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, rollbackOn = SQLException.class)
+	public void throwApplicationExceptionRollbackOnAppException(String name, int value) throws
SQLException {
+		rBean.insertRow(name, value, new SQLException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = Exception.class)
+	public void throwApplicationExceptionDontRollbackOnException(String name, int value) throws
SQLException {
+		rBean.insertRow(name, value, new SQLException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = SQLException.class)
+	public void throwApplicationExceptionDontRollbackOnAppException(String name, int value)
throws SQLException {
+		rBean.insertRow(name, value, new SQLException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = Exception.class, rollbackOn = SQLException.class)
+	public void throwExceptionRollbackOnExceptionDontRollbackOnAppException(String name, int
value) throws SQLException {
+		rBean.insertRow(name, value, new RuntimeException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = SQLException.class, rollbackOn
= Exception.class)
+	public void throwExceptionRollbackOnAppExceptionDontRollbackOnException(String name, int
value) throws SQLException {
+		rBean.insertRow(name, value, new RuntimeException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = SQLException.class, rollbackOn
= Exception.class)
+	public void throwAppExceptionRollbackOnExceptionDontRollbackOnAppException(String name,
int value) throws SQLException {
+		rBean.insertRow(name, value, new SQLException("Test exception"));
+	}
+
+	@Override
+	@Transactional(value = TxType.REQUIRED, dontRollbackOn = Exception.class, rollbackOn = SQLException.class)
+	public void throwAppExceptionRollbackOnAppExceptionDontRollbackOnException(String name,
int value) throws SQLException {
+		rBean.insertRow(name, value, new SQLException("Test exception"));
+	}
+
+
+	@Override
+	public void setrBean(TestBean rBean) {
+		this.rBean = rBean;
+	}
+
+}

Modified: aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1796654&r1=1796653&r2=1796654&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++ aries/trunk/transaction/transaction-testbundle/src/main/resources/OSGI-INF/blueprint/config.xml
Mon May 29 15:59:19 2017
@@ -50,6 +50,11 @@
         </service-properties>
     </service>
 
+    <bean id="rollbackOnBeanImpl" class="org.apache.aries.transaction.test.impl.RollbackOnBeanImpl">
+        <property name="rBean" ref="requiredBeanImpl" />
+    </bean>
+    <service id="rollbackOnBean" ref="rollbackOnBeanImpl" interface="org.apache.aries.transaction.test.RollbackOnBean"/>
+
     <bean id="supportsBeanImpl" class="org.apache.aries.transaction.test.impl.SupportsTestBeanImpl">
         <property name="testBean" ref="mandatoryBeanImpl" />
         <property name="connector" ref="connector" />



Mime
View raw message