Author: vhalbert(a)redhat.com
Date: 2009-11-19 13:58:25 -0500 (Thu, 19 Nov 2009)
New Revision: 1574
Added:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/CommonTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/LocalTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticWrapTransactionTests.java
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/PessimisticWrapTransactionTests.java
Log:
Teiid 773 - refactored back in the way jbedsp transaction classes where defined and added
the other integration test
Added:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/CommonTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/CommonTransactionTests.java
(rev 0)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/CommonTransactionTests.java 2009-11-19
18:58:25 UTC (rev 1574)
@@ -0,0 +1,599 @@
+/*
+ * Copyright (c) 2000-2007 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.test.testcases;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+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.OnWrapTransaction;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+/**
+ * A common test case among many different transaction stuff.
+ */
+public abstract class CommonTransactionTests extends BaseAbstractTransactionTestCase {
+
+ public CommonTransactionTests(String name) {
+ super(name);
+ }
+
+ protected abstract TransactionContainer getTransactionContainter();
+
+// void runConcurrentTestCases(int howMany, final String[] sqls) {
+//
+// SeparateClient[] clients = new SeparateClient[howMany];
+//
+// for(int i = 0; i < howMany; i++) {
+// AbstractQueryTransactionTest testCase = new AbstractQueryTransactionTest()
{
+// public void testCase() throws Exception {
+// execute(sqls);
+// }
+// };
+// clients[i] = new SeparateClient(getTransactionContainter(), testCase);
+// }
+//
+// for(int i = 0; i < howMany; i++) {
+// clients[i].start();
+// }
+//
+// try {
+// for(int i = 0; i < howMany; i++) {
+// clients[i].join();
+// }
+// } catch (InterruptedException e) {
+// // boo
+// }
+// }
+
+// static class SeparateClient extends Thread{
+// TransactionContainer container = null;
+// AbstractTransactionTestCase testCase = null;
+//
+// public SeparateClient(TransactionContainer container,
AbstractTransactionTestCase testCase) {
+// this.container = container;
+// this.testCase = testCase;
+// }
+//
+// public void run() {
+// this.container.runTransaction(this.testCase);
+// }
+// }
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
+ // 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() {
+ public void testCase() throws Exception {
+ execute("select * from pm1.g1 where pm1.g1.e1 < 100");
+ assertRowCount(100);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // there is nothing to verify here..
+ }
+
+
+ /**
+ * Sources = 1
+ * Commands = 1, Update
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourceUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("insert into pm1.g1 (e1, e2) values(100,
'100')");
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 = 100");
+ test.assertRowCount(1);
+ test.closeConnection();
+ }
+
+
+ /**
+ * Sources = 1
+ * Commands = 1, Update(prepared statement)
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourcePreparedUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ 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() {
+ public void testCase() throws Exception {
+
+ 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 < 110; 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");
+ test.assertRowCount(10);
+ test.execute("select * from g2 where e1 >= 100");
+ test.assertRowCount(10);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = 1, Select
+ * Batching = Partial Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testSingleSourcePartialProcessing() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("select * from pm1.g1 where pm1.g1.e1 < 100 limit
10");
+ assertRowCount(10);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
+ // 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() {
+ 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);
+ }
+ };
+
+ // run test
+ 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() {
+ public void testCase() throws Exception {
+ execute("select * from vm.g1 where vm.g1.pm1e1 < 100");
+ assertRowCount(100);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Update
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(500,
'500', 500, '500')");
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e2 = '500'");
+ test.assertRowCount(1);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e2 = '500'");
+ test.assertRowCount(1);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Update
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceSelectInto() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(501,
'501', 501, '501')");
+ execute("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where
pm1.g1.e1 = 501");
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e2 = '501'");
+ test.assertRowCount(1);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e2 = '501'");
+ test.assertRowCount(1);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Update
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceBulkRowInsert() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ for (int i = 100; i < 112; i++) {
+ Integer val = new Integer(i);
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
+ }
+ execute("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where
pm1.g1.e1 >= 100");
+ }
+ };
+
+ // 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 < 112");
+ test.assertRowCount(12);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 112");
+ test.assertRowCount(12);
+ test.execute("select * from g2 where e1 >= 100 and e1 < 112");
+ test.assertRowCount(12);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Update(prepared statement)
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourcePreparedUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ 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()});
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 = 500");
+ test.assertRowCount(1);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 = 500");
+ test.assertRowCount(1);
+ test.closeConnection();
+ }
+
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceMultipleCommands() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("delete from pm1.g2 where e1 >= ?", new Object[]
{new Integer(100)});
+ execute("delete from pm1.g1 where e1 >= ?", new Object[]
{new Integer(100)});
+ execute("delete from pm2.g2 where e1 >= ?", new Object[]
{new Integer(100)});
+ execute("delete from pm2.g1 where e1 >= ?", new Object[]
{new Integer(100)});
+
+ execute("select * from pm1.g1");
+ assertRowCount(100);
+
+ for (int i = 100; i < 115; 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()});
+
+ execute("insert into pm2.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ execute("insert into pm2.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ }
+
+ execute("update pm1.g1 set e2='blah' where e1 >
100");
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"))
{
+ protected boolean compareCaseSensitive() {
+ return false;
+ }
+ };
+ test.execute("select * from g1 where e1 >= 100 and e1 < 115");
+ test.assertRowCount(15);
+ test.execute("select * from g2 where e1 >= 100 and e1 < 115");
+ test.assertRowCount(15);
+ test.execute("select distinct e2 from g1 where e1 > 100");
+
+ // NOTE: if this is an oracle source, it failes because it return varchar2
+ test.assertResultsSetEquals(new String[] {"e2[varchar]",
"blah"});
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceMultipleVirtualCommands() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+
+ for (int i = 200; i < 207; i++) {
+ Integer val = new Integer(i);
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
+ execute("insert into vm.g2 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
+ }
+
+ execute("update vm.g1 set pm1e2='blah' where pm1e1 >=
200");
+
+ execute("delete from vm.g2 where vm.g2.pm1e1 >= 205");
+ execute("delete from vm.g1 where vm.g1.pm1e1 >= 205");
+
+ execute("select * from vm.g1 where pm1e1 >= 200 and pm1e1 <
207");
+ assertRowCount(5);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1")){
+ protected boolean compareCaseSensitive() {
+ return false;
+ }
+ };
+ test.execute("select * from g1 where e1 >= 200 and e1 < 207");
+ test.assertRowCount(5);
+ test.execute("select * from g2 where e1 >= 200 and e1 < 207");
+ test.assertRowCount(5);
+ test.execute("select distinct e2 from g1 where e1 >= 200 and e1 <
207");
+ test.assertResultsSetEquals(new String[] {"e2[varchar2]",
"blah"});
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testMultipleSourceMultipleCommandsCancel() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+
+ public void testCase() throws Exception {
+ Thread t = new Thread("Cancel Thread") {
+ public void run() {
+ try {
+ try {
+ Thread.sleep(500);
+ cancelQuery();
+ } catch (SQLException e) {
+ // debug(e.getMessage());
+ }
+ } catch (InterruptedException e) {}
+ }
+ };
+ t.start();
+ executeBatch(getMultipleSourceBatch());
+ }
+
+ /**
+ * @see
com.metamatrix.transaction.test.framework.AbstractQueryTest#exceptionExpected()
+ */
+ public boolean exceptionExpected() {
+ return true;
+ }
+ };
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results (this may finish under one second, then this test is
not valid)
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 600 and e1 < 650");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 600 and e1 < 650");
+ test.assertRowCount(0);
+ test.execute("select distinct e2 from g1 where e1 >= 600 and e1 <
650");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testMultipleSourceTimeout() throws Exception{
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ executeBatch(getMultipleSourceBatch(), 1); // time out after 1 sec
+ }
+
+ public boolean exceptionExpected() {
+ return true;
+ }
+
+ public void after() {
+ if (!exceptionOccurred()) {
+ fail("should have failed with time out exception");
+ }
+ else {
+ assertTrue(getLastException().getMessage().indexOf("Operation
timed out before completion") != -1);
+ }
+ }
+ };
+ getTransactionContainter().runTransaction(userTxn);
+
+ // now verify the results (this may finish under one second, then this test is
not valid)
+ AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
+ test.execute("select * from g1 where e1 >= 600 and e1 < 750");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 600 and e1 < 750");
+ test.assertRowCount(0);
+ test.execute("select distinct e2 from g1 where e1 >= 600 and e1 <
750");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+
+ static String[] getMultipleSourceBatch() {
+ ArrayList list = new ArrayList();
+
+ for (int i = 600; i < 750; 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 pm2.g1 (e1, e2)
values("+i+",'"+i+"')");
+ list.add("insert into pm2.g2 (e1, e2) values
("+i+",'"+i+"')");
+ }
+
+ list.add("update pm1.g1 set e2='blah' where pm1.g1.e1 >=
600");
+ list.add("update pm2.g1 set e2='blah' where pm2.g1.e1 >=
600");
+
+ list.add("delete from pm1.g2 where pm1.g2.e1 >= 610");
+ list.add("delete from pm1.g1 where pm1.g1.e1 >= 610");
+ list.add("delete from pm2.g2 where pm2.g2.e1 >= 610");
+ list.add("delete from pm2.g1 where pm2.g1.e1 >= 610");
+
+ return(String[])list.toArray(new String[list.size()]);
+ }
+
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Partial Processing, Single Connector Batch
+ * result = commit
+ * Note: This is producing the below error some times; however this is SQL Server
issue.
+ *
http://support.microsoft.com/?kbid=834849
+ */
+ public void testMultipleSourcePartialProcessingUsingLimit() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("select * from vm.g1 where pm1e1 < 100 limit 10");
+ assertRowCount(10);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ /**
+ * Sources = 2
+ * Commands = 1, Select
+ * Batching = Partial Processing, Single Connector Batch
+ * result = commit
+ * Note: This is producing the below error some times; however this is SQL Server
issue.
+ *
http://support.microsoft.com/?kbid=834849
+ */
+ public void testMultipleSourcePartialProcessingUsingMakedep() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ execute("select pm1.g1.e1, pm1.g1.e2 from pm1.g1 LEFT OUTER JOIN
pm2.g1 MAKENOTDEP ON pm1.g1.e2 = pm2.g1.e2 where pm2.g1.e1 >= 50 and pm2.g1.e1 <
100");
+ assertRowCount(50);
+ }
+ };
+
+ // run test
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+
+
+
+}
Property changes on:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/CommonTransactionTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/LocalTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/LocalTransactionTests.java
(rev 0)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/LocalTransactionTests.java 2009-11-19
18:58:25 UTC (rev 1574)
@@ -0,0 +1,273 @@
+/*
+ * Copyright (c) 2000-2007 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.test.testcases;
+
+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.LocalTransaction;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+
+
+/**
+ * User Transaction Test is where user handles all the transaction boundaries
+ * so, autocmmit = OFF, and No transaction auto wrapping.
+ */
+public class LocalTransactionTests extends CommonTransactionTests {
+
+
+ public LocalTransactionTests(String testName) {
+ super(testName);
+ }
+
+
+ @Override
+ protected TransactionContainer getTransactionContainter() {
+ // TODO Auto-generated method stub
+ return new LocalTransaction();
+ }
+
+ /**
+ * Sources = 1
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testSingleSourceMultipleCommandsExplicitRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+ for (int i = 200; i < 220; i++) {
+ execute("insert into pm1.g1 (e1, e2)
values("+i+",'"+i+"')");
+ execute("insert into pm1.g2 (e1, e2)
values("+i+",'"+i+"')");
+ }
+ }
+
+ public boolean rollbackAllways() {
+ 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 < 220");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 200 and e1 < 220");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * 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 < 220; 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()});
+ }
+
+ // force the rollback by trying to insert an invalid row.
+ 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 < 220");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testMultipleSourceMultipleCommandsExplicitRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+
+ for (int i = 700; i < 720; 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()});
+
+ execute("insert into pm2.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ execute("insert into pm2.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ }
+ }
+
+ // force the rollback
+ public boolean rollbackAllways() {
+ 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 >= 700 and e1 < 720");
+ test.assertRowCount(0);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 >= 700 and e1 < 720");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = rollback
+ */
+ public void testMultipleSourceMultipleCommandsReferentialIntegrityRollback() throws
Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+
+ for (int i = 700; i < 720; 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()});
+
+ execute("insert into pm2.g1 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ execute("insert into pm2.g2 (e1, e2) values(?,?)", new
Object[] {val, val.toString()});
+ }
+
+ // force the rollback by trying to insert an invalid row.
+ 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 >= 700 and e1 < 720");
+ test.assertRowCount(0);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 >= 700 and e1 < 720");
+ 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() {
+ public void testCase() throws Exception {
+ for (int i = 100; i < 120; i++) {
+ Integer val = new Integer(i);
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
+ }
+ execute("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.
+ 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 >= 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();
+ }
+
+ /**
+ * Sources = 2
+ * Commands = multiple - Success
+ * Batching = Full Processing, Single Connector Batch
+ * result = commit
+ */
+ public void testMultipleSourceMultipleVirtualCommandsRollback() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ public void testCase() throws Exception {
+
+ for (int i = 600; i < 615; i++) {
+ Integer val = new Integer(i);
+ execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
+ execute("insert into vm.g2 (pm1e1, pm1e2, pm2e1, pm2e2)
values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
+ }
+
+ execute("update vm.g1 set pm1e2='blah' where pm1e1 >=
605");
+
+ execute("delete from vm.g2 where vm.g2.pm1e1 >= 610");
+ execute("delete from vm.g1 where vm.g1.pm1e1 >= 610");
+
+ execute("select * from vm.g1 where pm1e1 >= 600 and pm1e1 <
615");
+ assertRowCount(10);
+
+ // force the rollback by trying to insert an invalid row.
+ 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 >= 600 and e1 < 615");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 600 and e1 < 615");
+ test.assertRowCount(0);
+ test.execute("select distinct e2 from g1 where e1 >= 600 and e1 <
615");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+}
Property changes on:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/LocalTransactionTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java 2009-11-19
18:58:25 UTC (rev 1574)
@@ -0,0 +1,147 @@
+/*
+ * 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.query.AbstractQueryTransactionTest;
+import org.teiid.test.framework.query.QueryExecution;
+import org.teiid.test.framework.transaction.OnWrapTransaction;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+
+
+public class OnWrapTransactionTests extends CommonTransactionTests {
+
+ public OnWrapTransactionTests(String testName) {
+ super(testName);
+ }
+
+
+ @Override
+ protected TransactionContainer getTransactionContainter() {
+ // TODO Auto-generated method stub
+ return new OnWrapTransaction();
+ }
+
+ /**
+ * 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 autocommit=on 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 < 110; 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 < 110");
+ test.assertRowCount(0);
+ test.closeConnection();
+
+ test = new QueryExecution(userTxn.getSource("pm2"));
+ test.execute("select * from g1 where e1 >= 100 and e1 < 110");
+ test.assertRowCount(0);
+ test.execute("select * from g2 where e1 >= 100 and e1 < 110");
+ test.assertRowCount(0);
+ test.closeConnection();
+ }
+}
Property changes on:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OnWrapTransactionTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticWrapTransactionTests.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticWrapTransactionTests.java
(rev 0)
+++
trunk/test-integration/db/src/test/java/org/teiid/test/testcases/OptimisticWrapTransactionTests.java 2009-11-19
18:58:25 UTC (rev 1574)
@@ -0,0 +1,491 @@
+/*
+ * 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.query.AbstractQueryTransactionTest;
+import org.teiid.test.framework.query.QueryExecution;
+import org.teiid.test.framework.transaction.OptimisticWrapTransaction;
+
+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 OptimisticWrapTransactionTests extends BaseAbstractTransactionTestCase {
+
+ public OptimisticWrapTransactionTests(String testName) {
+ super(testName);
+ }
+
+ protected TransactionContainer getTransactionContainter() {
+ return new OptimisticWrapTransaction();
+ }
+
+
///////////////////////////////////////////////////////////////////////////////////////////////
+ // 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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() {
+ 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 {
+ 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() {
+ 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 {
+ 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() {
+ 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() {
+ public void testCase() throws Exception {
+ execute("select * from vm.p1");
+ }
+
+ 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() {
+ 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 {
+ assertTrue(getLastException().getMessage(),
getLastException().getMessage().indexOf("txnAutoWrap=OPTIMISTIC") != -1);
+ }
+ }
+ };
+
+ getTransactionContainter().runTransaction(userTxn);
+ }
+
+ public void testMultipleSourceVirtualProceduralSelectWithUpdate() throws Exception {
+ AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest() {
+ 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 {
+ 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() {
+ 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 {
+ 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/OptimisticWrapTransactionTests.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-11-19
18:58:25 UTC (rev 1574)
@@ -0,0 +1,141 @@
+/*
+ * 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.query.AbstractQueryTransactionTest;
+import org.teiid.test.framework.query.QueryExecution;
+import org.teiid.test.framework.transaction.PessimisticWrapTransaction;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+public class PessimisticWrapTransactionTests extends CommonTransactionTests {
+
+ public PessimisticWrapTransactionTests(String testName) {
+ super(testName);
+ }
+
+ protected TransactionContainer getTransactionContainter() {
+ return new PessimisticWrapTransaction();
+ }
+
+ /**
+ * 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