|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.clarkware.junitperf.LoadTest
The LoadTest
is a test decorator that runs
a test with a simulated number of concurrent users and
iterations.
In its simplest form, a LoadTest
is constructed
with a test to decorate and the number of concurrent users.
For example, to create a load test of 10 concurrent users
with each user running ExampleTest
once and
all users started simultaneously, use:
Test loadTest = new LoadTest(new ExampleTest(), 10);
The load can be ramped by specifying a pluggable
Timer
instance which prescribes the delay
between the addition of each concurrent user. A
ConstantTimer
has a constant delay, with
a zero value indicating that all users will be started
simultaneously. A RandomTimer
has a random
delay with a uniformly distributed variation.
For example, to create a load test of 10 concurrent users
with each user running ExampleTest
once and
with a one second delay between the addition of users, use:
Timer timer = new ConstantTimer(1000); Test loadTest = new LoadTest(new ExampleTest(), 10, timer);
In order to simulate each concurrent user running a test for a
specified number of iterations, a LoadTest
can be
constructed to decorate a RepeatedTest
.
Alternatively, a LoadTest
convenience constructor
specifying the number of iterations is provided which creates a
RepeatedTest
.
For example, to create a load test of 10 concurrent users
with each user running ExampleTest
for 20 iterations,
and with a one second delay between the addition of users, use:
or, alternatively, use:Timer timer = new ConstantTimer(1000); Test repeatedTest = new RepeatedTest(new ExampleTest(), 20); Test loadTest = new LoadTest(repeatedTest, 10, timer);
ATimer timer = new ConstantTimer(1000); Test loadTest = new LoadTest(new ExampleTest(), 10, 20, timer);
LoadTest
can be decorated as a TimedTest
to test the elapsed time of the load test. For example, to decorate
the load test constructed above as a timed test with a maximum elapsed
time of 2 seconds, use:
Test timedTest = new TimedTest(loadTest, 2000);
By default, a LoadTest
does not enforce test
atomicity (as defined in transaction processing) if its decorated
test spawns threads, either directly or indirectly. In other words,
if a decorated test spawns a thread and then returns control without
waiting for its spawned thread to complete, then the test is assumed
to be transactionally complete.
If threads are integral to the successful completion of
a decorated test, meaning that the decorated test should not be
treated as complete until all of its threads complete, then
setEnforceTestAtomicity(true)
should be invoked to
enforce test atomicity. This effectively causes the load test to
wait for the completion of all threads belonging to the same
ThreadGroup
as the thread running the decorated test.
Test
Constructor Summary | |
LoadTest(junit.framework.Test test,
int users)
Constructs a LoadTest to decorate
the specified test using the specified number
of concurrent users and a delay of 0 ms. |
|
LoadTest(junit.framework.Test test,
int users,
int iterations)
Constructs a LoadTest to decorate
the specified test using the specified number
of concurrent users, number of iterations per
user, and a delay of 0 ms. |
|
LoadTest(junit.framework.Test test,
int users,
int iterations,
Timer timer)
Constructs a LoadTest to decorate
the specified test using the specified number
of concurrent users, number of iterations per
user, and delay timer. |
|
LoadTest(junit.framework.Test test,
int users,
Timer timer)
Constructs a LoadTest to decorate
the specified test using the specified number
of concurrent users and delay timer. |
Method Summary | |
protected void |
cleanup()
Cleans up thread resources. |
int |
countTestCases()
Returns the number of tests in this test. |
protected long |
getDelay()
Returns the test delay. |
void |
run(junit.framework.TestResult result)
Runs the test. |
void |
setEnforceTestAtomicity(boolean isAtomic)
Indicates whether test atomicity should be enforced. |
protected void |
sleep(long time)
Sleeps. |
java.lang.String |
toString()
Returns the test description. |
protected void |
waitForAllThreadsToComplete()
Waits for all threads in the ThreadedTestGroup to complete. |
protected void |
waitForTestCompletion()
Waits for test completion. |
protected void |
waitForThreadedTestThreadsToComplete()
Waits for all threads spawned by ThreadedTest instances
to complete. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public LoadTest(junit.framework.Test test, int users)
LoadTest
to decorate
the specified test using the specified number
of concurrent users and a delay of 0 ms.test
- Test to decorate.users
- Number of concurrent users.public LoadTest(junit.framework.Test test, int users, int iterations)
LoadTest
to decorate
the specified test using the specified number
of concurrent users, number of iterations per
user, and a delay of 0 ms.test
- Test to decorate.users
- Number of concurrent users.iteration
- Number of iterations per user.public LoadTest(junit.framework.Test test, int users, int iterations, Timer timer)
LoadTest
to decorate
the specified test using the specified number
of concurrent users, number of iterations per
user, and delay timer.test
- Test to decorate.users
- Number of concurrent users.iteration
- Number of iterations per user.public LoadTest(junit.framework.Test test, int users, Timer timer)
LoadTest
to decorate
the specified test using the specified number
of concurrent users and delay timer.test
- Test to decorate.users
- Number of concurrent users.java.lang.IllegalArgumentException
- If an invalid argument is
specified, such as a non-positive number of concurrent users.Method Detail |
public void setEnforceTestAtomicity(boolean isAtomic)
isAtomic
- true
to enforce test atomicity;
false
otherwise.public int countTestCases()
countTestCases
in interface junit.framework.Test
public void run(junit.framework.TestResult result)
run
in interface junit.framework.Test
result
- Test result.protected void waitForTestCompletion()
protected void waitForThreadedTestThreadsToComplete()
ThreadedTest
instances
to complete.protected void waitForAllThreadsToComplete()
ThreadedTestGroup
to complete.protected void sleep(long time)
protected void cleanup()
public java.lang.String toString()
toString
in class java.lang.Object
protected long getDelay()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |