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

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

public class BatchUpdateTest
extends BaseJDBCTestCase

Test BatchUpdate functionality.

This test examines the behavior fo BatchUpdate test. One fixture tests creating tables in batch, the other fixtures can be grouped into 5 rough categories: - tests that verify that correct usage with Statements work as expected - testEmptyStatementBatch() try executing a batch which nothing in it. - testSingleStatementBatch() try executing a batch which one statement in it. - testMultipleStatementsBatch() try executing a batch with 3 different statements in it. - test1000StatementsBatch() try executing a batch with 1000 statements in it. - testAutoCommitTrueBatch() try batch with autocommit true - testCombinationsOfClearBatch() try clear batch - testAssociatedParams() confirm associated parameters run ok with batches - tests that verify that incorrect usage with Statments give appropriate errors - testStatementWithResultSetBatch() statements which will return a resultset are not allowed in batch update. The following case should throw an exception for select. Below trying various placements of select statement in the batch, i.e. as 1st stmt, nth stmt and last stmt - testStatementNonBatchStuffInBatch() try executing a batch with regular statement intermingled. - testStatementWithErrorsBatch() Below trying various placements of overflow update statement in the batch, i.e. as 1st stmt, nth stat and last stmt - testTransactionErrorBatch() try transaction error, i.e. time out while getting the lock - tests that verify that usage with callableStatements work as expected - testCallableStatementBatch() try callable statements - testCallableStatementWithOutputParamBatch() try callable statement with output parameters - tests that verify that correct usage with preparedStatements work as expected - testEmptyValueSetPreparedBatch() try executing a batch which nothing in it. - testNoParametersPreparedBatch() try executing a batch with no parameters. - testSingleValueSetPreparedBatch() try executing a batch which one parameter set in it. - testMultipleValueSetPreparedBatch() try executing a batch with 3 parameter sets in it. - testMultipleValueSetNullPreparedBatch() try executing a batch with 2 parameter sets in it and they are set to null. - test1000ValueSetPreparedBatch() try executing a batch with 1000 statements in it. - testPreparedStatRollbackAndCommitCombinations() try executing batches with various rollback and commit combinations. - testAutoCommitTruePreparedStatBatch() try prepared statement batch with autocommit true - testCombinationsOfClearPreparedStatBatch() try clear batch - tests that verify that incorrect use with preparedStatements give appropriate errors - testPreparedStmtWithResultSetBatch() statements which will return a resultset are not allowed in batch update. The following case should throw an exception for select. - testPreparedStmtNonBatchStuffInBatch(); try executing a batch with regular statement intermingled. - testPreparedStmtWithErrorsBatch(); trying various placements of overflow update statement in the batch - testTransactionErrorPreparedStmtBatch() try transaction error, in this particular case time out while getting the lock Almost all fixtures but 1 execute with embedded and NetworkServer/DerbyNetClient - however, there is a difference in functionality between the two when an error condition is reaches. Thus, the negative tests have if / else if blocks for embedded and client. The 1 fixture that ise not running with network server is identified with //TODO: tags and has an if (usingEmbedded()) block and a JIRA issue attached to it.


Field Summary
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
BatchUpdateTest(java.lang.String name)
          Creates a new instance of BatchUpdateTest
 
Method Summary
protected  void assertBatchExecuteError(java.lang.String expectedError, java.sql.Statement stmt, int[] expectedUpdateCount)
          helper method to evaluate negative tests where we expect a batchExecuteException to be returned.
private  void assertBatchUpdateCounts(int[] expectedBatchResult, int[] executeBatchResult)
           
protected static junit.framework.Test baseSuite(java.lang.String name)
           
protected  void cleanUpCallableStatement(java.sql.CallableStatement cs, java.lang.String tableName)
           
static junit.framework.Test embeddedSuite()
          embeddedSuite runs tests only in embedded mode.
private static void executeBatchCallableStatement(java.sql.CallableStatement cs)
           
 void setUp()
          Set up the conection to the database.
static junit.framework.Test suite()
           
