public abstract class AbstractTask extends Object implements Runnable
AbstractTask is the abstraction layer of test scenario, which requires subtypes to implement test scenario
in execute() method.
Instances of task is shared across multiple threads, the execute() method must be thread-safe.
If you call locust.run(new AwesomeTask()), only one instance of AwesomeTask is used by multiple threads.
This behavior is different from locust in python.| 构造器和说明 |
|---|
AbstractTask() |
| 限定符和类型 | 方法和说明 |
|---|---|
abstract void |
execute()
Test scenarios should be implemented in this method, like sending http request.
|
abstract String |
getName()
Get the name of task.
|
abstract int |
getWeight()
When locust runs multiple tasks, their weights are used to allocate threads.
|
void |
onStart()
This method will be executed once before the test loop.
|
void |
onStop()
This method will be executed once after the test loop stopped, whether it ends in failure or not.
|
void |
run() |
public abstract int getWeight()
public abstract String getName()
public abstract void execute()
throws Exception
Exception - test scenarios may throw exception.public void onStart()
throws Exception
Exception - if an exception is thrown then a failure will be recorded and test
scenarios will not be executedpublic void onStop()
Copyright © 2022. All rights reserved.