-
Notifications
You must be signed in to change notification settings - Fork 30
/
Main.java
34 lines (26 loc) · 994 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package task;
import com.github.myzhan.locust4j.Locust;
/**
* It's a example about using locust4j's API.
* It's also very handy when you are writing codes for locust4j, and want to test.
*
* @author myzhan
*/
public class Main {
public static void main(String[] args) {
// setup locust
Locust locust = Locust.getInstance();
locust.setMasterHost("127.0.0.1");
locust.setMasterPort(5557);
// run tasks without connecting to master, for debug purpose.
locust.dryRun(new TaskAlwaysSuccess(), new TaskAlwaysFail());
// limit max RPS that Locust4j can generate
locust.setMaxRPS(1000);
// user specified task
// task instance is shared across multiple threads
// if you want to keep some context like Socket, use ThreadLocal
locust.run(new TaskAlwaysSuccess(), new TaskAlwaysFail());
// multiply tasks
// locust.run(new TaskAlwaysSuccess(), new TaskAlwaysFail());
}
}