static void takesString(java.lang.String[] outparam, int type)
           
 void test1000StatementsBatch()
           
 void test1000ValueSetPreparedBatch()
           
 void testAssociatedParams()
           
 void testAutoCommitTrueBatch()
           
 void testAutoCommitTruePreparedStatBatch()
           
 void testCallableStatementBatch()
           
 void testCallableStatementWithOutputParamBatch()
           
 void testCombinationsOfClearBatch()
           
 void testCombinationsOfClearPreparedStatBatch()
           
 void testContinueAfterError()
          Test the behaviour when one of the statements in a batch fails.
 void testEmptyStatementBatch()
           
 void testEmptyValueSetPreparedBatch()
           
 void testMinimalDDLInBatch()
           
 void testMultipleStatementsBatch()
           
 void testMultipleValueSetNullPreparedBatch()
           
 void testMultipleValueSetPreparedBatch()
           
 void testNoParametersPreparedBatch()
           
 void testPreparedStatRollbackAndCommitCombinations()
           
 void testPreparedStmtNonBatchStuffInBatch()
           
 void testPreparedStmtWithErrorsBatch()
           
 void testPreparedStmtWithResultSetBatch()
           
 void testSingleStatementBatch()
           
 void testSingleValueSetPreparedBatch()
           
 void testStatementNonBatchStuffInBatch()
           
 void testStatementWithErrorsBatch()
           
 void testStatementWithResultSetBatch()
           
 void testTransactionErrorBatch()
           
 void testTransactionErrorPreparedStmtBatch()
           
 void testUnderlyingExceptionIsVisible()
          Test that the underlying exception is included in the output when we call printStackTrace() on a BatchUpdateException.
 
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, 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

BatchUpdateTest

public BatchUpdateTest(java.lang.String name)
Creates a new instance of BatchUpdateTest

Method Detail

setUp

public void setUp()
           throws java.lang.Exception
Set up the conection to the database. This is itself a test of statements creating tables in batch.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

suite

public static junit.framework.Test suite()

embeddedSuite

public static junit.framework.Test embeddedSuite()
embeddedSuite runs tests only in embedded mode. Used by CollationTest

Returns:
embedded Test suite

baseSuite

protected static junit.framework.Test baseSuite(java.lang.String name)

assertBatchUpdateCounts

private void assertBatchUpdateCounts(int[] expectedBatchResult,
                                     int[] executeBatchResult)

assertBatchExecuteError

protected void assertBatchExecuteError(java.lang.String expectedError,
                                       java.sql.Statement stmt,
                                       int[] expectedUpdateCount)
                                throws java.sql.SQLException
helper method to evaluate negative tests where we expect a batchExecuteException to be returned.

Parameters:
expectedError - The sqlstate to look for.
stmt - The Statement that contains the Batch to be executed.
expectedUpdateCount - The expectedUpdateCount array.
Throws:
java.sql.SQLException - Thrown if the expected error occurs We expect a BatchUpdateException, and verify it is so.

testMinimalDDLInBatch

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

testEmptyStatementBatch

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

testSingleStatementBatch

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

testMultipleStatementsBatch

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

test1000StatementsBatch

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

testAutoCommitTrueBatch

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

testCombinationsOfClearBatch

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

testAssociatedParams

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

testStatementWithResultSetBatch

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

testStatementNonBatchStuffInBatch

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

testStatementWithErrorsBatch

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

testTransactionErrorBatch

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

testCallableStatementBatch

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

executeBatchCallableStatement

private static void executeBatchCallableStatement(java.sql.CallableStatement cs)
                                           throws java.sql.SQLException
Throws:
java.sql.SQLException

cleanUpCallableStatement

protected void cleanUpCallableStatement(java.sql.CallableStatement cs,
                                        java.lang.String tableName)
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

testCallableStatementWithOutputParamBatch

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

takesString

public static void takesString(java.lang.String[] outparam,
                               int type)
                        throws java.lang.Throwable
Throws:
java.lang.Throwable

testEmptyValueSetPreparedBatch

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

testNoParametersPreparedBatch

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

testSingleValueSetPreparedBatch

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

testMultipleValueSetPreparedBatch

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

testMultipleValueSetNullPreparedBatch

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

test1000ValueSetPreparedBatch

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

testPreparedStatRollbackAndCommitCombinations

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

testAutoCommitTruePreparedStatBatch

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

testCombinationsOfClearPreparedStatBatch

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

testPreparedStmtWithResultSetBatch

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

testPreparedStmtNonBatchStuffInBatch

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

testPreparedStmtWithErrorsBatch

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

testTransactionErrorPreparedStmtBatch

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

testUnderlyingExceptionIsVisible

public void testUnderlyingExceptionIsVisible()
                                      throws java.sql.SQLException
Test that the underlying exception is included in the output when we call printStackTrace() on a BatchUpdateException. Earlier, with the client driver, the underlying cause of a BatchUpdateException could not be seen without calling getNextException().

Throws:
java.sql.SQLException

testContinueAfterError

public void testContinueAfterError()
                            throws java.sql.SQLException
Test the behaviour when one of the statements in a batch fails. The embedded driver stops executing the batch when that happens, whereas the client driver continues. The difference between embedded and client is logged as DERBY-4316.

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.