|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eigenbase.test.concurrent.ConcurrentTestCommandGenerator
public class ConcurrentTestCommandGenerator
ConcurrentTestCommandGenerator creates instances of ConcurrentTestCommand
that perform specific actions in a specific
order and within the context of a test thread (ConcurrentTestCommandExecutor
).
Typical actions include preparing a SQL statement for execution, executing the statement and verifying its result set, and closing the statement.
A single ConcurrentTestCommandGenerator creates commands for multiple threads. Each thread is represented by an integer "thread ID". Thread IDs may take on any positive integer value and may be a sparse set (e.g. 1, 2, 5).
When each command is created, it is associated with a thread and given an execution order. Execution order values are positive integers, must be unique within a thread, and may be a sparse set.
There are no restrictions on the order of command creation.
Nested Class Summary | |
---|---|
protected static class |
ConcurrentTestCommandGenerator.AbstractCommand
abstract base to handle SQLExceptions |
(package private) static class |
ConcurrentTestCommandGenerator.AutoSynchronizationCommand
AutoSynchronizationCommand is idential to SynchronizationCommand, except that it is generated automatically by the test harness and is not counted when displaying the step number in which an error occurred. |
private static class |
ConcurrentTestCommandGenerator.CloseCommand
CloseCommand closes a previously prepared statement. |
private static class |
ConcurrentTestCommandGenerator.CommandWithTimeout
|
private static class |
ConcurrentTestCommandGenerator.CommitCommand
CommitCommand commits pending transactions via Connection.commit() . |
private static class |
ConcurrentTestCommandGenerator.DdlCommand
DdlCommand executes DDL commands. |
private static class |
ConcurrentTestCommandGenerator.ExplainCommand
ExplainCommand executes explain plan commands. |
static class |
ConcurrentTestCommandGenerator.FailedThread
Describes a thread that failed |
private static class |
ConcurrentTestCommandGenerator.FetchAndCompareCommand
FetchAndCompareCommand executes a previously prepared statement stored in the ConcurrentTestCommandExecutor and then validates the returned rows against expected data. |
private static class |
ConcurrentTestCommandGenerator.InsertCommand
InsertCommand exeutes an insert, update or delete SQL statement. |
private static class |
ConcurrentTestCommandGenerator.PrepareCommand
PrepareCommand creates a PreparedStatement . |
private static class |
ConcurrentTestCommandGenerator.RollbackCommand
RollbackCommand rolls back pending transactions via Connection.rollback() . |
private static class |
ConcurrentTestCommandGenerator.SleepCommand
SleepCommand causes the execution thread to wait for all other threads in the test before continuing. |
(package private) static class |
ConcurrentTestCommandGenerator.SynchronizationCommand
SynchronizationCommand causes the execution thread to wait for all other threads in the test before continuing. |
Field Summary | |
---|---|
private static char |
APOS
|
private static char |
COMMA
|
protected boolean |
debug
|
protected PrintStream |
debugStream
|
private List<ConcurrentTestCommandGenerator.FailedThread> |
failedThreads
Collects threads that failed. |
protected Properties |
jdbcProps
|
protected String |
jdbcURL
|
private static char |
LEFT_BRACKET
|
private static char |
RIGHT_BRACKET
|
private TreeMap<Integer,TreeMap<Integer,ConcurrentTestCommand>> |
threadMap
Maps Integer thread IDs to a TreeMap. |
private TreeMap<Integer,String> |
threadNameMap
Maps Integer thread IDs to thread names. |
Constructor Summary | |
---|---|
ConcurrentTestCommandGenerator()
Constructs a new ConcurrentTestCommandGenerator. |
Method Summary | |
---|---|
ConcurrentTestCommand |
addCloseCommand(int threadId,
int order)
Closes a previously prepared
SQL statement. |
protected ConcurrentTestCommand |
addCommand(int threadId,
int order,
ConcurrentTestCommand command)
Handles adding a command to threadMap . |
ConcurrentTestCommand |
addCommitCommand(int threadId,
int order)
Commits pending transaction on the thread's connection. |
ConcurrentTestCommand |
addDdlCommand(int threadId,
int order,
String ddl)
Executes a DDL statement immediately. |
ConcurrentTestCommand |
addExplainCommand(int threadId,
int order,
String sql)
Adds an "explain plan" command. |
ConcurrentTestCommand |
addFetchAndCompareCommand(int threadId,
int order,
int timeout,
String expected)
Executes a previously prepared SQL statement and compares its ResultSet to the given
data. |
ConcurrentTestCommand |
addInsertCommand(int threadId,
int order,
int timeout,
String sql)
Executes the given SQL via Statement.executeUpdate(String) . |
ConcurrentTestCommand |
addPrepareCommand(int threadId,
int order,
String sql)
Creates a PreparedStatement for the given SQL. |
ConcurrentTestCommand |
addRollbackCommand(int threadId,
int order)
Rolls back pending transaction on the thread's connection. |
ConcurrentTestCommand |
addSleepCommand(int threadId,
int order,
long millis)
Causes the given thread to sleep for the indicated number of milliseconds. |
ConcurrentTestCommand |
addSynchronizationCommand(int threadId,
int order)
Adds a synchronization commands. |
(package private) void |
customErrorHandler(ConcurrentTestCommandExecutor executor)
Custom error handling occurs here if requiresCustomErrorHandling() returns true. |
void |
execute()
Creates a ConcurrentTestCommandExecutor object for each define thread,
and then runs them all. |
boolean |
failed()
Returns whether any test thread failed. |
(package private) Iterator |
getCommandIterator(Integer threadId)
Returns an Iterator of ConcurrentTestCommand
objects for the given thread ID. |
(package private) Collection |
getCommands(Integer threadId)
Returns a Collection of ConcurrentTestCommand
objects for the given thread ID. |
List<ConcurrentTestCommandGenerator.FailedThread> |
getFailedThreads()
|
protected Set<Integer> |
getThreadIds()
Returns a set of thread IDs. |
protected String |
getThreadName(Integer threadId)
Retrieves the name of a given thread. |
boolean |
hasValidSynchronization()
Validates that all threads have the same number of SynchronizationCommands (otherwise a deadlock is guaranteed). |
protected ConcurrentTestCommandExecutor[] |
innerExecute()
|
protected void |
postExecute(ConcurrentTestCommandExecutor[] threads)
|
(package private) void |
printCommands(PrintStream out,
Integer threadId)
Prints a description of the commands to be executed for a given thread. |
(package private) boolean |
requiresCustomErrorHandling()
Indicates whether commands generated by this generator require special handling. |
void |
setDataSource(String jdbcURL,
Properties jdbcProps)
Sets the jdbc data source for executing the command threads. |
protected void |
setDebug(boolean enabled)
|
protected void |
setDebug(boolean enabled,
PrintStream alternatePrintStream)
|
void |
setThreadName(int threadId,
String name)
Configures a human-readable name for a given thread identifier. |
void |
synchronizeCommandSets()
Insures that the number of commands is the same for each thread, fills missing order value with null commands, and interleaves a synchronization command before each actual command. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final char APOS
private static final char COMMA
private static final char LEFT_BRACKET
private static final char RIGHT_BRACKET
protected boolean debug
protected PrintStream debugStream
protected String jdbcURL
protected Properties jdbcProps
private TreeMap<Integer,TreeMap<Integer,ConcurrentTestCommand>> threadMap
ConcurrentTestCommand
.
private TreeMap<Integer,String> threadNameMap
private List<ConcurrentTestCommandGenerator.FailedThread> failedThreads
Constructor Detail |
---|
public ConcurrentTestCommandGenerator()
Method Detail |
---|
public ConcurrentTestCommand addSynchronizationCommand(int threadId, int order)
Object.notifyAll()
). Each thread must
have exactly the same number of synchronization commands.
threadId
- the thread that should execute this commandorder
- the execution order
public ConcurrentTestCommand addSleepCommand(int threadId, int order, long millis)
Thread.sleep(long)
.
threadId
- the thread that should execute this commandorder
- the execution ordermillis
- the length of time to sleep in milliseconds (must not be
negative)
public ConcurrentTestCommand addExplainCommand(int threadId, int order, String sql)
threadId
- the thread that should execute this commandorder
- the execution ordersql
- the explain plan SQL (e.g. "explain plan for select *
from t"
)
public ConcurrentTestCommand addPrepareCommand(int threadId, int order, String sql)
PreparedStatement
for the given SQL. This command does
not execute the SQL, it merely creates a PreparedStatement and stores it
in the ConcurrentTestCommandExecutor.
threadId
- the thread that should execute this commandorder
- the execution ordersql
- the SQL to prepare (e.g. "select * from t"
)
addFetchAndCompareCommand(int, int, int, String)
public ConcurrentTestCommand addFetchAndCompareCommand(int threadId, int order, int timeout, String expected)
prepared
SQL statement and compares its ResultSet
to the given
data.
Expected data format: { 'row1, col1 value', 'row1, col2
value', ... }, { 'row2, col1 value', 'row2, col2 value', ... },
...
null
without quotes.{ 'foo', 10, 3.14, null }
Note on timeout: If the previously prepared statement's Statement.setQueryTimeout(int)
method throws an
UnsupportedOperationException
it is ignored and no timeout is set.
threadId
- the thread that should execute this commandorder
- the execution ordertimeout
- the query timeout, in seconds (see above)expected
- the expected results (see above)
public ConcurrentTestCommand addCloseCommand(int threadId, int order)
prepared
SQL statement.
threadId
- the thread that should execute this commandorder
- the execution order
public ConcurrentTestCommand addInsertCommand(int threadId, int order, int timeout, String sql)
Statement.executeUpdate(String)
. May
be used for update as well as insert statements.
Note on timeout: If the previously prepared statement's Statement.setQueryTimeout(int)
method throws an
UnsupportedOperationException
it is ignored and no timeout is set.
threadId
- the thread that should execute this commandorder
- the execution ordertimeout
- the query timeout, in seconds (see above)sql
- the insert/update/delete SQL
public ConcurrentTestCommand addCommitCommand(int threadId, int order)
threadId
- the thread that should execute this commandorder
- the execution order
public ConcurrentTestCommand addRollbackCommand(int threadId, int order)
threadId
- the thread that should execute this commandorder
- the execution order
public ConcurrentTestCommand addDdlCommand(int threadId, int order, String ddl)
protected ConcurrentTestCommand addCommand(int threadId, int order, ConcurrentTestCommand command)
threadMap
.
public void setThreadName(int threadId, String name)
protected void setDebug(boolean enabled)
protected void setDebug(boolean enabled, PrintStream alternatePrintStream)
public void setDataSource(String jdbcURL, Properties jdbcProps)
public void execute() throws Exception
ConcurrentTestCommandExecutor
object for each define thread,
and then runs them all.
Exception
- if no connection found or if a thread operation is
interruptedprotected ConcurrentTestCommandExecutor[] innerExecute() throws Exception
Exception
protected void postExecute(ConcurrentTestCommandExecutor[] threads) throws Exception
Exception
public boolean failed()
execute()
has
returned.
public List<ConcurrentTestCommandGenerator.FailedThread> getFailedThreads()
public void synchronizeCommandSets()
public boolean hasValidSynchronization()
protected Set<Integer> getThreadIds()
protected String getThreadName(Integer threadId)
boolean requiresCustomErrorHandling()
void customErrorHandler(ConcurrentTestCommandExecutor executor)
requiresCustomErrorHandling()
returns true. Default implementation does
nothing.
Collection getCommands(Integer threadId)
Collection
of ConcurrentTestCommand
objects for the given thread ID.
Iterator getCommandIterator(Integer threadId)
Iterator
of ConcurrentTestCommand
objects for the given thread ID.
void printCommands(PrintStream out, Integer threadId)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |