Class 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.

    • Field Detail

      • POST_SETUP_STATE

        private static final java.lang.String POST_SETUP_STATE
        See Also:
        Constant Field Values
      • POST_CLEANUP_STATE

        private static final java.lang.String POST_CLEANUP_STATE
        See Also:
        Constant Field Values
      • POST_THREAD_STATE

        private static final java.lang.String POST_THREAD_STATE
        See Also:
        Constant Field Values
      • EOF

        private static final java.lang.String EOF
      • 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
      • PLUGIN_LEN

        private static final int PLUGIN_LEN
      • INCLUDE_LEN

        private static final int INCLUDE_LEN
      • VAR_LEN

        private static final int VAR_LEN
      • REPEAT_READ_AHEAD_LIMIT

        private static final int REPEAT_READ_AHEAD_LIMIT
        See Also:
        Constant Field Values
      • SPACES

        private static final char[] SPACES
      • DASHES

        private static final char[] DASHES
      • SETUP_THREAD_ID

        private static final java.lang.Integer SETUP_THREAD_ID
      • CLEANUP_THREAD_ID

        private static final java.lang.Integer CLEANUP_THREAD_ID
      • quiet

        private boolean quiet
      • verbose

        private boolean verbose
      • lockstep

        private java.lang.Boolean lockstep
      • disabled

        private java.lang.Boolean disabled
      • scriptDirectory

        private java.io.File scriptDirectory
      • scriptStartTime

        private long scriptStartTime
      • pluginForCommand

        private final java.util.Map<java.lang.String,​ConcurrentTestPlugin> pluginForCommand
      • preSetupPluginForCommand

        private final java.util.Map<java.lang.String,​ConcurrentTestPlugin> preSetupPluginForCommand
      • setupCommands

        private final java.util.List<java.lang.String> setupCommands
      • cleanupCommands

        private final java.util.List<java.lang.String> cleanupCommands
      • threadBufferedWriters

        private final java.util.Map<java.lang.Integer,​java.io.BufferedWriter> threadBufferedWriters
      • threadStringWriters

        private final java.util.Map<java.lang.Integer,​java.io.StringWriter> threadStringWriters
      • shellWildcardPattern

        private final java.util.regex.Pattern shellWildcardPattern
    • Constructor Detail

      • ConcurrentTestCommandScript

        public ConcurrentTestCommandScript()
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • ConcurrentTestCommandScript

        public ConcurrentTestCommandScript​(java.lang.String filename)
                                    throws java.io.IOException
        Constructs and prepares a new ConcurrentTestCommandScript.
        Throws:
        java.io.IOException
    • Method Detail

      • fill

        private static char[] fill​(char[] chars,
                                   char c)
      • runAppProcess

        static int runAppProcess​(java.lang.ProcessBuilder pb,
                                 org.slf4j.Logger logger,
                                 java.io.Reader appInput,
                                 java.io.Writer appOutput)
                          throws java.io.IOException,
                                 java.lang.InterruptedException
        Runs an external application process.
        Parameters:
        pb - ProcessBuilder for the application
        logger - if not null, command and exit status will be logged here
        appInput - if not null, data will be copied to application's stdin
        appOutput - if not null, data will be captured from application's stdout and stderr
        Returns:
        application process exit value
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • prepare

        private void prepare​(java.lang.String filename,
                             java.util.List<java.lang.String> bindings)
                      throws java.io.IOException
        Gets ready to execute: loads script FILENAME applying external variable BINDINGS
        Throws:
        java.io.IOException
      • execute

        public void execute()
                     throws java.lang.Exception
        Executes the script
        Overrides:
        execute in class ConcurrentTestCommandGenerator
        Throws:
        java.lang.Exception - if no connection found or if a thread operation is interrupted
      • addThreadWriters

        private void addThreadWriters​(java.lang.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 java.lang.Exception
        Throws:
        java.lang.Exception
      • executeCleanup

        public void executeCleanup()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • executeCommands

        protected void executeCommands​(int threadId,
                                       java.util.List<java.lang.String> commands)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • storeResults

        private void storeResults​(java.lang.Integer threadId,
                                  java.sql.ResultSet rset,
                                  long timeout)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • isComment

        private boolean isComment​(java.lang.String line)
        Identifies the start of a comment line; same rules as sqlline
      • asBoolValue

        private boolean asBoolValue​(java.lang.String s)
        translates argument of !set force etc.
      • isSelect

        private boolean isSelect​(java.lang.String sql)
        Determines whether a block of SQL is a SELECT statement.
      • collectResults

        private java.util.Map<java.lang.Integer,​java.lang.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 java.lang.String getFormattedThreadName​(java.lang.Integer id)
      • printResults

        public void printResults​(java.io.PrintWriter out)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • printThreadResults

        private void printThreadResults​(java.io.PrintWriter out,
                                        java.lang.String[] threadResult)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getThreadWriter

        private java.io.BufferedWriter getThreadWriter​(java.lang.Integer threadId)
        Retrieves the output stream for the given thread id.
        Returns:
        a BufferedWriter on a StringWriter for the thread.
      • storeSql

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

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

        public static void main​(java.lang.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]...