Search in sources :

Example 1 with BaseJDBCTestSetup

use of org.apache.derbyTesting.junit.BaseJDBCTestSetup in project derby by apache.

the class StatementPoolingTest method suite.

public static Test suite() {
    BaseTestSuite suite = new BaseTestSuite("StatementPoolingTest suite");
    BaseTestSuite baseSuite = new BaseTestSuite(StatementPoolingTest.class);
    // Statement pooling is not yet enabled for XA.
    // suite.addTest(TestConfiguration.connectionXADecorator(baseSuite));
    suite.addTest(TestConfiguration.connectionCPDecorator(baseSuite));
    // Add tests that require data from the database.
    BaseTestSuite reqDataSuite = new BaseTestSuite("Requires data suite");
    reqDataSuite.addTest(new StatementPoolingTest("resTestCloseDoesNotAffectOtherStatement"));
    reqDataSuite.addTest(new StatementPoolingTest("resTestLogicalConnectionCloseInvalidatesLogicalStatement"));
    reqDataSuite.addTest(new StatementPoolingTest("resTestHoldCursorsOverCommit"));
    reqDataSuite.addTest(new StatementPoolingTest("resTestCloseCursorsAtCommit"));
    reqDataSuite.addTest(new StatementPoolingTest("resTestNoCommitOnReuse"));
    reqDataSuite.addTest(new StatementPoolingTest("resTestCommitOnReuse"));
    reqDataSuite.addTest(new StatementPoolingTest("resTestNoDataCommittedOnInvalidTransactionState"));
    suite.addTest(TestConfiguration.connectionCPDecorator(new BaseJDBCTestSetup(reqDataSuite) {

        public void setUp() throws Exception {
            // Generate some data we can use in the tests.
            Statement stmt = getConnection().createStatement();
            try {
                stmt.executeUpdate("drop table stmtpooltest");
            } catch (SQLException sqle) {
                assertSQLState("42Y55", sqle);
            }
            stmt.executeUpdate("create table stmtpooltest (" + "id int generated always as identity," + "val int)");
            PreparedStatement ps = getConnection().prepareStatement("insert into stmtpooltest values (DEFAULT, ?)");
            // Insert data with val in range [1,7].
            for (int val = 1; val <= 7; val++) {
                ps.setInt(1, val);
                ps.addBatch();
            }
            ps.executeBatch();
            try {
                stmt.executeUpdate("drop table stmtpooldata");
            } catch (SQLException sqle) {
                assertSQLState("42Y55", sqle);
            }
            stmt.executeUpdate("create table stmtpooldata (" + "id int generated always as identity," + "val int)");
        // Leave this table empty.
        }
    }));
    return TestConfiguration.clientServerDecorator(suite);
}
Also used : BaseJDBCTestSetup(org.apache.derbyTesting.junit.BaseJDBCTestSetup) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) PreparedStatement(java.sql.PreparedStatement)

Example 2 with BaseJDBCTestSetup

use of org.apache.derbyTesting.junit.BaseJDBCTestSetup in project derby by apache.

the class SpillHashTest method suite.

/**
 * Returns the implemented tests.
 *
 * @return An instance of <code>Test</code> with the implemented tests to
 *         run.
 */
public static Test suite() {
    // suite of tests with light load on the tables
    BaseTestSuite light = new BaseTestSuite();
    // suite of tests with heavy load on the tables
    BaseTestSuite heavy = new BaseTestSuite();
    light.addTest(new SpillHashTest("testJoinLight"));
    light.addTest(new SpillHashTest("testDistinctLight"));
    light.addTest(new SpillHashTest("testCursorLight"));
    heavy.addTest(new SpillHashTest("testJoinHeavy"));
    heavy.addTest(new SpillHashTest("testDistinctHeavy"));
    heavy.addTest(new SpillHashTest("testCursorHeavy"));
    Test lightSetup = new BaseJDBCTestSetup(light) {

        protected void setUp() throws Exception {
            super.setUp();
            Statement stmt = getConnection().createStatement();
            PreparedStatement insA = stmt.getConnection().prepareStatement("insert into ta(ca1,ca2) values(?,?)");
            PreparedStatement insB = stmt.getConnection().prepareStatement("insert into tb(cb1,cb2) values(?,?)");
            insertDups(insA, insB, initDupVals);
            getConnection().commit();
            stmt.close();
        // System.out.println("2");
        }
    };
    Test heavySetup = new BaseJDBCTestSetup(heavy) {

        protected void setUp() throws Exception {
            super.setUp();
            Statement stmt = getConnection().createStatement();
            PreparedStatement insA = stmt.getConnection().prepareStatement("insert into ta(ca1,ca2) values(?,?)");
            PreparedStatement insB = stmt.getConnection().prepareStatement("insert into tb(cb1,cb2) values(?,?)");
            for (int i = 1; i <= LOTS_OF_ROWS; i++) {
                insA.setInt(1, i);
                insA.setString(2, ca2Val(i));
                insA.executeUpdate();
                insB.setInt(1, i);
                insB.setString(2, cb2Val(i));
                insB.executeUpdate();
                if ((i & 0xff) == 0)
                    stmt.getConnection().commit();
            }
            insertDups(insA, insB, spillDupVals);
            getConnection().commit();
            stmt.close();
        // System.out.println("3");
        }
    };
    BaseTestSuite mainSuite = new BaseTestSuite();
    mainSuite.addTest(lightSetup);
    mainSuite.addTest(heavySetup);
    return new CleanDatabaseTestSetup(mainSuite) {

        protected void decorateSQL(Statement stmt) throws SQLException {
            for (int i = 0; i < prep.length; i++) {
                stmt.executeUpdate(prep[i]);
            }
        // System.out.println("1");
        }
    };
}
Also used : BaseJDBCTestSetup(org.apache.derbyTesting.junit.BaseJDBCTestSetup) Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) PreparedStatement(java.sql.PreparedStatement)

