org.osesb.scheduledjobs.databasepoller.test
Class DatabasePollerTestDriver

java.lang.Object
  extended by org.osesb.scheduledjobs.databasepoller.test.DatabasePollerTestDriver
All Implemented Interfaces:
java.lang.Runnable

public class DatabasePollerTestDriver
extends java.lang.Object
implements java.lang.Runnable

Helper class for DatabasePollerTest, which is a JUnit Test for the org.osesb.scheduledjobs.databasepoller package.

Tests a database poller that is configured by the ScheduledJobConfiguration file specified by the 'testConfiguration' property Test.properties.

Tests can be configured to run against different database applications using the </scheduled-job/job-configuration/database-poller-configuration/tableset-configuration/jdbc-configuration> element in the ScheduledJobConfiguration file and the 'databasePollerTestDriverConfiguration' property in Test.properties.

The target database application must be up and available for the tests to run. The JDBCTEST test tables must be created in the target database application. See org.osesb.utilities.jdbc.test.testdata for .sql files that create the test database.

The test DatabasePollerConfiguration(s) in the example folders (example1, example2,...) are configured to use the Customer table in the JDBC test database.

DatabasePollerTest uses a test driver, DatabasePollerTestDriver, which runs in a Thread that periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

DatabasePollerTestDriver is configured using the DataSetConfiguration file specified by the 'databasePollerTestDriverConfiguration' property in Test.properties. The DataSetConfiguration includes at least a SQLStatement that is used to update the database table(s) configured for the database poller that is being tested.

DatabasePollerTestDriver gets its database connection using the JDBCConfiguration that is configured for the TableSet that the database poller uses. The SQL statement configured for DatabasePollerTestDriver must update the databse table(s) configured for the database poller that is being tested. The tester should make sure that the DataSetConfiguration for the DatabasePollerTestDriver is consistent with the <jdbc-configuration> element in the ScheduledJobConfiguration file.

The test succeeds if the number of rows processed by the database poller is equal to 'the number of rows initially in the target table(s)' + 'the number of rows added by DatabasePollerTestDriver'. The number of rows initially in the target table(s) is given by the 'initialNumberOfTestRows' property in Test.properties.


Field Summary
protected  DataSetConfiguration dataSetConfiguration
          The DataSetConfiguration for this DatabasePollerTestDriver, which is set by the DatabasePollerTest that instantiates this class.
protected  java.sql.Connection dbConn
          JDBC Connections used by testThread.
protected static org.apache.commons.logging.Log log
          The logging implementation for this class.
protected static int MAX_ROWS_TO_INSERT
          The DatabasePollerTestDriver thread periodically inserts a random number of rows into the table(s) which are being scanned by the database poller.
protected  ScheduledJobConfiguration scheduledJobConfiguration
          The DatabasePollerConfiguration passed to the Constructor.
protected  java.lang.Thread testThread
          The DatabasePollerTestDriver thread periodically inserts a random number of rows into the table(s) which are being scanned by the database poller.
protected  boolean testThreadStopping
          run() flag for testThread.
protected  java.lang.String thisClassName
          The full name of this class.
protected  java.util.Date threadStartedTimestamp
          Timestamp for when testThread started.
protected  int totalNumberOfRowsInserted
          The DatabasePollerTestDriver thread periodically inserts a random number of rows into the table(s) which are being scanned by the database poller.
 
Constructor Summary
DatabasePollerTestDriver(ScheduledJobConfiguration scheduledJobConfiguration)
          Invoked by DatabasePollerTest to create a new instance of DatabasePollerTestDriver.
 
Method Summary
 DataSetConfiguration getDataSetConfiguration()
          Returns the DataSetConfiguration for this DatabasePollerTestDriver, which is set by the DatabasePollerTest that instantiates this class.
 ScheduledJobConfiguration getScheduledJobConfiguration()
          Returns the ScheduledJobConfiguration for this DatabasePollerTestDriver.
 int getTotalNumberOfRowsInserted()
          Get the totalNumberOfRowsInserted is the total number of rows inserted by testThread.
 void joinTestThread()
          Wait for testThread to die.
