Author: vhalbert(a)redhat.com
Date: 2009-12-22 11:58:39 -0500 (Tue, 22 Dec 2009)
New Revision: 1696
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TxnAutoTransaction.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/PessimisticWrapTransactionTests.java
Removed:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/AutoCommitTransaction.java
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/AutoWrapTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OffWrapTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java
Log:
Teiid-897 - changes related to autowrap change, added back in the old pessistic and
optimistic tests for backwards compatible
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/client/TransactionFactory.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -23,9 +23,10 @@
import org.teiid.test.framework.ConfigPropertyLoader;
import org.teiid.test.framework.TransactionContainer;
+import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
import org.teiid.test.framework.exception.QueryTestFailedException;
import org.teiid.test.framework.exception.TransactionRuntimeException;
-import org.teiid.test.framework.transaction.AutoCommitTransaction;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
import org.teiid.test.framework.transaction.JNDITransaction;
import org.teiid.test.framework.transaction.LocalTransaction;
import org.teiid.test.framework.transaction.OffWrapTransaction;
@@ -85,13 +86,13 @@
transacton = new JNDITransaction();
}
else if (type.equalsIgnoreCase(TRANSACTION_TYPES.OFFWRAP_TRANSACTION)) {
- transacton = new OffWrapTransaction();
+ transacton = new TxnAutoTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_OFF);
}
else if (type.equalsIgnoreCase(TRANSACTION_TYPES.ONWRAP_TRANSACTION)) {
- transacton = new OnWrapTransaction();
+ transacton = new TxnAutoTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_ON);
}
else if (type.equalsIgnoreCase(TRANSACTION_TYPES.AUTOWRAP_TRANSACTION)) {
- transacton = new AutoCommitTransaction();
+ transacton = new TxnAutoTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_AUTO);
} else {
throw new TransactionRuntimeException("Invalid property value of " +
type + " for " + TRANSACTION_TYPE );
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -7,6 +7,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.util.Collection;
import java.util.Iterator;
@@ -105,24 +106,7 @@
this.env.setProperty(key, value);
}
- class CloseInterceptor implements InvocationHandler {
-
- Connection conn;
-
- CloseInterceptor(Connection conn) {
- this.conn = conn;
- }
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
- if (method.getName().equals("close")) { //$NON-NLS-1$
- return null;
- }
- try {
- return method.invoke(this.conn, args);
- } catch (InvocationTargetException e) {
- throw e.getTargetException();
- }
- }
- }
+
void configure() throws QueryTestFailedException {
@@ -269,15 +253,19 @@
ConnectionStrategy cs = null;
if (identifier == null) {
- cs = new DriverConnection(ds.getProperties(), this.dsFactory);
+ cs = new DriverConnection(ds.getProperties(), null);
} else {
- cs = new DriverConnection(ds.getProperties(), this.dsFactory);
+ cs = new DriverConnection(ds.getProperties(), null);
}
- ds.setConnection(cs);
+ conn = cs.getConnection();
+
+ conn =
(Connection)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new
Class[] {java.sql.Connection.class}, new CloseInterceptor(conn));
+
+ ds.setConnection(conn);
- return ds.getConnection();
+ return conn;
}
@@ -300,16 +288,45 @@
ConnectionStrategy cs = null;
if (identifier == null) {
- cs = new DataSourceConnection(ds.getProperties(), this.dsFactory);
+ cs = new DataSourceConnection(ds.getProperties(), null);
} else {
- cs = new DataSourceConnection(ds.getProperties(), this.dsFactory);
+ cs = new DataSourceConnection(ds.getProperties(), null);
}
- ds.setXAConnection(cs);
+ conn = cs.getXAConnection();
- return ds.getXAConnection();
+ conn =
(XAConnection)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new
Class[] {javax.sql.XAConnection.class}, new CloseInterceptor(conn));
+
+ ds.setXAConnection(conn);
+
+ return conn;
+
}
+ class CloseInterceptor implements InvocationHandler {
+
+ Connection conn;
+ XAConnection xaconn;
+
+ CloseInterceptor(Object conn) {
+ if (conn instanceof Connection) {
+ this.conn = (Connection) conn;
+ } else {
+ this.xaconn = (XAConnection) conn;
+ }
+ }
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+ if (method.getName().equals("close")) { //$NON-NLS-1$
+ return null;
+ }
+ try {
+ return method.invoke(this.conn, args);
+ } catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ }
+ }
+ }
+
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -174,7 +174,6 @@
}
PropertiesUtils.setBeanProperties(ds, props, null);
- Object z = ds.getConnection();
return ((XADataSource)ds).getXAConnection();
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -4,7 +4,6 @@
*/
package org.teiid.test.framework.connection;
-import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -124,13 +123,7 @@
} else {
conn = DriverManager.getConnection(url);
}
-
-// if (this.useProxy()) {
-// conn =
(Connection)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new
Class[] {java.sql.Connection.class}, new CloseInterceptor(conn));
-// }
-
-// } catch (SQLException e) {
-
+
} catch (Throwable t) {
t.printStackTrace();
throw new QueryTestFailedException(t.getMessage());
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -1,11 +1,11 @@
package org.teiid.test.framework.datasource;
import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Properties;
import javax.sql.XAConnection;
-import org.teiid.test.framework.connection.ConnectionStrategy;
import org.teiid.test.framework.exception.QueryTestFailedException;
/**
@@ -26,12 +26,10 @@
// The connections are stored in the datasource and are reused
// for the duration of all tests so thats there's not
// disconnect/connect being performed over and over
- private ConnectionStrategy conn;
- private ConnectionStrategy xaconn;
+ private Connection conn=null;
+ private XAConnection xaconn=null;
- public DataSource() {
- this.name = "notassigned";
- }
+
public DataSource(String name, String group, Properties properties) {
this.name = name;
this.group = group;
@@ -68,23 +66,56 @@
public Connection getConnection() throws QueryTestFailedException {
if (this.conn == null) return null;
- return this.conn.getConnection();
+ try {
+ if (this.conn.isClosed()) {
+ this.conn = null;
+ }
+ } catch (SQLException e) {
+ this.conn = null;
+ }
+
+ return this.conn;
+
}
- public void setConnection(ConnectionStrategy c) {
+ public void setConnection(Connection c) {
this.conn = c;
}
- public XAConnection getXAConnection() throws QueryTestFailedException {
- if (this.xaconn == null) return null;
-
- return this.xaconn.getXAConnection();
+ public XAConnection getXAConnection() throws QueryTestFailedException {
+ return this.xaconn;
+
}
- public void setXAConnection(ConnectionStrategy xaconn) {
+ public void setXAConnection(XAConnection xaconn) {
this.xaconn = xaconn;
}
+
+ public void shutdown() {
+ if (this.conn != null) {
+ try {
+ this.conn.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ this.conn = null;
+
+ try {
+
+ if (this.xaconn != null) {
+ this.xaconn.close();
+ }
+ } catch (SQLException e) {
+ // ignore..
+ }
+
+ this.xaconn = null;
+
+ }
+
}
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -8,6 +8,7 @@
import java.io.FileFilter;
import java.io.IOException;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -97,6 +98,22 @@
void clear() {
modelToDatasourceMap.clear();
}
+
+ public void shutdown() {
+ if (allDatasourcesMap == null || allDatasourcesMap.size() == 0) {
+ return;
+ }
+
+ Iterator<String> it=allDatasourcesMap.keySet().iterator();
+ while(it.hasNext()) {
+ String key = (String) it.next();
+ DataSource ds = allDatasourcesMap.get(key);
+ ds.shutdown();
+ }
+
+ allDatasourcesMap.clear();
+
+ }
public void setDataSource(String modelName, DataSource ds) {
modelToDatasourceMap.put(modelName, ds);
Deleted:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/AutoCommitTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/AutoCommitTransaction.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/AutoCommitTransaction.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2000-2007 MetaMatrix, Inc.
- * All rights reserved.
- */
-package org.teiid.test.framework.transaction;
-
-import org.teiid.test.framework.TransactionContainer;
-import org.teiid.test.framework.TransactionQueryTestCase;
-import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
-
-
-/**
- * This transction is only valid when
- * AutoCommit = ON
- * txnAutoWrap = Optimistic.
- */
-public class AutoCommitTransaction extends TransactionContainer {
-
- private String autocommittxn = null;
-
- public AutoCommitTransaction() {
- super();
- }
-
- public AutoCommitTransaction(String autocommittxn) {
- super();
- this.autocommittxn = autocommittxn;
- }
-
- public void before(TransactionQueryTestCase test) {
- if (this.autocommittxn != null) {
-
test.getConnectionStrategy().setEnvironmentProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP,
this.autocommittxn);
- }
-
- }
-
- public void after(TransactionQueryTestCase test) {
-
- }
-}
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TxnAutoTransaction.java
===================================================================
---
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TxnAutoTransaction.java
(rev 0)
+++
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TxnAutoTransaction.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2000-2007 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.test.framework.transaction;
+
+import org.teiid.test.framework.TransactionContainer;
+import org.teiid.test.framework.TransactionQueryTestCase;
+import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
+
+
+/**
+ * This transction is only valid when
+ * AutoCommit = ON
+ * txnAutoWrap = Optimistic.
+ */
+public class TxnAutoTransaction extends TransactionContainer {
+
+ private String autocommittxn = null;
+
+ public TxnAutoTransaction() {
+ super();
+ }
+
+ public TxnAutoTransaction(String autocommittxn) {
+ super();
+ this.autocommittxn = autocommittxn;
+ }
+
+ public void before(TransactionQueryTestCase test) {
+ if (this.autocommittxn != null) {
+
test.getConnectionStrategy().setEnvironmentProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP,
this.autocommittxn);
+ }
+
+ }
+
+ public void after(TransactionQueryTestCase test) {
+
+ }
+}
Property changes on:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/TxnAutoTransaction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/AutoWrapTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/AutoWrapTransactionTests.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/AutoWrapTransactionTests.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -6,529 +6,139 @@
import java.util.ArrayList;
+import org.teiid.test.framework.ConfigPropertyNames;
import org.teiid.test.framework.TransactionContainer;
-import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
import org.teiid.test.framework.query.AbstractQueryTransactionTest;
import org.teiid.test.framework.query.QueryExecution;
-import org.teiid.test.framework.transaction.AutoCommitTransaction;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
import com.metamatrix.jdbc.api.AbstractQueryTest;
+public class AutoWrapTransactionTests extends CommonTransactionTests {
-/**
- * The main thing to test in this is, when the single source should is involved it should
work
- * fine, when multiple sources involved it should fail.
- */
-public class AutoWrapTransactionTests extends BaseAbstractTransactionTestCase {
-
public AutoWrapTransactionTests(String testName) {
super(testName);
}
protected TransactionContainer getTransactionContainter() {
- return new AutoCommitTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_AUTO);
+
+ return new
TxnAutoTransaction(ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_AUTO);
}
-
-
///////////////////////////////////////////////////////////////////////////////////////////////
- // Single Source - Rows below 500 (for insert/update/delete)
-
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Sources = 1
- * Commands = 1, Select
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testSingleSourceSelect() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceSelect") {
- public void testCase() throws Exception {
- execute("select * from pm1.g1 where pm1.g1.e1 < 100");
- assertRowCount(100);
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 1
- * Commands = 1, Update(prepared statement)
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testSingleSourcePreparedUpdate() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourcePreparedUpdate") {
- public void testCase() throws Exception {
- execute("insert into pm1.g1 (e1, e2) values(?, ?)", new
Object[] {new Integer(102), "102"});
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
-
- // now verify the results
- AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
- test.execute("select * from g1 where e1 = 102");
- test.assertRowCount(1);
- test.closeConnection();
- }
-
- /**
- * Sources = 1
* Commands = multiple - Success
* Batching = Full Processing, Single Connector Batch
- * result = commit
+ * result = rollback
*/
- public void testSingleSourceMultipleCommands() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceMultipleCommands") {
+ public void testSingleSourceMultipleCommandsReferentialIntegrityRollback() throws
Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
public void testCase() throws Exception {
- execute("delete from pm1.g2 where pm1.g2.e1 >= ?", new
Object[] {new Integer(100)});
- execute("delete from pm1.g1 where pm1.g1.e1 >= ?", new
Object[] {new Integer(100)});
-
- execute("select * from pm1.g1");
- assertRowCount(100);
- for (int i = 100; i < 120; i++) {
+ for (int i = 200; i < 210; i++) {
Integer val = new Integer(i);
execute("insert into pm1.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
execute("insert into pm1.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
}
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
-
- // now verify the results
- AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
- test.execute("select * from g1 where e1 >= 100 and e1 < 120");
- test.assertRowCount(20);
- test.execute("select * from g2 where e1 >= 100 and e1 < 120");
- test.assertRowCount(20);
- test.closeConnection();
- }
-
- /**
- * Sources = 1
- * Commands = multiple - Success
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testSingleSourceBatchCommand() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceBatchCommand") {
- public void testCase() throws Exception {
- ArrayList list = new ArrayList();
- list.add("delete from pm1.g2 where pm1.g2.e1 >= 100");
- list.add("delete from pm1.g1 where pm1.g1.e1 >= 100");
-
- for (int i = 200; i < 205; i++) {
- list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
- list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
- }
- executeBatch((String[])list.toArray(new String[list.size()]));
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
-
- // now verify the results
- AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
- test.execute("select * from g1 where e1 >= 200 and e1 < 205");
- test.assertRowCount(5);
- test.execute("select * from g2 where e1 >= 200 and e1 < 205");
- test.assertRowCount(5);
- test.closeConnection();
- }
-
- /**
- * Sources = 1
- * Commands = 1, Update(prepared statement)
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testSingleSourcePreparedUpdateRollback() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourcePreparedUpdateRollback") {
- public void testCase() throws Exception {
- execute("insert into pm1.g2 (e1, e2) values(?, ?)", new
Object[] {new Integer(9999), "9999"});
- }
-
- public boolean exceptionExpected() {
- return true;
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
-
- // now verify the results
- AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
- test.execute("select * from g2 where e1 = 9999");
- test.assertRowCount(0);
- test.closeConnection();
- }
-
-
- /**
- * Sources = 1
- * Commands = multiple - Success
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testSingleSourceMultipleCommandsRollback() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceMultipleCommandsRollback") {
- public void testCase() throws Exception {
- execute("delete from pm1.g2 where pm1.g2.e1 >= ?", new
Object[] {new Integer(100)});
- execute("delete from pm1.g1 where pm1.g1.e1 >= ?", new
Object[] {new Integer(100)});
- execute("select * from pm1.g1");
- assertRowCount(100);
-
- for (int i = 300; i < 310; i++) {
- Integer val = new Integer(i);
- execute("insert into pm1.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
- execute("insert into pm1.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
- }
-
- // this will make it rollback
- execute("insert into pm1.g2 (e1, e2) values(?, ?)", new
Object[] {new Integer(9999), "9999"});
+ // try to rollback, however since this pessimistic above two are already
commited
+ execute("insert into pm1.g2 (e1, e2) values(?,?)", new Object[]
{new Integer(9999), "9999"});
}
public boolean exceptionExpected() {
return true;
- }
-
+ }
};
// run test
getTransactionContainter().runTransaction(userTxn);
- // now verify the results (since they are not bundled in single command they
should be treated individually)
+ // now verify the results
AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
- test.execute("select * from g1 where e1 >= 300 and e1 < 310");
+ test.execute("select * from g1 where e1 >= 200 and e1 < 210");
test.assertRowCount(10);
- test.execute("select * from g2 where e1 >= 300 and e1 < 310");
- test.assertRowCount(10);
test.execute("select * from g2 where e1 = 9999");
test.assertRowCount(0);
test.closeConnection();
- }
+ }
/**
* Sources = 1
* Commands = multiple - Success
* Batching = Full Processing, Single Connector Batch
- * result = commit
+ * result = rollback
*/
- public void testSingleSourceBatchCommandRollback() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceBatchCommandRollback") {
+ public void testSingleSourceBatchCommandReferentialIntegrityRollback() throws
Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
public void testCase() throws Exception {
ArrayList list = new ArrayList();
- list.add("delete from pm1.g2 where pm1.g2.e1 >= 100");
- list.add("delete from pm1.g1 where pm1.g1.e1 >= 100");
-
- for (int i = 400; i < 410; i++) {
+ for (int i = 200; i < 210; i++) {
list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
- list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
}
-
- // this will make it rollback
- list.add("insert into pm1.g2 (e1, e2) values(9999,
'9999')");
+ // try to rollback, since we are in single batch it must rollback
+ list.add("insert into pm1.g2 (e1, e2)
values(9999,'9999')");
executeBatch((String[])list.toArray(new String[list.size()]));
}
public boolean exceptionExpected() {
return true;
- }
-
+ }
};
// run test
getTransactionContainter().runTransaction(userTxn);
- // now verify the results (all commands will trated as single under single
transaction)
+ // now verify the results
AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
- test.execute("select * from g1 where e1 >= 400 and e1 < 410");
+ test.execute("select * from g1 where e1 >= 200 and e1 < 210");
test.assertRowCount(0);
- test.execute("select * from g2 where e1 >= 400 and e1 < 410");
- test.assertRowCount(0);
test.execute("select * from g2 where e1 = 9999");
- test.assertRowCount(0);
+ test.assertRowCount(0);
test.closeConnection();
- }
+ }
-
///////////////////////////////////////////////////////////////////////////////////////////////
- // Multiple Sources - Rows from 500
-
///////////////////////////////////////////////////////////////////////////////////////////////
-
/**
* Sources = 2
- * Commands = 1, Select
+ * Commands = 1, Update
* Batching = Full Processing, Single Connector Batch
* result = commit
*/
- public void testMultipleSourceSelect() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceSelect") {
+ public void testMultipleSourceBulkRowInsertRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ ArrayList list = new ArrayList();
public void testCase() throws Exception {
- execute("select * from pm1.g1 join pm2.g1 on pm1.g1.e1 = pm2.g1.e1
where pm1.g1.e1 < 100");
- assertRowCount(100);
- }
-
- public void after() {
- // selects are special case as they will not fail to use multiple
sources. The transaction
- // source count only starts when there are updates to db, so this is OK
- if (exceptionOccurred()) {
- fail("should not have failed to involve multiple sources under
optimistic txn");
+ for (int i = 100; i < 120; i++) {
+ list.add("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values("+i+",'"+i+"',"+i+",'"+i+"')");
}
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 2
- * Commands = 1, Select
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testMultipleSourceUpdate() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceUpdate") {
- public void testCase() throws Exception {
- Integer value = new Integer(500);
- execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {value, value.toString(), value, value.toString()});
- }
-
- public boolean exceptionExpected() {
- return true;
- }
-
- public void after() {
- if (!exceptionOccurred()) {
- fail("should have failed to involve multiple sources under
optimistic txn");
- }
- else {
- if (getLastException() != null) {
- this.getLastException().printStackTrace();
-// String msg = getLastException().getMessage();
-// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
-// assertTrue(isfound);
- } else {
- fail("Program Error: it indicates exception occured, but no
exception is found" );
- }
-
- // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
- }
- }
- };
-
- // run test
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 2
- * Commands = multiple - Success
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testMultipleSourcesBatchCommand() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourcesBatchCommand") {
- public void testCase() throws Exception {
- ArrayList list = new ArrayList();
- list.add("delete from pm1.g2 where pm1.g2.e1 >= 100");
- list.add("delete from pm1.g1 where pm1.g1.e1 >= 100");
+ list.add("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where
pm1.g1.e1 >= 100");
- list.add("delete from pm2.g2 where pm2.g2.e1 >= 100");
- list.add("delete from pm2.g1 where pm2.g1.e1 >= 100");
+ // force the rollback by trying to insert an invalid row.
+ list.add("insert into pm1.g2 (e1, e2)
values(9999,'9999')");
- for (int i = 200; i < 210; i++) {
- list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
- list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
-
- list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
- list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
- }
executeBatch((String[])list.toArray(new String[list.size()]));
}
- public void after() {
- if (!exceptionOccurred()) {
- fail("should have failed to involve multiple sources under
optimistic txn");
- }
- else {
- if (getLastException() != null) {
- this.getLastException().printStackTrace();
-// String msg = getLastException().getMessage();
-// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
-// assertTrue(isfound);
- } else {
- fail("Program Error: it indicates exception occured, but no
exception is found" );
- }
- // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
- }
- }
-
public boolean exceptionExpected() {
return true;
- }
-
- };
-
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 2
- * Commands = 1, Select
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testMultipleSourceVirtualSelect() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualSelect") {
- public void testCase() throws Exception {
- execute("select * from vm.g1");
- }
-
- public void after() {
- if (exceptionOccurred()) {
- fail("should not have failed to involve multiple sources under
optimistic txn");
- }
}
};
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 2
- * Commands = 1, Select
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testMultipleSourceVirtualProceduralSelect() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualProceduralSelect") {
- public void testCase() throws Exception {
- execute("select * from vm.p1");
- }
- // if vm.p1 needs a transaction, depends on transformation
- //
- public void after() {
- if (exceptionOccurred()) {
- fail("should have failed to involve multiple sources under
optimistic txn");
- }
- }
- };
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 2
- * Commands = 1, Select
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testMultipleSourceVirtualProcedure() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualProcedure") {
- public void testCase() throws Exception {
- execute("select * from vm.p2 where vm.p2.e1 = ? and vm.p2.e2 =
?", new Object[] {new Integer(200), "200"});
- }
-
- public boolean exceptionExpected() {
- return true;
- }
-
- public void after() {
- if (!exceptionOccurred()) {
- fail("should have failed to involve multiple sources under
optimistic txn");
- }
- else {
- if (getLastException() != null) {
- this.getLastException().printStackTrace();
-// String msg = getLastException().getMessage();
-// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
-// assertTrue(isfound);
- } else {
- fail("Program Error: it indicates exception occured, but no
exception is found" );
- }
- // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
- }
- }
- };
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(0);
+ test.closeConnection();
- getTransactionContainter().runTransaction(userTxn);
- }
-
- public void testMultipleSourceVirtualProceduralSelectWithUpdate() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualProceduralSelectWithUpdate")
{
- public void testCase() throws Exception {
- execute("exec vm.p2(?, ?)", new Object[] {new Integer(200),
"200"});
- }
-
- public boolean exceptionExpected() {
- return true;
- }
-
- public void after() {
- if (!exceptionOccurred()) {
- fail("should have failed to involve multiple sources under
optimistic txn");
- }
- else {
- if (getLastException() != null) {
- this.getLastException().printStackTrace();
-// String msg = getLastException().getMessage();
-// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
-// assertTrue(isfound);
- } else {
- fail("Program Error: it indicates exception occured, but no
exception is found" );
- }
- // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
- }
- }
- };
-
- getTransactionContainter().runTransaction(userTxn);
- }
-
- /**
- * Sources = 2
- * Commands = 1, Select
- * Batching = Full Processing, Single Connector Batch
- * result = commit
- */
- public void testMultipleSourceVirtualUpdate() throws Exception {
- AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualUpdate") {
- public void testCase() throws Exception {
- execute("delete from vm.g1 where vm.g1.pm1e1 > 100");
- }
-
- public void after() {
- if (!exceptionOccurred()) {
- fail("should have failed to involve multiple sources under
optimistic txn");
- }
- else {
- if (getLastException() != null) {
- this.getLastException().printStackTrace();
-// String msg = getLastException().getMessage();
-// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
-// assertTrue(isfound);
- } else {
- fail("Program Error: it indicates exception occured, but no
exception is found" );
- }
- // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
- }
- }
-
- public boolean exceptionExpected() {
- return true;
- }
-
- };
-
- getTransactionContainter().runTransaction(userTxn);
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(0);
+ test.closeConnection();
}
}
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OffWrapTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OffWrapTransactionTests.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OffWrapTransactionTests.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -10,7 +10,7 @@
import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
import org.teiid.test.framework.query.AbstractQueryTransactionTest;
import org.teiid.test.framework.query.QueryExecution;
-import org.teiid.test.framework.transaction.AutoCommitTransaction;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
import com.metamatrix.jdbc.api.AbstractQueryTest;
@@ -25,7 +25,7 @@
@Override
protected TransactionContainer getTransactionContainter() {
- return new AutoCommitTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_OFF);
+ return new TxnAutoTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_OFF);
}
Modified:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java 2009-12-21
20:53:49 UTC (rev 1695)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -10,7 +10,7 @@
import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
import org.teiid.test.framework.query.AbstractQueryTransactionTest;
import org.teiid.test.framework.query.QueryExecution;
-import org.teiid.test.framework.transaction.AutoCommitTransaction;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
import com.metamatrix.jdbc.api.AbstractQueryTest;
@@ -26,7 +26,7 @@
@Override
protected TransactionContainer getTransactionContainter() {
- return new AutoCommitTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_ON);
+ return new TxnAutoTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_ON);
}
/**
Added:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticTransactionTests.java
(rev 0)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticTransactionTests.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -0,0 +1,534 @@
+/*
+ * Copyright (c) 2000-2007 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.test.testcases;
+
+import java.util.ArrayList;
+
+import org.teiid.test.framework.TransactionContainer;
+import org.teiid.test.framework.ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS;
+import org.teiid.test.framework.query.AbstractQueryTransactionTest;
+import org.teiid.test.framework.query.QueryExecution;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+
+/**
+ * The main thing to test in this is, when the single source should is involved it should
work
+ * fine, when multiple sources involved it should fail.
+ */
+public class OptimisticTransactionTests extends BaseAbstractTransactionTestCase {
+
+ public OptimisticTransactionTests(String testName) {
+ super(testName);
+ }
+
+ protected TransactionContainer getTransactionContainter() {
+ return new TxnAutoTransaction(TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_OPTIMISTIC);
+ }
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
+ // Single Source - Rows below 500 (for insert/update/delete)
+
///////////////////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Sources = 1
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourceSelect() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceSelect") {
+ public void testCase() throws Exception {
+ execute("select * from pm1.g1 where pm1.g1.e1 < 100");
+ assertRowCount(100);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 1
+ * Commands = 1, Update(prepared statement)
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourcePreparedUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourcePreparedUpdate") {
+ public void testCase() throws Exception {
+ execute("insert into pm1.g1 (e1, e2) values(?, ?)", new
Object[] {new Integer(102), "102"});
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 = 102");
+ test.assertRowCount(1);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourceMultipleCommands() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceMultipleCommands") {
+ public void testCase() throws Exception {
+ execute("delete from pm1.g2 where pm1.g2.e1 >= ?", new
Object[] {new Integer(100)});
+ execute("delete from pm1.g1 where pm1.g1.e1 >= ?", new
Object[] {new Integer(100)});
+
+ execute("select * from pm1.g1");
+ assertRowCount(100);
+ for (int i = 100; i < 120; i++) {
+ Integer val = new Integer(i);
+ execute("insert into pm1.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ execute("insert into pm1.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ }
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(20);
+ test.execute("select * from g2 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(20);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourceBatchCommand() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceBatchCommand") {
+ public void testCase() throws Exception {
+ ArrayList list = new ArrayList();
+ list.add("delete from pm1.g2 where pm1.g2.e1 >= 100");
+ list.add("delete from pm1.g1 where pm1.g1.e1 >= 100");
+
+ for (int i = 200; i < 205; i++) {
+ list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
+ list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
+ }
+ executeBatch((String[])list.toArray(new String[list.size()]));
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 200 and e1 < 205");
+ test.assertRowCount(5);
+ test.execute("select * from g2 where e1 >= 200 and e1 < 205");
+ test.assertRowCount(5);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = 1, Update(prepared statement)
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourcePreparedUpdateRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourcePreparedUpdateRollback") {
+ public void testCase() throws Exception {
+ execute("insert into pm1.g2 (e1, e2) values(?, ?)", new
Object[] {new Integer(9999), "9999"});
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g2 where e1 = 9999");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourceMultipleCommandsRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceMultipleCommandsRollback") {
+ public void testCase() throws Exception {
+ execute("delete from pm1.g2 where pm1.g2.e1 >= ?", new
Object[] {new Integer(100)});
+ execute("delete from pm1.g1 where pm1.g1.e1 >= ?", new
Object[] {new Integer(100)});
+
+ execute("select * from pm1.g1");
+ assertRowCount(100);
+
+ for (int i = 300; i < 310; i++) {
+ Integer val = new Integer(i);
+ execute("insert into pm1.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ execute("insert into pm1.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ }
+
+ // this will make it rollback
+ execute("insert into pm1.g2 (e1, e2) values(?, ?)", new
Object[] {new Integer(9999), "9999"});
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results (since they are not bundled in single command they
should be treated individually)
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 300 and e1 < 310");
+ test.assertRowCount(10);
+ test.execute("select * from g2 where e1 >= 300 and e1 < 310");
+ test.assertRowCount(10);
+ test.execute("select * from g2 where e1 = 9999");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourceBatchCommandRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testSingleSourceBatchCommandRollback") {
+ public void testCase() throws Exception {
+ ArrayList list = new ArrayList();
+ list.add("delete from pm1.g2 where pm1.g2.e1 >= 100");
+ list.add("delete from pm1.g1 where pm1.g1.e1 >= 100");
+
+ for (int i = 400; i < 410; i++) {
+ list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
+ list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
+ }
+
+ // this will make it rollback
+ list.add("insert into pm1.g2 (e1, e2) values(9999,
'9999')");
+
+ executeBatch((String[])list.toArray(new String[list.size()]));
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results (all commands will trated as single under single
transaction)
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 400 and e1 < 410");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 400 and e1 < 410");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 = 9999");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
+ // Multiple Sources - Rows from 500
+
///////////////////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceSelect() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceSelect") {
+ public void testCase() throws Exception {
+ execute("select * from pm1.g1 join pm2.g1 on pm1.g1.e1 = pm2.g1.e1
where pm1.g1.e1 < 100");
+ assertRowCount(100);
+ }
+
+ public void after() {
+ // selects are special case as they will not fail to use multiple
sources. The transaction
+ // source count only starts when there are updates to db, so this is OK
+ if (exceptionOccurred()) {
+ fail("should not have failed to involve multiple sources under
optimistic txn");
+ }
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceUpdate") {
+ public void testCase() throws Exception {
+ Integer value = new Integer(500);
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {value, value.toString(), value, value.toString()});
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ public void after() {
+ if (!exceptionOccurred()) {
+ fail("should have failed to involve multiple sources under
optimistic txn");
+ }
+ else {
+ if (getLastException() != null) {
+ this.getLastException().printStackTrace();
+// String msg = getLastException().getMessage();
+// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
+// assertTrue(isfound);
+ } else {
+ fail("Program Error: it indicates exception occured, but no
exception is found" );
+ }
+
+ // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
+ }
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourcesBatchCommand() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourcesBatchCommand") {
+ public void testCase() throws Exception {
+ ArrayList list = new ArrayList();
+ list.add("delete from pm1.g2 where pm1.g2.e1 >= 100");
+ list.add("delete from pm1.g1 where pm1.g1.e1 >= 100");
+
+ list.add("delete from pm2.g2 where pm2.g2.e1 >= 100");
+ list.add("delete from pm2.g1 where pm2.g1.e1 >= 100");
+
+ for (int i = 200; i < 210; i++) {
+ list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
+ list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
+
+ list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
+ list.add("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
+ }
+ executeBatch((String[])list.toArray(new String[list.size()]));
+ }
+
+ public void after() {
+ if (!exceptionOccurred()) {
+ fail("should have failed to involve multiple sources under
optimistic txn");
+ }
+ else {
+ if (getLastException() != null) {
+ this.getLastException().printStackTrace();
+// String msg = getLastException().getMessage();
+// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
+// assertTrue(isfound);
+ } else {
+ fail("Program Error: it indicates exception occured, but no
exception is found" );
+ }
+ // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
+ }
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceVirtualSelect() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualSelect") {
+ public void testCase() throws Exception {
+ execute("select * from vm.g1");
+ }
+
+ public void after() {
+ if (exceptionOccurred()) {
+ fail("should not have failed to involve multiple sources under
optimistic txn");
+ }
+ }
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceVirtualProceduralSelect() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualProceduralSelect") {
+ public void testCase() throws Exception {
+ execute("select * from vm.p1");
+ }
+ // if vm.p1 needs a transaction, depends on transformation
+ //
+ public void after() {
+ if (exceptionOccurred()) {
+ fail("should have failed to involve multiple sources under
optimistic txn");
+ }
+ }
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceVirtualProcedure() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualProcedure") {
+ public void testCase() throws Exception {
+ execute("select * from vm.p2 where vm.p2.e1 = ? and vm.p2.e2 =
?", new Object[] {new Integer(200), "200"});
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ public void after() {
+ if (!exceptionOccurred()) {
+ fail("should have failed to involve multiple sources under
optimistic txn");
+ }
+ else {
+ if (getLastException() != null) {
+ this.getLastException().printStackTrace();
+// String msg = getLastException().getMessage();
+// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
+// assertTrue(isfound);
+ } else {
+ fail("Program Error: it indicates exception occured, but no
exception is found" );
+ }
+ // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
+ }
+ }
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ public void testMultipleSourceVirtualProceduralSelectWithUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualProceduralSelectWithUpdate")
{
+ public void testCase() throws Exception {
+ execute("exec vm.p2(?, ?)", new Object[] {new Integer(200),
"200"});
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ public void after() {
+ if (!exceptionOccurred()) {
+ fail("should have failed to involve multiple sources under
optimistic txn");
+ }
+ else {
+ if (getLastException() != null) {
+ this.getLastException().printStackTrace();
+// String msg = getLastException().getMessage();
+// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
+// assertTrue(isfound);
+ } else {
+ fail("Program Error: it indicates exception occured, but no
exception is found" );
+ }
+ // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
+ }
+ }
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceVirtualUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new
AbstractQueryTransactionTest("testMultipleSourceVirtualUpdate") {
+ public void testCase() throws Exception {
+ execute("delete from vm.g1 where vm.g1.pm1e1 > 100");
+ }
+
+ public void after() {
+ if (!exceptionOccurred()) {
+ fail("should have failed to involve multiple sources under
optimistic txn");
+ }
+ else {
+ if (getLastException() != null) {
+ this.getLastException().printStackTrace();
+// String msg = getLastException().getMessage();
+// boolean isfound = (msg.indexOf("txnAutoWrap=OPTIMISTIC") !=
-1 ? true : false);
+// assertTrue(isfound);
+ } else {
+ fail("Program Error: it indicates exception occured, but no
exception is found" );
+ }
+ // assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
+ }
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+}
Property changes on:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticTransactionTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/PessimisticWrapTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/PessimisticWrapTransactionTests.java
(rev 0)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/PessimisticWrapTransactionTests.java 2009-12-22
16:58:39 UTC (rev 1696)
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2000-2007 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.test.testcases;
+
+import java.util.ArrayList;
+
+import org.teiid.test.framework.ConfigPropertyNames;
+import org.teiid.test.framework.TransactionContainer;
+import org.teiid.test.framework.query.AbstractQueryTransactionTest;
+import org.teiid.test.framework.query.QueryExecution;
+import org.teiid.test.framework.transaction.TxnAutoTransaction;
+
+import com.arjuna.common.internal.util.logging.commonPropertyManager;
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+public class PessimisticWrapTransactionTests extends CommonTransactionTests {
+
+ public PessimisticWrapTransactionTests(String testName) {
+ super(testName);
+ }
+
+ protected TransactionContainer getTransactionContainter() {
+
+ return new
TxnAutoTransaction(ConfigPropertyNames.TXN_AUTO_WRAP_OPTIONS.AUTO_WRAP_PESSIMISTIC);
+ }
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testSingleSourceMultipleCommandsReferentialIntegrityRollback() throws
Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ for (int i = 200; i < 210; i++) {
+ Integer val = new Integer(i);
+ execute("insert into pm1.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ execute("insert into pm1.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ }
+
+ // try to rollback, however since this pessimistic above two are already
commited
+ execute("insert into pm1.g2 (e1, e2) values(?,?)", new Object[]
{new Integer(9999), "9999"});
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 200 and e1 < 210");
+ test.assertRowCount(10);
+ test.execute("select * from g2 where e1 = 9999");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testSingleSourceBatchCommandReferentialIntegrityRollback() throws
Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ ArrayList list = new ArrayList();
+ for (int i = 200; i < 210; i++) {
+ list.add("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
+ }
+
+ // try to rollback, since we are in single batch it must rollback
+ list.add("insert into pm1.g2 (e1, e2)
values(9999,'9999')");
+ executeBatch((String[])list.toArray(new String[list.size()]));
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 200 and e1 < 210");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 = 9999");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Update
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceBulkRowInsertRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ ArrayList list = new ArrayList();
+ public void testCase() throws Exception {
+ for (int i = 100; i < 120; i++) {
+ list.add("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values("+i+",'"+i+"',"+i+",'"+i+"')");
+ }
+ list.add("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where
pm1.g1.e1 >= 100");
+
+ // force the rollback by trying to insert an invalid row.
+ list.add("insert into pm1.g2 (e1, e2)
values(9999,'9999')");
+
+ executeBatch((String[])list.toArray(new String[list.size()]));
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(0);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 100 and e1 < 120");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+}
Property changes on:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/PessimisticWrapTransactionTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain