Class ConcurrentTestCommandScript
- java.lang.Object
-
- org.apache.calcite.test.concurrent.ConcurrentTestCommandGenerator
-
- org.apache.calcite.test.concurrent.ConcurrentTestCommandScript
-
public class ConcurrentTestCommandScript extends ConcurrentTestCommandGenerator
ConcurrentTestCommandScript creates instances ofConcurrentTestCommand
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ConcurrentTestCommandScript.CommandParser
Command parser.private static class
ConcurrentTestCommandScript.CommandWithTimeout
Command that has a timeout.private static class
ConcurrentTestCommandScript.CommandWithTimeoutAndRowLimit
Command with timeout and row limit.private class
ConcurrentTestCommandScript.EchoCommand
Echo command.private class
ConcurrentTestCommandScript.FetchAndPrintCommand
FetchAndPrintCommand executes a previously prepared statement stored inthe ConcurrentTestCommandExecutor and then outputs the returned rows.private class
ConcurrentTestCommandScript.PluginCommand
Plugin command.private class
ConcurrentTestCommandScript.PrepareCommand
PrepareCommand creates aPreparedStatement
, which is saved as the current statement of its test thread.private class
ConcurrentTestCommandScript.PrintCommand
Print command.private class
ConcurrentTestCommandScript.ResultsReader
Result reader.private class
ConcurrentTestCommandScript.SelectCommand
SelectCommand creates and executes a SQL select statement, with optional timeout and row limit.private class
ConcurrentTestCommandScript.ShellCommand
Shell command.private class
ConcurrentTestCommandScript.SqlCommand
SelectCommand creates and executes a SQL select statement, with optional timeout.private static class
ConcurrentTestCommandScript.StateAction
State action.private static class
ConcurrentTestCommandScript.StateDatum
State datum.private static class
ConcurrentTestCommandScript.Tool
Standalone client test tool.private class
ConcurrentTestCommandScript.VariableTable
Symbol table of script variables.-
Nested classes/interfaces inherited from class org.apache.calcite.test.concurrent.ConcurrentTestCommandGenerator
ConcurrentTestCommandGenerator.AbstractCommand, ConcurrentTestCommandGenerator.AutoSynchronizationCommand, ConcurrentTestCommandGenerator.FailedThread, ConcurrentTestCommandGenerator.SynchronizationCommand
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BUF_SIZE
private static java.lang.String
CLEANUP
private static java.lang.String
CLEANUP_STATE
private static java.lang.Integer
CLEANUP_THREAD_ID
private java.util.List<java.lang.String>
cleanupCommands
private static java.lang.String
CLOSE
private static char[]
DASHES
private java.lang.Boolean
disabled
private static java.lang.String
DISABLED
private static java.lang.String
ECHO
private static int
ECHO_LEN
private static java.lang.String
ENABLED
private static java.lang.String
END
private static java.lang.String
EOF
private static java.lang.String
EOF_STATE
private static java.lang.String
ERR
private static int
ERR_LEN
private static java.lang.String
FETCH
private static int
FETCH_LEN
private static java.lang.String
INCLUDE
private static int
INCLUDE_LEN
private java.lang.Boolean
lockstep
private static java.lang.String
LOCKSTEP
private static java.lang.String
NOLOCKSTEP
private static java.lang.String
PLUGIN
private static int
PLUGIN_LEN
private java.util.Map<java.lang.String,ConcurrentTestPlugin>
pluginForCommand
private java.util.List<ConcurrentTestPlugin>
plugins
private static java.lang.String
POST_CLEANUP_STATE
private static java.lang.String
POST_SETUP_STATE
private static java.lang.String
POST_THREAD_STATE
private static java.lang.String
PRE_SETUP_STATE
private static java.lang.String
PREPARE
private static int
PREPARE_LEN
private java.util.Map<java.lang.String,ConcurrentTestPlugin>
preSetupPluginForCommand
private static java.lang.String
PRINT
private static int
PRINT_LEN
private boolean
quiet
private static java.lang.String
REPEAT
private static int
REPEAT_LEN
private static int
REPEAT_READ_AHEAD_LIMIT
private static java.lang.String
REPEAT_STATE
private static java.lang.String
ROWLIMIT
private static int
ROWLIMIT_LEN
private java.io.File
scriptDirectory
private long
scriptStartTime
private static java.lang.String
SETUP
private static java.lang.String
SETUP_STATE
private static java.lang.Integer
SETUP_THREAD_ID
private java.util.List<java.lang.String>
setupCommands
private static java.lang.String
SHELL
private static int
SHELL_LEN
private java.util.regex.Pattern
shellWildcardPattern
private static java.lang.String
SLEEP
private static int
SLEEP_LEN
private static char[]
SPACES
private static java.lang.String
SQL
private static java.lang.String
SQL_STATE
private static ConcurrentTestCommandScript.StateAction[]
STATE_TABLE
private static java.lang.String
SYNC
private static java.lang.String
THREAD
private static int
THREAD_LEN
private static java.lang.String
THREAD_STATE
private java.util.Map<java.lang.Integer,java.io.BufferedWriter>
threadBufferedWriters
private java.util.Map<java.lang.Integer,ConcurrentTestCommandScript.ResultsReader>
threadResultsReaders
private java.util.Map<java.lang.Integer,java.io.StringWriter>
threadStringWriters
private static java.lang.String
TIMEOUT
private static int
TIMEOUT_LEN
private static java.lang.String
VAR
private static int
VAR_LEN
private ConcurrentTestCommandScript.VariableTable
vars
private boolean
verbose
-
Fields inherited from class org.apache.calcite.test.concurrent.ConcurrentTestCommandGenerator
debug, debugStream, jdbcProps, jdbcURL
-
-
Constructor Summary
Constructors Constructor Description ConcurrentTestCommandScript()
ConcurrentTestCommandScript(java.lang.String filename)
Constructs and prepares a new ConcurrentTestCommandScript.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addThreadWriters(java.lang.Integer threadId)
private boolean
asBoolValue(java.lang.String s)
translates argument of !set force etc.private java.util.Map<java.lang.Integer,java.lang.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 ifConcurrentTestCommandGenerator.requiresCustomErrorHandling()
returns true.void
execute()
Executes the scriptvoid
executeCleanup()
protected void
executeCommands(int threadId, java.util.List<java.lang.String> commands)
void
executeSetup()
private static char[]
fill(char[] chars, char c)
private java.lang.String
getFormattedThreadName(java.lang.Integer id)
private java.io.BufferedWriter
getThreadWriter(java.lang.Integer threadId)
Retrieves the output stream for the given thread id.private boolean
isComment(java.lang.String line)
Identifies the start of a comment line; same rules as sqllineboolean
isDisabled()
private boolean
isSelect(java.lang.String sql)
Determines whether a block of SQL is a SELECT statement.static void
main(java.lang.String[] args)
Client tool that connects via jdbc and runs one or more mtsql on that connection.private void
prepare(java.lang.String filename, java.util.List<java.lang.String> bindings)
Gets ready to execute: loads script FILENAME applying external variable BINDINGSvoid
printResults(java.io.PrintWriter out)
private void
printThreadResults(java.io.PrintWriter out, java.lang.String[] threadResult)
(package private) boolean
requiresCustomErrorHandling()
Causes errors to be send here for custom handling.(package private) static int
runAppProcess(java.lang.ProcessBuilder pb, org.slf4j.Logger logger, java.io.Reader appInput, java.io.Writer appOutput)
Runs an external application process.void
setQuiet(boolean val)
void
setVerbose(boolean val)
private void
storeMessage(java.lang.Integer threadId, java.lang.String message)
Saves a message to be printed with the thread's output.private void
storeResults(java.lang.Integer threadId, java.sql.ResultSet rset, long timeout)
private void
storeSql(java.lang.Integer threadId, java.lang.String sql)
Saves a SQL command to be printed with the thread's output.boolean
useLockstep()
-
Methods inherited from class org.apache.calcite.test.concurrent.ConcurrentTestCommandGenerator
addCloseCommand, addCommand, addCommitCommand, addDdlCommand, addExplainCommand, addFetchAndCompareCommand, addInsertCommand, addPrepareCommand, addRollbackCommand, addSleepCommand, addSynchronizationCommand, failed, getCommandIterable, getCommands, getFailedThreads, getThreadIds, getThreadName, hasValidSynchronization, innerExecute, postExecute, printCommands, setDataSource, setDebug, setDebug, setThreadName, synchronizeCommandSets
-
-
-
-
Field Detail
-
PRE_SETUP_STATE
private static final java.lang.String PRE_SETUP_STATE
- See Also:
- Constant Field Values
-
SETUP_STATE
private static final java.lang.String SETUP_STATE
- See Also:
- Constant Field Values
-
POST_SETUP_STATE
private static final java.lang.String POST_SETUP_STATE
- See Also:
- Constant Field Values
-
CLEANUP_STATE
private static final java.lang.String CLEANUP_STATE
- See Also:
- Constant Field Values
-
POST_CLEANUP_STATE
private static final java.lang.String POST_CLEANUP_STATE
- See Also:
- Constant Field Values
-
THREAD_STATE
private static final java.lang.String THREAD_STATE
- See Also:
- Constant Field Values
-
REPEAT_STATE
private static final java.lang.String REPEAT_STATE
- See Also:
- Constant Field Values
-
SQL_STATE
private static final java.lang.String SQL_STATE
- See Also:
- Constant Field Values
-
POST_THREAD_STATE
private static final java.lang.String POST_THREAD_STATE
- See Also:
- Constant Field Values
-
EOF_STATE
private static final java.lang.String EOF_STATE
- See Also:
- Constant Field Values
-
VAR
private static final java.lang.String VAR
- See Also:
- Constant Field Values
-
LOCKSTEP
private static final java.lang.String LOCKSTEP
- See Also:
- Constant Field Values
-
NOLOCKSTEP
private static final java.lang.String NOLOCKSTEP
- See Also:
- Constant Field Values
-
ENABLED
private static final java.lang.String ENABLED
- See Also:
- Constant Field Values
-
DISABLED
private static final java.lang.String DISABLED
- See Also:
- Constant Field Values
-
SETUP
private static final java.lang.String SETUP
- See Also:
- Constant Field Values
-
CLEANUP
private static final java.lang.String CLEANUP
- See Also:
- Constant Field Values
-
END
private static final java.lang.String END
- See Also:
- Constant Field Values
-
THREAD
private static final java.lang.String THREAD
- See Also:
- Constant Field Values
-
REPEAT
private static final java.lang.String REPEAT
- See Also:
- Constant Field Values
-
SYNC
private static final java.lang.String SYNC
- See Also:
- Constant Field Values
-
TIMEOUT
private static final java.lang.String TIMEOUT
- See Also:
- Constant Field Values
-
ROWLIMIT
private static final java.lang.String ROWLIMIT
- See Also:
- Constant Field Values
-
PREPARE
private static final java.lang.String PREPARE
- See Also:
- Constant Field Values
-
PRINT
private static final java.lang.String PRINT
- See Also:
- Constant Field Values
-
FETCH
private static final java.lang.String FETCH
- See Also:
- Constant Field Values
-
CLOSE
private static final java.lang.String CLOSE
- See Also:
- Constant Field Values
-
SLEEP
private static final java.lang.String SLEEP
- See Also:
- Constant Field Values
-
ERR
private static final java.lang.String ERR
- See Also:
- Constant Field Values
-
ECHO
private static final java.lang.String ECHO
- See Also:
- Constant Field Values
-
INCLUDE
private static final java.lang.String INCLUDE
- See Also:
- Constant Field Values
-
SHELL
private static final java.lang.String SHELL
- See Also:
- Constant Field Values
-
PLUGIN
private static final java.lang.String PLUGIN
- See Also:
- Constant Field Values
-
SQL
private static final java.lang.String SQL
- See Also:
- Constant Field Values
-
EOF
private static final java.lang.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
-
PLUGIN_LEN
private static final int PLUGIN_LEN
-
INCLUDE_LEN
private static final int INCLUDE_LEN
-
VAR_LEN
private static final int VAR_LEN
-
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
-
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
-
vars
private ConcurrentTestCommandScript.VariableTable vars
-
scriptDirectory
private java.io.File scriptDirectory
-
scriptStartTime
private long scriptStartTime
-
plugins
private final java.util.List<ConcurrentTestPlugin> plugins
-
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
-
threadResultsReaders
private final java.util.Map<java.lang.Integer,ConcurrentTestCommandScript.ResultsReader> threadResultsReaders
-
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 applicationlogger
- if not null, command and exit status will be logged hereappInput
- if not null, data will be copied to application's stdinappOutput
- 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 classConcurrentTestCommandGenerator
- 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 anString[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
-
requiresCustomErrorHandling
boolean requiresCustomErrorHandling()
Causes errors to be send here for custom handling. SeecustomErrorHandler(ConcurrentTestCommandExecutor)
.- Overrides:
requiresCustomErrorHandling
in classConcurrentTestCommandGenerator
-
customErrorHandler
void customErrorHandler(ConcurrentTestCommandExecutor executor)
Description copied from class:ConcurrentTestCommandGenerator
Custom error handling occurs here ifConcurrentTestCommandGenerator.requiresCustomErrorHandling()
returns true. Default implementation does nothing.- Overrides:
customErrorHandler
in classConcurrentTestCommandGenerator
-
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]...
-
-