org.eigenbase.test.concurrent
Class ConcurrentTestCommandScript

java.lang.Object
  extended by org.eigenbase.test.concurrent.ConcurrentTestCommandGenerator
      extended by org.eigenbase.test.concurrent.ConcurrentTestCommandScript

public class ConcurrentTestCommandScript
extends ConcurrentTestCommandGenerator

ConcurrentTestCommandScript creates instances of ConcurrentTestCommand that perform specific actions in a specific order and within the context of a test thread (ConcurrentTestCommandExecutor).

Actions are loaded from a script (see package javadoc for script format).

A single ConcurrentTestCommandScript creates commands for multiple threads. Each thread is represented by an integer "thread ID" and, optionally, a String thread name. Thread IDs may take on any positive integer value and may be a sparse set (e.g. 1, 2, 5). Thread names may be any String.

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. See ConcurrentTestCommandGenerator.synchronizeCommandSets() for other considerations.

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

Nested Class Summary
private  class ConcurrentTestCommandScript.CommandParser
           
private static class ConcurrentTestCommandScript.CommandWithTimeout
           
private static class ConcurrentTestCommandScript.CommandWithTimeoutAndRowLimit
           
private  class ConcurrentTestCommandScript.EchoCommand
           
private  class ConcurrentTestCommandScript.FetchAndPrintCommand
          FetchAndPrintCommand executes a previously prepared statement stored inthe ConcurrentTestCommandExecutor and then outputs the returned rows.
private  class ConcurrentTestCommandScript.PrepareCommand
          PrepareCommand creates a PreparedStatement, which is saved as the current statement of its test thread.
private  class ConcurrentTestCommandScript.PrintCommand
           
private  class ConcurrentTestCommandScript.ResultsReader
           
private  class ConcurrentTestCommandScript.SelectCommand
          SelectCommand creates and executes a SQL select statement, with optional timeout and row limit.
private  class ConcurrentTestCommandScript.ShellCommand
           
private  class ConcurrentTestCommandScript.SqlCommand
          SelectCommand creates and executes a SQL select statement, with optional timeout.
private static class ConcurrentTestCommandScript.StateAction
           
private static class ConcurrentTestCommandScript.StateDatum
           
private static class ConcurrentTestCommandScript.Tool
           
private  class ConcurrentTestCommandScript.VariableTable
           
 
Nested classes/interfaces inherited from class org.eigenbase.test.concurrent.ConcurrentTestCommandGenerator
ConcurrentTestCommandGenerator.AbstractCommand, ConcurrentTestCommandGenerator.AutoSynchronizationCommand, ConcurrentTestCommandGenerator.FailedThread, ConcurrentTestCommandGenerator.SynchronizationCommand
 
Field Summary
private static int BUF_SIZE
           
private static String CLEANUP
           
private static String CLEANUP_STATE
           
private static Integer CLEANUP_THREAD_ID
           
private  List<String> cleanupCommands
           
private static String CLOSE
           
private static char[] dashes
           
private  Boolean disabled
           
private static String DISABLED
           
private static String ECHO
           
private static int ECHO_LEN
           
private static String ENABLED
           
private static String END
           
private static String EOF
           
private static String EOF_STATE
           
private static String ERR
           
private static int ERR_LEN
           
private  long executionStartTime
           
private static String FETCH
           
private static int FETCH_LEN
           
private static String INCLUDE
           
private static int INCLUDE_LEN
           
private  Boolean lockstep
           
private static String LOCKSTEP
           
private static String NOLOCKSTEP
           
private static String POST_CLEANUP_STATE
           
private static String POST_SETUP_STATE
           
private static String POST_THREAD_STATE
           
private static String PRE_SETUP_STATE
           
private static String PREPARE
           
private static int PREPARE_LEN
           
private static String PRINT
           
private static int PRINT_LEN
           
private  boolean quiet
           
private static String REPEAT
           
private static int REPEAT_LEN
           
private static int REPEAT_READ_AHEAD_LIMIT
           
