Search in sources :

Example 16 with QueryExecution

use of org.teiid.test.framework.query.QueryExecution 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 17 with QueryExecution

use of org.teiid.test.framework.query.QueryExecution 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 18 with QueryExecution

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

the class CommonTransactionTests method testSingleSourceMultipleCommands.

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

        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);
}
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 19 with QueryExecution

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

the class CommonTransactionTests method testMultipleSourceUpdate.

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

        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);
}
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 20 with QueryExecution

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

the class LocalTransactionTests method testMultipleSourceMultipleCommandsExplicitRollback.

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

        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 = new QueryExecution(userTxn.getSource("pm2"));
    test.execute("select * from g1 where e1 >= 700 and e1 < 720");
    test.assertRowCount(0);
}
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)

Aggregations

Test (org.junit.Test)29 AbstractQueryTest (org.teiid.jdbc.AbstractQueryTest)29 AbstractQueryTransactionTest (org.teiid.test.framework.query.AbstractQueryTransactionTest)29 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