Skip to content

Commit 3e475b8

Browse files
Add randomChoice option to weightedSwitchCotroller doc
1 parent 9eff9ed commit 3e475b8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/guide/request-generation/weighted-switch-controller.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,33 @@ public class PerformanceTest {
3030
}
3131
```
3232

33+
By default `weightedSwitchController` will execute their children sequentially it is possible to change this behavior to execute them randomly by using `.randomChoice(true)`
34+
35+
```java
36+
import static org.assertj.core.api.Assertions.assertThat;
37+
import static us.abstracta.jmeter.javadsl.JmeterDsl.*;
38+
39+
import java.io.IOException;
40+
import java.time.Duration;
41+
import org.junit.jupiter.api.Test;
42+
import us.abstracta.jmeter.javadsl.core.TestPlanStats;
43+
44+
public class PerformanceTest {
45+
46+
@Test
47+
public void testPerformance() throws IOException {
48+
TestPlanStats stats = testPlan(
49+
threadGroup(2, 10,
50+
weightedSwitchController()
51+
.randomChoice(true) // will run children in a random way
52+
.child(30, httpSampler("https://myservice/1"))
53+
.child(20, httpSampler("https://myservice/2"))
54+
)
55+
).run();
56+
assertThat(stats.overall().sampleTimePercentile99()).isLessThan(Duration.ofSeconds(5));
57+
}
58+
59+
}
60+
```
61+
3362
[DslWeightedSwitchController](/jmeter-java-dsl/src/main/java/us/abstracta/jmeter/javadsl/core/controllers/DslWeightedSwitchController.java) for more details.

0 commit comments

Comments
 (0)