private static String REPEAT_STATE
           
private static String ROWLIMIT
           
private static int ROWLIMIT_LEN
           
private  File scriptDirectory
           
private static String SETUP
           
private static String SETUP_STATE
           
private static Integer SETUP_THREAD_ID
           
private  List<String> setupCommands
           
private static String SHELL
           
private static int SHELL_LEN
           
private  Pattern shellWildcardPattern
           
private static String SLEEP
           
private static int SLEEP_LEN
           
private static char[] spaces
           
private static String SQL
           
private static String SQL_STATE
           
private static ConcurrentTestCommandScript.StateAction[] STATE_TABLE
           
private static String SYNC
           
private static String THREAD
           
private static int THREAD_LEN
           
private static String THREAD_STATE
           
private  Map<Integer,BufferedWriter> threadBufferedWriters
           
private  Map<Integer,ConcurrentTestCommandScript.ResultsReader> threadResultsReaders
           
private  Map<Integer,StringWriter> threadStringWriters
           
private static String TIMEOUT
           
private static int TIMEOUT_LEN
           
private static String VAR
           
private static int VAR_LEN
           
private  ConcurrentTestCommandScript.VariableTable vars
           
private  boolean verbose
           
 
Fields inherited from class org.eigenbase.test.concurrent.ConcurrentTestCommandGenerator
debug, debugStream, jdbcProps, jdbcURL
 
Constructor Summary
ConcurrentTestCommandScript()
           
ConcurrentTestCommandScript(String filename)
          Constructs and prepares a new ConcurrentTestCommandScript.
 
Method Summary
private  void addThreadWriters(Integer threadId)
           
private  Map<Integer,String[]> collectResults()
          Builds a map of thread ids to result data for the thread.
(package private)  void customErrorHandler(ConcurrentTestCommandExecutor executor)
          Custom error handling occurs here if ConcurrentTestCommandGenerator.requiresCustomErrorHandling() returns true.
 void execute()
          Executes the script
 void executeCleanup()
           
protected  void executeCommands(int threadID, List<String> commands)
           
 void executeSetup()
           
private  String getFormattedThreadName(Integer id)
           
private  BufferedWriter getThreadWriter(Integer threadId)
          Retrieves the output stream for the given thread id.
 boolean isDisabled()
           
private  boolean isSelect(String sql)
          Determines if a block of SQL is a select statment or not.
static void main(String[] args)
          Client tool that connects via jdbc and runs one or more mtsql on that connection.
private  void prepare(String filename, List<String> bindings)
          Gets ready to execute: loads script FILENAME applying external variable BINDINGS.
 void printResults(BufferedWriter out)
           
private  void printThreadResults(BufferedWriter out, String[] threadResult)
           
(package private)  boolean requiresCustomErrorHandling()
          Causes errors to be send here for custom handling.
 void setQuiet(boolean val)
           
 void setVerbose(boolean val)
           
private  void storeMessage(Integer threadId, String message)
          Saves a message to be printed with the thread's output.
private  void storeResults(Integer threadId, ResultSet rset, boolean withTimeout)
           
private  void storeSql(Integer threadId, String sql)
          Saves a SQL command to be printed with the thread's output.
 boolean useLockstep()
           
 
Methods inherited from class org.eigenbase.test.concurrent.ConcurrentTestCommandGenerator
addCloseCommand, addCommand, addCommitCommand, addDdlCommand, addExplainCommand, addFetchAndCompareCommand, addInsertCommand, addPrepareCommand, addRollbackCommand, addSleepCommand, addSynchronizationCommand, failed, getCommandIterator, getCommands, getFailedThreads, getThreadIds, getThreadName, hasValidSynchronization, innerExecute, postExecute, printCommands, setDataSource, setDebug, setDebug, setThreadName, synchronizeCommandSets
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRE_SETUP_STATE

private static final String PRE_SETUP_STATE
See Also:
Constant Field Values

SETUP_STATE

