Search in sources :

Example 21 with AbstractQueryTransactionTest

use of org.teiid.test.framework.query.AbstractQueryTransactionTest in project teiid by teiid.

the class CommonTransactionTests method testMultipleSourceMultipleCommandsCancel.

/**
 * Sources = 2
 * Commands = multiple - Success
 * Batching = Full Processing, Single Connector Batch
 * result = rollback
 */
@Test
public void testMultipleSourceMultipleCommandsCancel() throws Exception {
    AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceMultipleCommandsCancel") {

        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());
        }

        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);
}
Also used : AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) SQLException(java.sql.SQLException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) QueryExecution(org.teiid.test.framework.query.QueryExecution) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) Test(org.junit.Test)

Example 22 with AbstractQueryTransactionTest

use of org.teiid.test.framework.query.AbstractQueryTransactionTest in project teiid by teiid.

the class CommonTransactionTests method testSingleSourcePreparedUpdate.

/**
 * Sources = 1
 * Commands = 1, Update(prepared statement)
 * Batching = Full Processing, Single Connector Batch
 * result = commit
 */
@Test
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);
}
Also used : AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) QueryExecution(org.teiid.test.framework.query.QueryExecution) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) Test(org.junit.Test)

Example 23 with AbstractQueryTransactionTest

use of org.teiid.test.framework.query.AbstractQueryTransactionTest in project teiid by teiid.

the class CommonTransactionTests method testMultipleSourceSelect.

// /////////////////////////////////////////////////////////////////////////////////////////////
// Multiple Sources     - Rows from 500
// /////////////////////////////////////////////////////////////////////////////////////////////
/**
 * Sources = 2
 * Commands = 1, Select
 * Batching = Full Processing, Single Connector Batch
 * result = commit
 */
@Test
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);
        }
    };
    // run test
    getTransactionContainter().runTransaction(userTxn);
}
Also used : AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) Test(org.junit.Test)

Example 24 with AbstractQueryTransactionTest

use of org.teiid.test.framework.query.AbstractQueryTransactionTest in project teiid by teiid.

the class CommonTransactionTests method testMultipleSourceMultipleCommands.

/**
 * Sources = 2
 * Commands = multiple - Success
 * Batching = Full Processing, Single Connector Batch
 * result = commit
 */
@Test
public void testMultipleSourceMultipleCommands() throws Exception {
    AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceMultipleCommands") {

        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
    if (userTxn.getSource("pm1").getMetaData().getDatabaseProductName().toLowerCase().indexOf("oracle") > -1) {
        test.assertResultsSetEquals(new String[] { "e2[varchar2]", "blah" });
    } else {
        test.assertResultsSetEquals(new String[] { "e2[varchar]", "blah" });
    }
}
Also used : AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) QueryExecution(org.teiid.test.framework.query.QueryExecution) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) Test(org.junit.Test)

Example 25 with AbstractQueryTransactionTest

use of org.teiid.test.framework.query.AbstractQueryTransactionTest in project teiid by teiid.

the class CommonTransactionTests method testSingleSourceSelect.

// 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
 */
@Test
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);
// there is nothing to verify here..
}
Also used : AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) AbstractQueryTransactionTest(org.teiid.test.framework.query.AbstractQueryTransactionTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 AbstractQueryTest (org.teiid.jdbc.AbstractQueryTest)37 AbstractQueryTransactionTest (org.teiid.test.framework.query.AbstractQueryTransactionTest)37 QueryExecution (org.teiid.test.framework.query.QueryExecution)29 ArrayList (java.util.ArrayList)5 SQLException (java.sql.SQLException)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2 TimeoutException (java.util.concurrent.TimeoutException)1