org.eigenbase.test.concurrent
Class ConcurrentTestCommandExecutor

java.lang.Object
  extended by java.lang.Thread
      extended by org.eigenbase.test.concurrent.ConcurrentTestCommandExecutor
All Implemented Interfaces:
Runnable

 class ConcurrentTestCommandExecutor
extends Thread

ConcurrentTestCommandExecutor is a thread that executes a sequence of commands on a JDBC connection.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/test/concurrent/ConcurrentTestCommandExecutor.java#2 $
Author:
Stephan Zuercher

Nested Class Summary
static class ConcurrentTestCommandExecutor.Sync
          Synchronization object that allows multiple ConcurrentTestCommandExecutors to execute commands in lock-step.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  Iterator commands
          Command sequence for this thread.
private  Connection connection
          JDBC connection for commands.
private  PrintStream debugPrintStream
          Debugging print stream.
private  Throwable error
          First exception thrown by the thread.
private  ConcurrentTestCommand errorCommand
          Command throwing error *
private  Properties jdbcProps
          JDBC Connection properties.
private  String jdbcURL
          JDBC URL to connect with.
private  Statement statement
          Current JDBC Statement.
private  ConcurrentTestCommandExecutor.Sync synchronizer
          Used to synchronize command execution.
private  Integer threadId
          The id for this thread.
private  String when
          Location of error.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConcurrentTestCommandExecutor(int threadId, String threadName, String jdbcURL, Properties jdbcProps, Iterator commands, ConcurrentTestCommandExecutor.Sync synchronizer, PrintStream debugPrintStream)
          Constructs a ConcurrentTestCommandExecutor with the given thread ID, JDBC URL, commands and synchronization object.
 
Method Summary
 void clearStatement()
          Clears the thread's current JDBC statement.
 Connection getConnection()
          Obtains the thread's JDBC connection.
 Throwable getFailureCause()
          Checks whether an exception occurred during execution.
 ConcurrentTestCommand getFailureCommand()
           
 String getFailureLocation()
          Returns location (e.g., command number) for exception returned by getFailureCause().
 Statement getStatement()
          Obtains the thread's current JDBC statement.
 ConcurrentTestCommandExecutor.Sync getSynchronizer()
          Retrieves the object used to synchronize threads at a point in the list of commands.
 Integer getThreadId()
           
private  void handleError(Throwable error, String when, ConcurrentTestCommand command)
          Handles details of an exception during execution.
 void run()
          Executes the configured commands.
 void setStatement(Statement stmt)
          Sets the thread's current JDBC statement.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

threadId

private Integer threadId
The id for this thread.


jdbcURL

private String jdbcURL
JDBC URL to connect with.


jdbcProps

private Properties jdbcProps
JDBC Connection properties.


commands

private Iterator commands
Command sequence for this thread.


synchronizer

private ConcurrentTestCommandExecutor.Sync synchronizer
Used to synchronize command execution.


connection

private Connection connection
JDBC connection for commands.


statement

private Statement statement
Current JDBC Statement. May be null.


error

private Throwable error
First exception thrown by the thread.


when

private String when
Location of error.


debugPrintStream

private final PrintStream debugPrintStream
Debugging print stream. May be null.


errorCommand

private ConcurrentTestCommand errorCommand
Command throwing error *

Constructor Detail

ConcurrentTestCommandExecutor

ConcurrentTestCommandExecutor(int threadId,
                              String threadName,
                              String jdbcURL,
                              Properties jdbcProps,
                              Iterator commands,
                              ConcurrentTestCommandExecutor.Sync synchronizer,
                              PrintStream debugPrintStream)
Constructs a ConcurrentTestCommandExecutor with the given thread ID, JDBC URL, commands and synchronization object.

Parameters:
threadId - the thread ID (see ConcurrentTestCommandGenerator)
threadName - the thread's name
jdbcURL - the JDBC URL to connect to
jdbcProps - JDBC Connnection properties (user, password, etc.)
commands - the sequence of commands to execute -- null elements indicate no-ops
synchronizer - synchronization object (may not be null);
debugPrintStream - if non-null a PrintStream to use for debugging output (may help debugging thread synchronization issues)
Method Detail

run

public void run()
Executes the configured commands.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

handleError

private void handleError(Throwable error,
                         String when,
                         ConcurrentTestCommand command)
Handles details of an exception during execution.


getConnection

public Connection getConnection()
Obtains the thread's JDBC connection.


getStatement

public Statement getStatement()
Obtains the thread's current JDBC statement. May return null.


setStatement

public void setStatement(Statement stmt)
Sets the thread's current JDBC statement. To clear the JDBC statement use clearStatement().


clearStatement

public void clearStatement()
Clears the thread's current JDBC statement. To set the JDBC statement use setStatement(Statement).


getSynchronizer

public ConcurrentTestCommandExecutor.Sync getSynchronizer()
Retrieves the object used to synchronize threads at a point in the list of commands.


getFailureCause

public Throwable getFailureCause()
Checks whether an exception occurred during execution. If this method returns null, the thread's commands all succeeded. If this method returns non-null, see getFailureLocation() for details on which command caused the failure.


getFailureLocation

public String getFailureLocation()
Returns location (e.g., command number) for exception returned by getFailureCause().


getFailureCommand

public ConcurrentTestCommand getFailureCommand()

getThreadId

public Integer getThreadId()