|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
ConcurrentTestCommand | ConcurrentTestCommand represents a command, sequentially executed by
ConcurrentTestCommandExecutor , during a concurrency test |
Class Summary | |
---|---|
ConcurrentTestCommandExecutor | ConcurrentTestCommandExecutor is a thread that executes a sequence of
commands on a JDBC connection. |
ConcurrentTestCommandExecutor.Sync | Synchronization object that allows multiple ConcurrentTestCommandExecutors to execute commands in lock-step. |
ConcurrentTestCommandGenerator | ConcurrentTestCommandGenerator creates instances of ConcurrentTestCommand that perform specific actions in a specific
order and within the context of a test thread (ConcurrentTestCommandExecutor ). |
ConcurrentTestCommandGenerator.AbstractCommand | abstract base to handle SQLExceptions |
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. |
ConcurrentTestCommandGenerator.CloseCommand | CloseCommand closes a previously prepared statement. |
ConcurrentTestCommandGenerator.CommandWithTimeout | |
ConcurrentTestCommandGenerator.CommitCommand | CommitCommand commits pending transactions via Connection.commit() . |
ConcurrentTestCommandGenerator.DdlCommand | DdlCommand executes DDL commands. |
ConcurrentTestCommandGenerator.ExplainCommand | ExplainCommand executes explain plan commands. |
ConcurrentTestCommandGenerator.FailedThread | Describes a thread that failed |
ConcurrentTestCommandGenerator.FetchAndCompareCommand | FetchAndCompareCommand executes a previously prepared statement stored in the ConcurrentTestCommandExecutor and then validates the returned rows against expected data. |
ConcurrentTestCommandGenerator.InsertCommand | InsertCommand exeutes an insert, update or delete SQL statement. |
ConcurrentTestCommandGenerator.PrepareCommand | PrepareCommand creates a PreparedStatement . |
ConcurrentTestCommandGenerator.RollbackCommand | RollbackCommand rolls back pending transactions via Connection.rollback() . |
ConcurrentTestCommandGenerator.SleepCommand | SleepCommand causes the execution thread to wait for all other threads in the test before continuing. |
ConcurrentTestCommandGenerator.SynchronizationCommand | SynchronizationCommand causes the execution thread to wait for all other threads in the test before continuing. |
ConcurrentTestCommandScript | ConcurrentTestCommandScript creates instances of ConcurrentTestCommand that perform specific actions in a specific
order and within the context of a test thread (ConcurrentTestCommandExecutor ). |
ConcurrentTestCommandScript.CommandWithTimeout | |
ConcurrentTestCommandScript.CommandWithTimeoutAndRowLimit | |
ConcurrentTestCommandScript.StateAction | |
ConcurrentTestCommandScript.StateDatum | |
ConcurrentTestCommandScript.Tool | |
ConcurrentTestTimedCommandGenerator | ConcurrentTestTimedCommandGenerator extends ConcurrentTestCommandGenerator and repeats the configured command
sequence until a certain amount of time has elapsed. |
Exception Summary | |
---|---|
ConcurrentTestCommand.ShouldHaveFailedException | Indicates that a command should have failed, but instead succeeded, which is a test error |
A framework for concurrent jdbc unit tests.
The class ConcurrentCommandGenerator
providea a java API for constructing
concurrent jdbc tests: an instance of the class represents a test case, which
contains several sequences of SQL commands (abstracted as subclasses of
ConcurrentCommand
). Each sequence is run in its own thread as a
separate jdbc client (ie a separate java.sql.Connection
). There are
facilties to synchronize these command threads. Only a simple command sequence
is supported: no branching, no looping.
An alternative is to define a test by writing a test script
in mtsql
format, as described below. An instance
of ConcurrentCommandScript
parses and executes a script.
Revision | $Id: //open/dev/farrago/src/org/eigenbase/test/concurrent/package.html#1 $ |
---|---|
Copyright | Copyright (C) 2005-2009 The Eigenbase Project
Copyright (C) 2005-2009 SQLstream, Inc. Copyright (C) 2005-2009 LucidEra, Inc. |
Author | Stephan Zuercher |
The syntactic structure of an mtsql script is:
<directive>* <setup section>? <cleanup section>? <thread section>+ <directive> := @[no]lockstep | @enable | @disable <setup section> := @setup <basic command>* @end <cleanup section> := @setup <basic command>* @end <thread section> := @thread <thread-name>? <command>* @end <command> := <basic command> | <command prefix>? <threadly command> | <synchronization point>
Blank lines and comments are allowed anywhere. A comment starts with two hyphens and runs to the end of the line. Command names start with an '@'. Some commands run to the end of the line; but a command that contains SQL can span lines and ends with a semicolon.
Running a section means running its commands in sequence. First the setup section (if any) is run. Next all the thread sections are run at once, each in its own thread. When all these threads complete, the cleanup section (if any) is run.
The threads are synchronized by inserting synchronization points (@sync).
When a thread reaches a @sync, it waits until all threads are waiting on the same @sync: then all threads proceed. @sync points have no names. Clearly all thread sections must contain the same number of @sync points.
The directive @lockstep has the same effect as adding a @sync after each command in every thread section. Clearly it requires that all thread sections have the same number of commands. The default is the antonym @nolockstep.
The directive @disable means "skip this script". The deault is the antonym @enable.
When a command fails, the rest of its section is skipped. If this happens in a thread section, the thread stops, but the other threads continue (with one fewer partner to synchronize with), and finally the cleanup section runs. If the setup section fails, then only the cleanup section is run. (Note: Not sure this behavior is correct or desirable.)
<SQL statement>; An SQL statement terminated by a semicolon. The statement can span lines.
@include FILE Reads and executes the contents of FILE, another mtsql script. Inclusions may nest.
@sleep N -- thread sleeps for N milliseconds @echo MESSAGE -- prints the message to stdout <SQL statement> ';' -- executes the SQL @timeout N <SQL> ';' -- executes the SQL with the given timeout (msecs) @rowlimit N <SQL> ';' -- executes the SQL, stops fetching after N rows. @err <SQL> ';' -- executes the SQL, expecting it to fail. @repeat N <command>+ @end Denotes a repeated block of commands, with repeat count = N. N must be positive. @prepare SQL-STATEMENT ';' Prepares the sql. A thread has at most one prepared statement at a time. @print FORMAT Sets the result-printing format for the current prepared statement. FORMAT is a sequence of the phrases: none -- means print nothing all -- means print all rows (the default) every N -- means print the first row (row 0), then row N, 2N, etc. count -- means print the row number before the row (starts with 0). time -- means print the actual time the row was fetched (Sorry, no way yet to print selected columns, to print time in a special way, etc.) @fetch <timeout>? Starts fetching and printing result rows, with an optional timeout (in msecs). Stop on EOD or on timeout. @close Closes the current prepared statement. However that an open prepared statement will be closed automatically at the end of its thread. @shell <Shell Command> Runs the command in a spawned subshell, proceeds after it concludes, but quits if it fails. For @shell and @echo, the command or message runs to the end of the line in the script, but can be continued if the line ends with a single '\'.
Needed mainly to pass arguments to the command of @shell, but also useful to parameterize SQL statements, timeout values etc.
@var VAR Declares a variable VAR @var VAR1 VAR2 ... VARn Declares n variables.
The initial value of a script variable VAR is taken from the shell environment variable of the same name. The value can be set to a different value when the script is run, by employing a phrase VAR=VALUE on the mtsql command line.
A command-line tool that runs an mtsql script against a specified jdbc connection,a nd prints the query results. (But see @print command to filter the output.)
Usage: mtsql [-qvg] -u SERVER -d DRIVER [-n USER] [-p PASSWORD] [VAR=VALUE]* SCRIPT [SCRIPT]* Flags: -q : (quiet) do not print results. -v : (verbose) trace as script is parsed. -g : (debug) print command lists before starting the threads -u SERVER : sets the target; a jdbc URL. -d DRIVER : sets the jdbc driver; a class on the classpath VAR=VALUE : binds the script variable VAR to the VALUE; VAR must be declared at the beginning of the script(s) in a @var command.
-- redundant: @nolockstep -- Two threads reading the same data. @thread 1,2 -- pre execute the SQL to prime the pumps @timeout 1000 select * from sales.bids; @prepare select * from sales.bids; -- rendezvous with writer thread @sync @fetch 15000 @sync @close @end @thread writer -- rendezvous with reader threads @sync @sleep 5000 insert into sales.bids values(1, 'ORCL', 100, 12.34, 10000, 'Oracle at 12.34'); commit; insert into sales.bids values(2, 'MSFT', 101, 23.45, 20000, 'Microsoft at 23.45'); commit; -- real test has more inserts here @sync @end
-- thread 1 > select * from sales.bids; +---------+------------+ | DEPTNO | NAME | +---------+------------+ | 10 | Sales | | 20 | Marketing | | 30 | Accounts | +---------+------------+ > > select * from sales.bids; +---------+------------+ | DEPTNO | NAME | +---------+------------+ | 10 | Sales | | 20 | Marketing | | 30 | Accounts | +---------+------------+ -- end of thread 1 -- thread 2 > select * from sales.bids; +---------+------------+ | DEPTNO | NAME | +---------+------------+ | 10 | Sales | | 20 | Marketing | | 30 | Accounts | +---------+------------+ > > select * from sales.bids; +---------+------------+ | DEPTNO | NAME | +---------+------------+ | 10 | Sales | | 20 | Marketing | | 30 | Accounts | +---------+------------+ -- end of thread 2 -- thread writer > insert into sales.bids > values(1, 'ORCL', 100, 12.34, 10000, 'Oracle at 12.34'); 1 row affected. > commit; > insert into sales.bids > values(2, 'MSFT', 101, 23.45, 20000, 'Microsoft at 23.45'); 1 row affected. > commit; -- end of thread writer(Yes the results of the select statements are obviously wrong.)
|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |