org.apache.derbyTesting.functionTests.tests.jdbcapi
Class StatementPoolingTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.StatementPoolingTest
All Implemented Interfaces:
junit.framework.Test

public class StatementPoolingTest
extends BaseJDBCTestCase

A set of tests specifically targeted at connections that support statement pooling.


Field Summary
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
StatementPoolingTest(java.lang.String name)
           
 
Method Summary
private static void assertClassName(java.lang.Object obj, java.lang.String expectedName)
          Assert that the name of the class of the object is what is expected.
private  void cleanTableExceptedToBeEmpty()
          Deletes row from a test table that is expected to be empty.
private  void doTestGetStatement(java.sql.PreparedStatement ps)
          Make sure ResultSet.getStatement() returns the same object as the one that created the result set.
private  void doTestHoldabilityIsReset(boolean closeConnection)
          Test sequence for testing if the connection holdability is reset.
private  void doTestIsolationLevelIsReset(boolean closeConnection, boolean executeQuery)
          Tests if the connection isolation level is reset when a new connection is obtained.
private  void doTestResultSetCloseForHoldability(int holdability)
          Tests if the holdability settings is taking effect, and also that the result set is closed when the connection is closed.
 void resTestCloseCursorsAtCommit()
           
 void resTestCloseDoesNotAffectOtherStatement()
          Checks if a reset of one statement affects other open statement on the connection.
 void resTestCommitOnReuse()
          Tests that autocommit is working.
 void resTestHoldCursorsOverCommit()
           
 void resTestLogicalConnectionCloseInvalidatesLogicalStatement()
          Checks if closing the logical connection closes the logical statement.
 void resTestNoCommitOnReuse()
          Tests that nothing is committed on the connection when autocommit is disabled.
 void resTestNoDataCommittedOnInvalidTransactionState()
          Tests that nothing is committed on the connection when autocommit is disabled.
static junit.framework.Test suite()
           
 void testCacheOverflow()
          Tests that the statement cache is able to throw out prepared statements when it reaches maximum capacity.
 void testCachingLogicalConnectionCloseLeavesPhysicalStatementsOpen()
          Tests that closing the caching logical connection closes the logical prepared statement, but not the physical prepared statement.
 void testClosingPSClosesRS()
          Tests that closing the prepared statement also closes the result set.
 void testDeleteReferringTableWhenInCache()
          Tests that closing a logical prepared statement referring a non-existing table works.
 void testDeleteReferringTableWhenOpen()
          Tests that closing a logical prepared statement referring a non-existing table works.
 void testGetStatementCallable()
          Make sure ResultSet.getStatement() returns the same object as the one that created the result set.
 void testGetStatementPrepared()
          Make sure ResultSet.getStatement() returns the same object as the one that created the result set.
 void testHoldabilityIsResetExplicitClose()
          Tests that the connection holdability is reset, when it is first modified, the connection closed and a new logical connection obtained.
 void testHoldabilityIsResetNoExplicitClose()
          Tests that the connection holdability is reset, when it is first modified, and a new logical connection obtained without first explicitly closing the previous one.
 void testIsolationLevelIsResetExplicitCloseNoQuery()
           
 void testIsolationLevelIsResetExplicitCloseQuery()
           
 void testIsolationLevelIsResetNoExplicitCloseNoQuery()
           
 void testIsolationLevelIsResetNoExplicitCloseQuery()
           
 void testPoolingEnabledByCheckingImplementationDetails()
          Verifies that statement pooling is enabled by checking the names of the implementation classes in Derby.
 void testPrepareCallPath()
          This test merley checks that creating a logical callable statement does not fail.
 void testPrepareCallWithNoCallPath()
          This test merley checks that creating a logical callable statement, which is not really a call, does not fail.
 void testPrepareStatementPath()
          This test merley checks that creating a logical prepared statement does not fail.
 void testTemporaryTablesAreDeletedInNewLogicalConnection()
          Tests that a temporary table crated in one logical connection is gone in the next logical connection.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StatementPoolingTest

public StatementPoolingTest(java.lang.String name)
Method Detail

testCacheOverflow

public void testCacheOverflow()
                       throws java.sql.SQLException
Tests that the statement cache is able to throw out prepared statements when it reaches maximum capacity.

Throws:
java.sql.SQLException - if something goes wrong...

