|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.derbyTesting.functionTests.tests.jdbcapi.SetQueryTimeoutTest
public class SetQueryTimeoutTest
Functional test for the Statement.setQueryTimeout() method. This test consists of four parts: 1. Executes a SELECT query in 4 different threads concurrently. The query calls a user-defined, server-side function which delays the execution, so that it takes several seconds even though the data volume is really low. The fetch operations take longer time than the timeout value set. Hence, this part tests getting timeouts from calls to ResultSet.next(). Two connections are used, two threads execute their statement in the context of one connection, the other two threads in the context of the other connection. Of the 4 threads, only one executes its statement with a timeout value. This way, the test ensures that the correct statement is affected by setQueryTimeout(), regardless of what connection/transaction it and other statements are executed in the context of. 2. Executes an INSERT query in multiple threads. This part tests getting timeouts from calls to Statement.execute(). Each thread executes the query in the context of a separate connection. There is no point in executing multiple statements on the same connection; since only one statement per connection executes at a time, there will be no interleaving of execution between them (contrary to the first part of this test, where calls to ResultSet.next() may be interleaved between the different threads). Half of the threads execute their statement with a timeout value set, this is to verify that the correct statements are affected by the timeout, while the other statements execute to completion. 3. Sets an invalid (negative) timeout. Verifies that the correct exception is thrown. 4. Tests that the query timeout value is not forgotten after the execution of a statement (DERBY-1692).
| Nested Class Summary | |
|---|---|
private static class |
SetQueryTimeoutTest.StatementExecutor
|
private static class |
SetQueryTimeoutTest.TestFailedException
This Exception class is used for getting fail-fast behaviour in this test. |
| Field Summary | |
|---|---|
private static int |
CONNECTIONS
|
private static int |
TIMEOUT
|
| Constructor Summary | |
|---|---|
SetQueryTimeoutTest()
|
|
| Method Summary | |
|---|---|
static int |
delay(int seconds,
int value)
This is the user-defined function which is called from our queries |
private static void |
dropTables(java.sql.Connection conn,
java.lang.String tablePrefix)
|
private static void |
exec(java.sql.Connection connection,
java.lang.String queryString)
|
private static void |
exec(java.sql.Connection connection,
java.lang.String queryString,
java.util.Collection ignoreExceptions)
Used for executing the SQL statements for setting up this test (the preparation phase). |
private static void |
expectException(java.lang.String expectSqlState,
java.sql.SQLException sqlException,
java.lang.String failMsg)
This method compares a thrown SQLException's SQLState value to an expected SQLState. |
private static java.lang.String |
getExecQuery(java.lang.String tablePrefix)
|
private static java.lang.String |
getFetchQuery(java.lang.String tablePrefix)
|
void |
go(java.lang.String[] args)
The actual main bulk of this test. |
static void |
main(java.lang.String[] args)
Main program, makes this class invocable from the command line |
private static java.sql.PreparedStatement |
prepare(java.sql.Connection conn,
java.lang.String query)
|
private static void |
prepareForTimedQueries(java.sql.Connection conn)
|
private static void |
prepareTables(java.sql.Connection conn,
java.lang.String tablePrefix)
|
private static void |
printSQLException(java.sql.SQLException e)
|
private static void |
testInvalidTimeoutValue(java.sql.Connection conn)
|
private static void |
testRememberTimeoutValue(java.sql.Connection conn)
Test for DERBY-1692. |
private static void |
testStatementRemembersTimeout(java.sql.PreparedStatement ps)
Test that a prepared statement remembers its timeout value when executed multiple times. |
private static void |
testStatementRemembersTimeout(java.sql.Statement stmt)
Test that a statement remembers its timeout value when executed multiple times. |
private static void |
testTimeoutWithExec(java.sql.Connection[] connections)
Part two of this test. |
private static void |
testTimeoutWithExecuteUpdate(java.sql.Connection conn)
This tests timeout with executeUpdate call. |
private static void |
testTimeoutWithFetch(java.sql.Connection conn1,
java.sql.Connection conn2)
Part 1 of this test. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final int TIMEOUT
private static final int CONNECTIONS
| Constructor Detail |
|---|
public SetQueryTimeoutTest()
| Method Detail |
|---|
private static void printSQLException(java.sql.SQLException e)
private static void exec(java.sql.Connection connection,
java.lang.String queryString,
java.util.Collection ignoreExceptions)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void exec(java.sql.Connection connection,
java.lang.String queryString)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void dropTables(java.sql.Connection conn,
java.lang.String tablePrefix)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void prepareTables(java.sql.Connection conn,
java.lang.String tablePrefix)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
public static int delay(int seconds,
int value)
throws java.sql.SQLException
java.sql.SQLException
private static void prepareForTimedQueries(java.sql.Connection conn)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedExceptionprivate static java.lang.String getFetchQuery(java.lang.String tablePrefix)
private static java.lang.String getExecQuery(java.lang.String tablePrefix)
private static void expectException(java.lang.String expectSqlState,
java.sql.SQLException sqlException,
java.lang.String failMsg)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static java.sql.PreparedStatement prepare(java.sql.Connection conn,
java.lang.String query)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void testTimeoutWithFetch(java.sql.Connection conn1,
java.sql.Connection conn2)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void testTimeoutWithExec(java.sql.Connection[] connections)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void testInvalidTimeoutValue(java.sql.Connection conn)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void testTimeoutWithExecuteUpdate(java.sql.Connection conn)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void testRememberTimeoutValue(java.sql.Connection conn)
throws SetQueryTimeoutTest.TestFailedException
SetQueryTimeoutTest.TestFailedException
private static void testStatementRemembersTimeout(java.sql.Statement stmt)
throws java.sql.SQLException,
SetQueryTimeoutTest.TestFailedException
java.sql.SQLException
SetQueryTimeoutTest.TestFailedException
private static void testStatementRemembersTimeout(java.sql.PreparedStatement ps)
throws java.sql.SQLException,
SetQueryTimeoutTest.TestFailedException
java.sql.SQLException
SetQueryTimeoutTest.TestFailedExceptionpublic static void main(java.lang.String[] args)
public void go(java.lang.String[] args)
|
Built on Sat 2009-11-28 18:44:18-0800, from revision 885187 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||