Class ConcurrentTestCommandExecutor
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.calcite.test.concurrent.ConcurrentTestCommandExecutor
-
- All Implemented Interfaces:
java.lang.Runnable
class ConcurrentTestCommandExecutor extends java.lang.Thread
ConcurrentTestCommandExecutor is a thread that executes a sequence ofcommands
on a JDBC connection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConcurrentTestCommandExecutor.Sync
Synchronization object that allows multiple ConcurrentTestCommandExecutors to execute commands in lock-step.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Iterable<ConcurrentTestCommand>
commands
Command sequence for this thread.private java.sql.Connection
connection
JDBC connection for commands.private java.io.PrintStream
debugPrintStream
Debugging print stream.private java.lang.Throwable
error
First exception thrown by the thread.private ConcurrentTestCommand
errorCommand
Command throwing error *private java.util.Properties
jdbcProps
JDBC Connection properties.private java.lang.String
jdbcURL
JDBC URL to connect with.private java.sql.Statement
statement
Current JDBC Statement.private ConcurrentTestCommandExecutor.Sync
synchronizer
Used to synchronize command execution.private java.lang.Integer
threadId
The id for this thread.private java.lang.String
when
Location oferror
.
-
Constructor Summary
Constructors Constructor Description ConcurrentTestCommandExecutor(int threadId, java.lang.String threadName, java.lang.String jdbcURL, java.util.Properties jdbcProps, java.lang.Iterable<ConcurrentTestCommand> commands, ConcurrentTestCommandExecutor.Sync synchronizer, java.io.PrintStream debugPrintStream)
Constructs a ConcurrentTestCommandExecutor with the given thread ID, JDBC URL, commands and synchronization object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearStatement()
Clears the thread's current JDBC statement.java.sql.Connection
getConnection()
Obtains the thread's JDBC connection.java.lang.Throwable
getFailureCause()
Checks whether an exception occurred during execution.ConcurrentTestCommand
getFailureCommand()
java.lang.String
getFailureLocation()
Returns location (e.g., command number) for exception returned bygetFailureCause()
.java.sql.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.java.lang.Integer
getThreadId()
private void
handleError(java.lang.Throwable error, java.lang.String when, ConcurrentTestCommand command)
Handles details of an exception during execution.void
run()
Executes the configured commands.void
setStatement(java.sql.Statement stmt)
Sets the thread's current JDBC statement.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
threadId
private java.lang.Integer threadId
The id for this thread.
-
jdbcURL
private java.lang.String jdbcURL
JDBC URL to connect with.
-
jdbcProps
private java.util.Properties jdbcProps
JDBC Connection properties.
-
commands
private java.lang.Iterable<ConcurrentTestCommand> commands
Command sequence for this thread.
-
synchronizer
private ConcurrentTestCommandExecutor.Sync synchronizer
Used to synchronize command execution.
-
connection
private java.sql.Connection connection
JDBC connection for commands.
-
statement
private java.sql.Statement statement
Current JDBC Statement. May be null.
-
error
private java.lang.Throwable error
First exception thrown by the thread.
-
when
private java.lang.String when
Location oferror
.
-
debugPrintStream
private final java.io.PrintStream debugPrintStream
Debugging print stream. May be null.
-
errorCommand
private ConcurrentTestCommand errorCommand
Command throwing error *
-
-
Constructor Detail
-
ConcurrentTestCommandExecutor
ConcurrentTestCommandExecutor(int threadId, java.lang.String threadName, java.lang.String jdbcURL, java.util.Properties jdbcProps, java.lang.Iterable<ConcurrentTestCommand> commands, ConcurrentTestCommandExecutor.Sync synchronizer, java.io.PrintStream debugPrintStream)
Constructs a ConcurrentTestCommandExecutor with the given thread ID, JDBC URL, commands and synchronization object.- Parameters:
threadId
- the thread ID (seeConcurrentTestCommandGenerator
)threadName
- the thread's namejdbcURL
- the JDBC URL to connect tojdbcProps
- JDBC Connection properties (user, password, etc.)commands
- the sequence of commands to execute -- null elements indicate no-opssynchronizer
- synchronization object (may not be null);debugPrintStream
- if non-null a PrintStream to use for debugging output (may help debugging thread synchronization
-
-
Method Detail
-
run
public void run()
Executes the configured commands.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
handleError
private void handleError(java.lang.Throwable error, java.lang.String when, ConcurrentTestCommand command)
Handles details of an exception during execution.
-
getConnection
public java.sql.Connection getConnection()
Obtains the thread's JDBC connection.
-
getStatement
public java.sql.Statement getStatement()
Obtains the thread's current JDBC statement. May return null.
-
setStatement
public void setStatement(java.sql.Statement stmt)
Sets the thread's current JDBC statement. To clear the JDBC statement useclearStatement()
.
-
clearStatement
public void clearStatement()
Clears the thread's current JDBC statement. To set the JDBC statement usesetStatement(Statement)
.
-
getSynchronizer
public ConcurrentTestCommandExecutor.Sync getSynchronizer()
Retrieves the object used to synchronize threads at a point in the list of commands.
-
getFailureCause
public java.lang.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, seegetFailureLocation()
for details on which command caused the failure.
-
getFailureLocation
public java.lang.String getFailureLocation()
Returns location (e.g., command number) for exception returned bygetFailureCause()
.
-
getFailureCommand
public ConcurrentTestCommand getFailureCommand()
-
getThreadId
public java.lang.Integer getThreadId()
-
-