Example 3 with BaseJDBCTestSetup

use of org.apache.derbyTesting.junit.BaseJDBCTestSetup in project derby by apache.

the class TimestampArithTest method suite.

public static Test suite() {
    return new BaseJDBCTestSetup(new BaseTestSuite(TimestampArithTest.class, "TimestampArithTest")) {

        protected void setUp() throws Exception {
            super.setUp();
            for (int i = 0; i < intervalJdbcNames.length; i++) {
                tsAddPS[i] = getConnection().prepareStatement(composeSqlStr("ADD", i, "?", "?"));
                tsDiffPS[i] = getConnection().prepareStatement(composeSqlStr("DIFF", i, "?", "?"));
            }
            stmt = getConnection().createStatement();
        }

        protected void tearDown() throws Exception {
            closeAll(tsAddPS);
            tsAddPS = null;
            closeAll(tsDiffPS);
            tsDiffPS = null;
            stmt.close();
            stmt = null;
            super.tearDown();
        }
    };
}
Also used : BaseJDBCTestSetup(org.apache.derbyTesting.junit.BaseJDBCTestSetup) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite)

Example 4 with BaseJDBCTestSetup

use of org.apache.derbyTesting.junit.BaseJDBCTestSetup in project derby by apache.

the class ResultSetTest method decorateTestSuite.

private static Test decorateTestSuite(Test rsSuite) {
    // Wrap suite in a TestSetup-class.
    return new BaseJDBCTestSetup(rsSuite) {

        protected void setUp() throws SQLException {
            Connection con = getConnection();
            Statement stmt = con.createStatement();
            stmt.execute("create table UpdateTestTableResultSet (" + "sno int not null unique," + "dBlob BLOB," + "dClob CLOB," + "dLongVarchar LONG VARCHAR," + "dLongBit LONG VARCHAR FOR BIT DATA)");
            stmt.close();
        }

        protected void tearDown() throws Exception {
            Connection con = getConnection();
            Statement stmt = con.createStatement();
            stmt.execute("drop table UpdateTestTableResultSet");
            stmt.close();
            super.tearDown();
        }
    };
}
Also used : BaseJDBCTestSetup(org.apache.derbyTesting.junit.BaseJDBCTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection)

Example 5 with BaseJDBCTestSetup

use of org.apache.derbyTesting.junit.BaseJDBCTestSetup in project derby by apache.

the class JDBCDriverTest method suite.

/**
 * Returns a suite with all the available JDBC client driver compatibility
 * tests.
 * <p>
 * JUnit boilerplate which adds as test cases all public methods
 * whose names start with the string "test" in the named classes.
 */
public static Test suite() {
    BaseTestSuite testSuite = new BaseTestSuite("JDBCDriverTest suite");
    testSuite.addTestSuite(JDBCDriverTest.class);
    return TestConfiguration.defaultExistingServerDecorator(new BaseJDBCTestSetup(testSuite) {

        protected void setUp() throws Exception {
            super.setUp();
            Connection con = getConnection();
            Statement s = con.createStatement();
            // We can't use Connection.getSchema yet.
            ResultSet rs = s.executeQuery("values CURRENT SCHEMA");
            rs.next();
            String schema = rs.getString(1);
            rs.close();
            s.close();
            con.setAutoCommit(false);
            // Drop the current schema to clean up. Hopefully this
            // is enough to start "reset" the database for each
            // client run (running the newest CleanDatabaseTestSetup
            // fails on older versions).
            JDBC.dropSchema(con.getMetaData(), schema);
            con.commit();
            // Initialize the database for the tests.
            con.setAutoCommit(true);
            createTable(con, ALL_TYPES_TABLE, ALL_TYPES);
            createUDTObjects(con);
            create_derby_2602_objects(con);
        }
    });
}
Also used : BaseJDBCTestSetup(org.apache.derbyTesting.junit.BaseJDBCTestSetup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SQLException(java.sql.SQLException)

Aggregations

BaseJDBCTestSetup (org.apache.derbyTesting.junit.BaseJDBCTestSetup)5 PreparedStatement (java.sql.PreparedStatement)4 Statement (java.sql.Statement)4 BaseTestSuite (org.apache.derbyTesting.junit.BaseTestSuite)4 CallableStatement (java.sql.CallableStatement)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ResultSet (java.sql.ResultSet)1 Test (junit.framework.Test)1 CleanDatabaseTestSetup (org.apache.derbyTesting.junit.CleanDatabaseTestSetup)1