private static final String SETUP_STATE
See Also:
Constant Field Values

POST_SETUP_STATE

private static final String POST_SETUP_STATE
See Also:
Constant Field Values

CLEANUP_STATE

private static final String CLEANUP_STATE
See Also:
Constant Field Values

POST_CLEANUP_STATE

private static final String POST_CLEANUP_STATE
See Also:
Constant Field Values

THREAD_STATE

private static final String THREAD_STATE
See Also:
Constant Field Values

REPEAT_STATE

private static final String REPEAT_STATE
See Also:
Constant Field Values

SQL_STATE

private static final String SQL_STATE
See Also:
Constant Field Values

POST_THREAD_STATE

private static final String POST_THREAD_STATE
See Also:
Constant Field Values

EOF_STATE

private static final String EOF_STATE
See Also:
Constant Field Values

VAR

private static final String VAR
See Also:
Constant Field Values

LOCKSTEP

private static final String LOCKSTEP
See Also:
Constant Field Values

NOLOCKSTEP

private static final String NOLOCKSTEP
See Also:
Constant Field Values

ENABLED

private static final String ENABLED
See Also:
Constant Field Values

DISABLED

private static final String DISABLED
See Also:
Constant Field Values

SETUP

private static final String SETUP
See Also:
Constant Field Values

CLEANUP

private static final String CLEANUP
See Also:
Constant Field Values

END

private static final String END
See Also:
Constant Field Values

THREAD

private static final String THREAD
See Also:
Constant Field Values

REPEAT

private static final String REPEAT
See Also:
Constant Field Values

SYNC

private static final String SYNC
See Also:
Constant Field Values

TIMEOUT

private static final String TIMEOUT
See Also:
Constant Field Values

ROWLIMIT

private static final String ROWLIMIT
See Also:
Constant Field Values

PREPARE

private static final String PREPARE
See Also:
Constant Field Values

PRINT

private static final String PRINT
See Also:
Constant Field Values

FETCH

private static final String FETCH
See Also:
Constant Field Values

CLOSE

private static final String CLOSE
See Also:
Constant Field Values

SLEEP

private static final String SLEEP
See Also:
Constant Field Values

ERR

private static final String ERR
See Also:
Constant Field Values

ECHO

private static final String ECHO
See Also:
Constant Field Values

INCLUDE

private static final String INCLUDE
See Also:
Constant Field Values

SHELL

private static final String SHELL
See Also:
Constant Field Values

SQL

private static final String SQL
See Also:
Constant Field Values

EOF

private static final String EOF

STATE_TABLE

private static final ConcurrentTestCommandScript.StateAction[] STATE_TABLE

FETCH_LEN

private static final int FETCH_LEN

PREPARE_LEN

private static final int PREPARE_LEN

PRINT_LEN

private static final int PRINT_LEN

REPEAT_LEN

private static final int REPEAT_LEN

SLEEP_LEN

private static final int SLEEP_LEN

THREAD_LEN

private static final int THREAD_LEN

TIMEOUT_LEN

private static final int TIMEOUT_LEN

ROWLIMIT_LEN

private static final int ROWLIMIT_LEN

ERR_LEN

private static final int ERR_LEN

ECHO_LEN

private static final int ECHO_LEN

SHELL_LEN

private static final int SHELL_LEN

INCLUDE_LEN

private static final int INCLUDE_LEN

VAR_LEN

private static final int VAR_LEN

spaces

private static final char[] spaces

dashes

private static final char[] dashes

BUF_SIZE

private static final int BUF_SIZE
See Also:
Constant Field Values

REPEAT_READ_AHEAD_LIMIT

private static final int REPEAT_READ_AHEAD_LIMIT
See Also:
Constant Field Values

SETUP_THREAD_ID

private static final Integer SETUP_THREAD_ID

CLEANUP_THREAD_ID

private static final Integer CLEANUP_THREAD_ID

quiet

private boolean quiet

verbose

private boolean verbose

lockstep

private Boolean lockstep

