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

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.CacheSessionDataTest
All Implemented Interfaces:
junit.framework.Test

public class CacheSessionDataTest
extends BaseJDBCTestCase

This is a test for DERBY-3192 (https://issues.apache.org/jira/browse/DERBY-3192) which tries to avoid unecessary roundtrips by piggybacking session information on the messages going back to the client. The goal is that whenever a user requests session information from the client driver, the correct information should already be available and no special roundtrip be required. So far the test only checks caching of the isolation level, but other session attributes can be added later. The test attempts to "fool" the caching mechanism by modifying the isolation level without going through the client's Connection.setTransactionIsolation method. The effect of modifying the isolation level in and out of XA transactions is covered by the XA tests and not tested here.


Field Summary
private static int isolationIndex
           
private static IsoLevel[] isoLevels
           
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
CacheSessionDataTest(java.lang.String name)
           
 
Method Summary
private static junit.framework.Test baseSuite(java.lang.String name)
          Creates a new TestSuite with all the tests, and wraps it in a CleanDatabaseSetup with a custom decorator.
private  void cursorTest(java.lang.String table, int type, int concur)
          Utility method for testing Statements that return different types of ResultSets to check that piggybacking doesn't cause problems.
private static IsoLevel cycleIsolation()
          Utility that cycles through the legal isolation levels in the following order: read uncommitted -> read committed -> repeatable read -> serializable -> read uncommitted -> ...
static int getCycleIsolationJDBC()
          Implementation of the SQL function GET_CYCLE_ISOLATION_JDBC.
static java.lang.String getCycleIsolationSQL()
          Implementation of the SQL function GET_CYCLE_ISOLATION_SQL.
static java.lang.String getSchemaTransition(java.lang.String nextSchema)
          Implementation of the SQL function GET_SCHEMA_TRANSITION.
static int getTransactionIsolationJDBC()
          Implementation of the SQL function GET_TRANSACTION_ISOLATION_JDBC.
private  void preparedCursorTest(java.lang.String table, int type, int concur)
          Utility method for testing PreparedStatements that return different types of ResultSets to check that piggybacking doesn't cause problems.
static void setIsolationJDBC(int isolation)
          Implementation of the stored procedure SET_ISOLATION_JDBC.
static void setIsolationSQL(java.lang.String sqlName)
          Implementation of the SQL function SET_ISOLATION_SQL.
static void setSchema(java.lang.String schemaName)
          Implementation of the SQL procedure SET_SCHEMA.
 void setUp()
          Turns off auto commit on the default connection and verifies that the isolation level is read committed.
static junit.framework.Test suite()
          Adds both the embedded and client-server versions of the baseSuite to the Test.
 void tearDown()
          Removes all tables in schema APP which has the prefix 'T', before calling super.tearDown().
 void testChangeIsoLevelCallableStatementJDBC()
           
 void testChangeIsoLevelCallableStatementSQL()
           
 void testChangeIsoLevelFunctionJDBC()
           
 void testChangeIsoLevelFunctionSQL()
           
 void testChangeIsoLevelPreparedFunctionJDBC()
           
 void testChangeIsoLevelPreparedFunctionSQL()
           
 void testChangeIsoLevelPreparedStatementSQL()
           
 void testChangeIsoLevelProcedureJDBC()
           
 void testChangeIsoLevelProcedureJdbcBatch()
           
 void testChangeIsoLevelProcedureJdbcCallableBatch()
           
 void testChangeIsoLevelProcedureSQL()
           
 void testChangeIsoLevelProcedureSqlBatch()
           
 void testChangeIsoLevelProcedureSqlCallableBatch()
           
 void testChangeIsoLevelSQLInBatch()
           
 void testChangeIsoLevelStatementSQL()
           
 void testLargeForwardOnlyReadOnly()
           
 void testLargeForwardOnlyUpdatable()
           
 void testLargePreparedForwardOnlyReadOnly()
           
 void testLargePreparedForwardOnlyUpdatable()
           
 void testLargePreparedScrollInsensitiveReadOnly()
           
 void testLargePreparedScrollInsensitiveUpdatable()
           
 void testLargePreparedScrollSensitiveReadOnly()
           
 void testLargePreparedScrollSensitiveUpdatable()
           
 void testLargeScrollInsensitiveReadOnly()
           
 void testLargeScrollInsensitiveUpdatable()
           
 void testLargeScrollSensitiveReadOnly()
           
 void testLargeScrollSensitiveUpdatable()
           
 void testPreparedSetSchema()
           
 void testPreparedSetSchemaFunction()
           
 void testPreparedSetSchemaFunctionLarge()
           
 void testPreparedSetSchemaProcedure()
           
 void testSetSchema()
           
 void testSetSchemaFunction()
           
 void testSetSchemaFunctionLarge()
           
 void testSetSchemaProcedure()
           
 void testSmallForwardOnlyReadOnly()
           
 void testSmallForwardOnlyUpdatable()
           
 void testSmallPreparedForwardOnlyReadOnly()
           
 void testSmallPreparedForwardOnlyUpdatable()
           
 void testSmallPreparedScrollInsensitiveReadOnly()
           
 void testSmallPreparedScrollInsensitiveUpdatable()
           
 void testSmallPreparedScrollSensitiveReadOnly()
           
 void testSmallPreparedScrollSensitiveUpdatable()
           
 void testSmallScrollInsensitiveReadOnly()
           
 void testSmallScrollInsensitiveUpdatable()
           
 void testSmallScrollSensitiveReadOnly()
           
 void testSmallScrollSensitiveUpdatable()
           
private  void verifyCachedIsolation(java.sql.Connection c)
          Utility that verifies that the isolation level reported by the client is the same as evaluating 'VALUES CURRENT ISOLATION' and getting the isolation level from the EmbedConnection on the server.
private  void verifyCachedSchema(java.sql.Connection c)
           
 
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, 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, 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
 

Field Detail

isoLevels

private static IsoLevel[] isoLevels

isolationIndex

private static int isolationIndex
Constructor Detail

CacheSessionDataTest

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

suite

public static junit.framework.Test suite()
Adds both the embedded and client-server versions of the baseSuite to the Test. An empty TestSuite is returned unless we have JDBC3 support, because all test cases call verifyCachedIsolation() which in turn makes use of getTransactionIsolationJDBC() (GET_TRANSACTION_ISOLATION_JDBC) which uses DriverManager to access the default connection.

Returns:
the resulting Test object

baseSuite

private static junit.framework.Test baseSuite(java.lang.String name)
Creates a new TestSuite with all the tests, and wraps it in a CleanDatabaseSetup with a custom decorator.

Parameters:
name - TestSuite name
Returns:
wrapped TestSuite

setUp

public void setUp()
           throws java.sql.SQLException
Turns off auto commit on the default connection and verifies that the isolation level is read committed. Initailizes the array 'isoLevels' with the 4 standard isolation levels if this has not already been done.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.sql.SQLException

tearDown

public void tearDown()
              throws java.lang.Exception
Removes all tables in schema APP which has the prefix 'T', before calling super.tearDown().

Overrides:
tearDown in class BaseJDBCTestCase
Throws:
java.lang.Exception

setIsolationJDBC

public static void setIsolationJDBC(int isolation)
                             throws java.sql.SQLException
Implementation of the stored procedure SET_ISOLATION_JDBC. Sets the the isolation level given as argument on the default connection using Connection.setTransactionIasolation.

Parameters:
isolation - JDBC isolation level constant representing the new isolation level
Throws:
java.sql.SQLException

setIsolationSQL

public static void setIsolationSQL(java.lang.String sqlName)
                            throws java.sql.SQLException
Implementation of the SQL function SET_ISOLATION_SQL. Sets the the isolation level given as argument on the default connection using SQL.

Parameters:
sqlName - SQL string representing the new isolation level
Throws:
java.sql.SQLException

getTransactionIsolationJDBC

public static int getTransactionIsolationJDBC()
                                       throws java.sql.SQLException
Implementation of the SQL function GET_TRANSACTION_ISOLATION_JDBC. Returns the isolation level reported by the default EmbedConnection on the server. Used to verify that the isolation level reported by the client is correct.

Returns:
JDBC isolation level constant reported by the embedded driver
Throws:
java.sql.SQLException

getCycleIsolationJDBC

public static int getCycleIsolationJDBC()
                                 throws java.sql.SQLException
Implementation of the SQL function GET_CYCLE_ISOLATION_JDBC. Cycles the isolation level on the default Connection.

Returns:
the new JDBC isolation level constant
Throws:
java.sql.SQLException

getCycleIsolationSQL

public static java.lang.String getCycleIsolationSQL()
                                             throws java.sql.SQLException
Implementation of the SQL function GET_CYCLE_ISOLATION_SQL. Cycles the isolation level on the default Connection.

Returns:
the SQL name of the new isolation level
Throws:
java.sql.SQLException

setSchema

public static void setSchema(java.lang.String schemaName)
                      throws java.sql.SQLException
Implementation of the SQL procedure SET_SCHEMA. Sets a different schema on the default Connection.

Parameters:
schemaName - name of the new schema
Throws:
java.sql.SQLException

getSchemaTransition

public static java.lang.String getSchemaTransition(java.lang.String nextSchema)
                                            throws java.sql.SQLException
Implementation of the SQL function GET_SCHEMA_TRANSITION. Sets the current schema to the name given as argument and returns the schema transition.

Parameters:
nextSchema - schema to transition to
Returns:
a string of the form oldSchema->newSchema
Throws:
java.sql.SQLException

cycleIsolation

private static IsoLevel cycleIsolation()
Utility that cycles through the legal isolation levels in the following order: read uncommitted -> read committed -> repeatable read -> serializable -> read uncommitted -> ...

Returns:
IsoLevel object representing the isolation level.

verifyCachedIsolation

private void verifyCachedIsolation(java.sql.Connection c)
                            throws java.sql.SQLException
Utility that verifies that the isolation level reported by the client is the same as evaluating 'VALUES CURRENT ISOLATION' and getting the isolation level from the EmbedConnection on the server.

Parameters:
c - Connection to check
Throws:
java.sql.SQLException

verifyCachedSchema

private void verifyCachedSchema(java.sql.Connection c)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

testChangeIsoLevelStatementSQL

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

testChangeIsoLevelPreparedStatementSQL

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

testChangeIsoLevelFunctionJDBC

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

testChangeIsoLevelFunctionSQL

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

testChangeIsoLevelPreparedFunctionJDBC

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

testChangeIsoLevelPreparedFunctionSQL

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

testChangeIsoLevelProcedureJDBC

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

testChangeIsoLevelProcedureSQL

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

testChangeIsoLevelCallableStatementJDBC

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

testChangeIsoLevelCallableStatementSQL

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

testChangeIsoLevelSQLInBatch

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

testChangeIsoLevelProcedureJdbcBatch

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

testChangeIsoLevelProcedureSqlBatch

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

testChangeIsoLevelProcedureJdbcCallableBatch

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

testChangeIsoLevelProcedureSqlCallableBatch

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

cursorTest

private void cursorTest(java.lang.String table,
                        int type,
                        int concur)
                 throws java.sql.SQLException
Utility method for testing Statements that return different types of ResultSets to check that piggybacking doesn't cause problems.

Parameters:
table - table to select from
type - type of ResultSet
concur - concurrency of ResultSet
Throws:
java.sql.SQLException

preparedCursorTest

private void preparedCursorTest(java.lang.String table,
                                int type,
                                int concur)
                         throws java.sql.SQLException
Utility method for testing PreparedStatements that return different types of ResultSets to check that piggybacking doesn't cause problems.

Parameters:
table - table to select from
type - type of ResultSet
concur - concurrency of ResultSet
Throws:
java.sql.SQLException

testSmallForwardOnlyReadOnly

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

testSmallScrollInsensitiveReadOnly

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

testSmallScrollSensitiveReadOnly

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

testSmallForwardOnlyUpdatable

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

testSmallScrollInsensitiveUpdatable

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

testSmallScrollSensitiveUpdatable

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

testSmallPreparedForwardOnlyReadOnly

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

testSmallPreparedScrollSensitiveReadOnly

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

testSmallPreparedScrollInsensitiveReadOnly

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

testSmallPreparedForwardOnlyUpdatable

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

testSmallPreparedScrollSensitiveUpdatable

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

testSmallPreparedScrollInsensitiveUpdatable

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

testLargeForwardOnlyReadOnly

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

testLargeScrollSensitiveReadOnly

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

testLargeScrollInsensitiveReadOnly

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

testLargeForwardOnlyUpdatable

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

testLargeScrollSensitiveUpdatable

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

testLargeScrollInsensitiveUpdatable

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

testLargePreparedForwardOnlyReadOnly

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

testLargePreparedScrollSensitiveReadOnly

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

testLargePreparedScrollInsensitiveReadOnly

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

testLargePreparedForwardOnlyUpdatable

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

testLargePreparedScrollSensitiveUpdatable

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

testLargePreparedScrollInsensitiveUpdatable

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

testSetSchema

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

testPreparedSetSchema

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

testSetSchemaProcedure

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

testPreparedSetSchemaProcedure

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

testSetSchemaFunction

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

testPreparedSetSchemaFunction

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

testSetSchemaFunctionLarge

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

testPreparedSetSchemaFunctionLarge

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

Built on Wed 2009-11-25 18:43:31-0800, from revision 884373

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