testPoolingEnabledByCheckingImplementationDetails

public void testPoolingEnabledByCheckingImplementationDetails()
                                                       throws java.sql.SQLException
Verifies that statement pooling is enabled by checking the names of the implementation classes in Derby.

Throws:
java.sql.SQLException - if creating the JDBC objects fail

assertClassName

private static void assertClassName(java.lang.Object obj,
                                    java.lang.String expectedName)
Assert that the name of the class of the object is what is expected.

The assert does not consider package names, only the name passed in as expectedName and the passed in name concatenated with "40".

WARNING: This method is not a general utility method. Please look at the implementation to determine if you can use it.

Parameters:
obj - object to check
expectedName - the expected name of the class
Throws:
AssertionFailedError - if the class name is not as expected

testPrepareStatementPath

public void testPrepareStatementPath()
                              throws java.sql.SQLException
This test merley checks that creating a logical prepared statement does not fail.

Throws:
java.sql.SQLException - if creating the prepared statement fails

testPrepareCallPath

public void testPrepareCallPath()
                         throws java.sql.SQLException
This test merley checks that creating a logical callable statement does not fail.

Throws:
java.sql.SQLException - if creating the callable statement fails

testPrepareCallWithNoCallPath

public void testPrepareCallWithNoCallPath()
                                   throws java.sql.SQLException
This test merley checks that creating a logical callable statement, which is not really a call, does not fail.

Throws:
java.sql.SQLException - if creating the callable statement fails

testClosingPSClosesRS

public void testClosingPSClosesRS()
                           throws java.sql.SQLException
Tests that closing the prepared statement also closes the result set.

Throws:
java.sql.SQLException - if something goes wrong...

testHoldabilityIsResetExplicitClose

public void testHoldabilityIsResetExplicitClose()
                                         throws java.sql.SQLException
Tests that the connection holdability is reset, when it is first modified, the connection closed and a new logical connection obtained.

Throws:
java.sql.SQLException - if something goes wrong...

testHoldabilityIsResetNoExplicitClose

public void testHoldabilityIsResetNoExplicitClose()
                                           throws java.sql.SQLException
Tests that the connection holdability is reset, when it is first modified, and a new logical connection obtained without first explicitly closing the previous one.

Throws:
java.sql.SQLException - if something goes wrong...

doTestHoldabilityIsReset

private void doTestHoldabilityIsReset(boolean closeConnection)
                               throws java.sql.SQLException
Test sequence for testing if the connection holdability is reset.

Parameters:
closeConnection - determines if the logical connection is explicitly closed before a new one is obtained
Throws:
java.sql.SQLException - if something goes wrong...

testIsolationLevelIsResetExplicitCloseQuery

public void testIsolationLevelIsResetExplicitCloseQuery()
                                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

testIsolationLevelIsResetExplicitCloseNoQuery

public void testIsolationLevelIsResetExplicitCloseNoQuery()
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

testIsolationLevelIsResetNoExplicitCloseNoQuery

public void testIsolationLevelIsResetNoExplicitCloseNoQuery()
                                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

testIsolationLevelIsResetNoExplicitCloseQuery

public void testIsolationLevelIsResetNoExplicitCloseQuery()
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

doTestIsolationLevelIsReset

private void doTestIsolationLevelIsReset(boolean closeConnection,
                                         boolean executeQuery)
                                  throws java.sql.SQLException
Tests if the connection isolation level is reset when a new connection is obtained.

The two arguments are introduced to test different scenarios; explicit and implicit connection closing, and session data caching (piggybacked information).

Parameters:
closeConnection - tells if the connection is explicitly closed before a new one is obtained
executeQuery - tells if a query is executed on the connection before a new connection is obtained.
Throws:
java.sql.SQLException - if something goes wrong...

testCachingLogicalConnectionCloseLeavesPhysicalStatementsOpen

public void testCachingLogicalConnectionCloseLeavesPhysicalStatementsOpen()
                                                                   throws java.sql.SQLException
Tests that closing the caching logical connection closes the logical prepared statement, but not the physical prepared statement.

Since there are no public interface methods to test this, the approach taken will be as follows:

  1. Create a new table.
  2. Prepare a statement selecting from the table.
  3. Close the statement, putting it into the cache.
  4. Delete the table.
  5. Prepare the selecting statement again.
  6. Execute the statement.