disabled

private Boolean disabled

vars

private ConcurrentTestCommandScript.VariableTable vars

scriptDirectory

private File scriptDirectory

executionStartTime

private long executionStartTime

setupCommands

private List<String> setupCommands

cleanupCommands

private List<String> cleanupCommands

threadBufferedWriters

private Map<Integer,BufferedWriter> threadBufferedWriters

threadStringWriters

private Map<Integer,StringWriter> threadStringWriters

threadResultsReaders

private Map<Integer,ConcurrentTestCommandScript.ResultsReader> threadResultsReaders

shellWildcardPattern

private final Pattern shellWildcardPattern
Constructor Detail

ConcurrentTestCommandScript

public ConcurrentTestCommandScript()
                            throws IOException
Throws:
IOException

ConcurrentTestCommandScript

public ConcurrentTestCommandScript(String filename)
                            throws IOException
Constructs and prepares a new ConcurrentTestCommandScript.

Throws:
IOException
Method Detail

prepare

private void prepare(String filename,
                     List<String> bindings)
              throws IOException
Gets ready to execute: loads script FILENAME applying external variable BINDINGS.

Throws:
IOException

execute

public void execute()
             throws Exception
Executes the script

Overrides:
execute in class ConcurrentTestCommandGenerator
Throws:
Exception - if no connection found or if a thread operation is interrupted

addThreadWriters

private void addThreadWriters(Integer threadId)

setQuiet

public void setQuiet(boolean val)

setVerbose

public void setVerbose(boolean val)

useLockstep

public boolean useLockstep()

isDisabled

public boolean isDisabled()

executeSetup

public void executeSetup()
                  throws Exception
Throws:
Exception

executeCleanup

public void executeCleanup()
                    throws Exception
Throws:
Exception

executeCommands

protected void executeCommands(int threadID,
                               List<String> commands)
                        throws Exception
Throws:
Exception

storeResults

private void storeResults(Integer threadId,
                          ResultSet rset,
                          boolean withTimeout)
                   throws SQLException
Throws:
SQLException

isSelect

private boolean isSelect(String sql)
Determines if a block of SQL is a select statment or not.


collectResults

private Map<Integer,String[]> collectResults()
Builds a map of thread ids to result data for the thread. Each result datum is an String[2] containing the thread name and the thread's output.

Returns:
the map.

getFormattedThreadName

private String getFormattedThreadName(Integer id)

printResults

public void printResults(BufferedWriter out)
                  throws IOException
Throws:
IOException

printThreadResults

private void printThreadResults(BufferedWriter out,
                                String[] threadResult)
                         throws IOException
Throws:
IOException

requiresCustomErrorHandling

boolean requiresCustomErrorHandling()
Causes errors to be send here for custom handling. See customErrorHandler(ConcurrentTestCommandExecutor).

Overrides:
requiresCustomErrorHandling in class ConcurrentTestCommandGenerator

customErrorHandler

void customErrorHandler(ConcurrentTestCommandExecutor executor)
Description copied from class: ConcurrentTestCommandGenerator
Custom error handling occurs here if ConcurrentTestCommandGenerator.requiresCustomErrorHandling() returns true. Default implementation does nothing.

Overrides:
customErrorHandler in class ConcurrentTestCommandGenerator

getThreadWriter

private BufferedWriter getThreadWriter(Integer threadId)
Retrieves the output stream for the given thread id.

Returns:
a BufferedWriter on a StringWriter for the thread.

storeSql

private void storeSql(Integer threadId,
                      String sql)
Saves a SQL command to be printed with the thread's output.


storeMessage

private void storeMessage(Integer threadId,
                          String message)
Saves a message to be printed with the thread's output.


main

public static void main(String[] args)
Client tool that connects via jdbc and runs one or more mtsql on that connection.

Usage: mtsql [-vgq] -u SERVER -d DRIVER [-n USER][-p PASSWORD] [VAR=VAL]... SCRIPT [SCRIPT]...