static void main(java.lang.String[] args)
          main() For testing.
 void run()
          Run the DatabasePollerTestDriver thread, periodically inserts a random number of rows into the table(s) which are being scanned by the database poller.
 void setDataSetConfiguration(DataSetConfiguration dataSetConfiguration)
          Sets the DataSetConfiguration for this DatabasePollerTestDriver, which is set by the DatabasePollerTest that instantiates this class.
 void start()
          Start testThread, which periodically inserts a random number of rows into the table(s) which are being scanned by the database poller.
 void stop()
          Stop testThread, which periodically inserts a random number of rows into the table(s) which are being scanned by the database poller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thisClassName

protected java.lang.String thisClassName
The full name of this class.


scheduledJobConfiguration

protected ScheduledJobConfiguration scheduledJobConfiguration
The DatabasePollerConfiguration passed to the Constructor.

DatabasePollerTestDriver accesses the JDBCConfiguration and the repeat inetrval configured for the database poller.


dataSetConfiguration

protected DataSetConfiguration dataSetConfiguration
The DataSetConfiguration for this DatabasePollerTestDriver, which is set by the DatabasePollerTest that instantiates this class.

The DataSetConfiguration includes at least a SQLStatement that is used to insert rows into the database table(s) configured for the database poller that is being tested.

See Also:
setDataSetConfiguration(DataSetConfiguration dataSetConfiguration)

testThread

protected java.lang.Thread testThread
The DatabasePollerTestDriver thread periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

See Also:
start(), stop(), run()

threadStartedTimestamp

protected java.util.Date threadStartedTimestamp
Timestamp for when testThread started.

See Also:
start(), run()

testThreadStopping

protected boolean testThreadStopping
run() flag for testThread.

See Also:
start(), stop(), run()

dbConn

protected java.sql.Connection dbConn
JDBC Connections used by testThread.

See Also:
start(), run()

MAX_ROWS_TO_INSERT

protected static final int MAX_ROWS_TO_INSERT
The DatabasePollerTestDriver thread periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

See Also:
run(), Constant Field Values

totalNumberOfRowsInserted

protected int totalNumberOfRowsInserted
The DatabasePollerTestDriver thread periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

totalNumberOfRowsInserted is the total number of rows inserted by testThread.

See Also:
run()

log

protected static org.apache.commons.logging.Log log
The logging implementation for this class.

Constructor Detail

DatabasePollerTestDriver

public DatabasePollerTestDriver(ScheduledJobConfiguration scheduledJobConfiguration)
                         throws java.lang.Exception
Invoked by DatabasePollerTest to create a new instance of DatabasePollerTestDriver.

Parameters:
scheduledJobConfiguration - The ScheduledJobConfiguration for the database poller being tested.
Throws:
java.lang.Exception - if constructed with a null scheduledJobConfiguration.
Method Detail

start

public void start()
           throws java.lang.Exception
Start testThread, which periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

Throws:
java.lang.Exception

stop

public void stop()
Stop testThread, which periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.


joinTestThread

public void joinTestThread()
Wait for testThread to die.


run

public void run()
Run the DatabasePollerTestDriver thread, periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

Specified by:
run in interface java.lang.Runnable
See Also:
start(), stop()

getScheduledJobConfiguration

public ScheduledJobConfiguration getScheduledJobConfiguration()
Returns the ScheduledJobConfiguration for this DatabasePollerTestDriver.

Returns:
the ScheduledJobConfiguration for this DatabasePollerTestDriver.

getDataSetConfiguration

public DataSetConfiguration getDataSetConfiguration()
Returns the DataSetConfiguration for this DatabasePollerTestDriver, which is set by the DatabasePollerTest that instantiates this class.

The DataSetConfiguration includes at least a SQLStatement that is used to insert rows into the database table(s) configured for the database poller that is being tested.

Returns:
the DataSetConfiguration for this DatabasePollerTestDriver.

setDataSetConfiguration

public void setDataSetConfiguration(DataSetConfiguration dataSetConfiguration)
Sets the DataSetConfiguration for this DatabasePollerTestDriver, which is set by the DatabasePollerTest that instantiates this class.

The DataSetConfiguration includes at least a SQLStatement that is used to insert rows into the database table(s) configured for the database poller that is being tested.

Parameters:
dataSetConfiguration - The DataSetConfiguration for this DatabasePollerTestDriver.

getTotalNumberOfRowsInserted

public int getTotalNumberOfRowsInserted()
Get the totalNumberOfRowsInserted is the total number of rows inserted by testThread.

Returns:
the totalNumberOfRowsInserted is the total number of rows inserted by testThread.
See Also:
run()

main

public static void main(java.lang.String[] args)
main() For testing.

Parameters:
args - commandline arguments