If the physical statement was closed when closing the caching logical connection, the prepare will fail. If it was left open, the prepare will succeed because the statement is fetched from the cache, but the execution will fail because the table no longer exists.

Throws:
java.sql.SQLException - if something goes wrong...

resTestCloseDoesNotAffectOtherStatement

public void resTestCloseDoesNotAffectOtherStatement()
                                             throws java.sql.SQLException
Checks if a reset of one statement affects other open statement on the connection.

Throws:
java.sql.SQLException - if something goes wrong...

testDeleteReferringTableWhenOpen

public void testDeleteReferringTableWhenOpen()
                                      throws java.sql.SQLException
Tests that closing a logical prepared statement referring a non-existing table works.

In this test, the prepared statement that will be made invalid by the delete is held open by the user.

Throws:
java.sql.SQLException - if something goes wrong...

testDeleteReferringTableWhenInCache

public void testDeleteReferringTableWhenInCache()
                                         throws java.sql.SQLException
Tests that closing a logical prepared statement referring a non-existing table works.

In this test, the prepared statement that will be made invalid by the delete is in the statement cache when the delete happens.

Throws:
java.sql.SQLException - if something goes wrong...

resTestCloseCursorsAtCommit

public void resTestCloseCursorsAtCommit()
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

resTestHoldCursorsOverCommit

public void resTestHoldCursorsOverCommit()
                                  throws java.sql.SQLException
Throws:
java.sql.SQLException

testTemporaryTablesAreDeletedInNewLogicalConnection

public void testTemporaryTablesAreDeletedInNewLogicalConnection()
                                                         throws java.sql.SQLException
Tests that a temporary table crated in one logical connection is gone in the next logical connection.

Throws:
java.sql.SQLException - if the test fails for some reason

doTestResultSetCloseForHoldability

private void doTestResultSetCloseForHoldability(int holdability)
                                         throws java.sql.SQLException
Tests if the holdability settings is taking effect, and also that the result set is closed when the connection is closed.

Parameters:
holdability - result set holdability as specfied by ResultSet
Throws:
java.sql.SQLException - if something goes wrong...

testGetStatementCallable

public void testGetStatementCallable()
                              throws java.sql.SQLException
Make sure ResultSet.getStatement() returns the same object as the one that created the result set.

Throws:
java.sql.SQLException

testGetStatementPrepared

public void testGetStatementPrepared()
                              throws java.sql.SQLException
Make sure ResultSet.getStatement() returns the same object as the one that created the result set.

Throws:
java.sql.SQLException

doTestGetStatement

private void doTestGetStatement(java.sql.PreparedStatement ps)
                         throws java.sql.SQLException
Make sure ResultSet.getStatement() returns the same object as the one that created the result set.

Parameters:
ps - prepared or callable statement to test with
Throws:
java.sql.SQLException - if something goes wrong...

resTestLogicalConnectionCloseInvalidatesLogicalStatement

public void resTestLogicalConnectionCloseInvalidatesLogicalStatement()
                                                              throws java.sql.SQLException
Checks if closing the logical connection closes the logical statement.

Throws:
java.sql.SQLException - if something goes wrong...

resTestNoCommitOnReuse

public void resTestNoCommitOnReuse()
                            throws java.sql.SQLException
Tests that nothing is committed on the connection when autocommit is disabled.

Throws:
java.sql.SQLException - if something goes wrong...

resTestCommitOnReuse

public void resTestCommitOnReuse()
                          throws java.sql.SQLException
Tests that autocommit is working.

Throws:
java.sql.SQLException - if something goes wrong...

resTestNoDataCommittedOnInvalidTransactionState

public void resTestNoDataCommittedOnInvalidTransactionState()
                                                     throws java.sql.SQLException
Tests that nothing is committed on the connection when autocommit is disabled.

Throws:
java.sql.SQLException - if something goes wrong...

cleanTableExceptedToBeEmpty

private void cleanTableExceptedToBeEmpty()
                                  throws java.sql.SQLException
Deletes row from a test table that is expected to be empty.

Throws:
java.sql.SQLException - if a database operation fails

suite

public static junit.framework.Test suite()

Built on Thu 2009-11-26 18:42:53-0800, from revision 884739

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.