2929 * Selects a child in each iteration according to specified relative weights.
3030 * <p>
3131 * Internally this uses <a
32- * href="https://github.com/Blazemeter/jmeter-bzm-plugins/blob/master/wsc/WeightedSwitchController.md">
32+ * href="https://github.com/Blazemeter/jmeter-bzm-plugins/blob/master/wsc
33+ * /WeightedSwitchController.md">
3334 * BlazeMeter Weighted Switch Controller plugin</a>.
3435 * <p>
3536 * This controller is handy when you want part of the test plan to act in a probabilistic manner
@@ -57,10 +58,10 @@ public DslWeightedSwitchController() {
5758 * Adds a child to the controller with a configured weight for selecting it in iterations.
5859 *
5960 * @param weight is the weight to assign to this particular element for execution in iterations.
60- * Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add
61- * samplers or controllers, their default assigned weight will be 100.
62- * @param child is the element to add as controller child that will be selected for execution
63- * during iterations according to given weight.
61+ * Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add samplers or
62+ * controllers, their default assigned weight will be 100.
63+ * @param child is the element to add as controller child that will be selected for execution
64+ * during iterations according to given weight.
6465 * @return the controller for further configuration and usage.
6566 */
6667 public DslWeightedSwitchController child (long weight , DslController child ) {
@@ -71,10 +72,10 @@ public DslWeightedSwitchController child(long weight, DslController child) {
7172 * Adds a child to the controller with a configured weight for selecting it in iterations.
7273 *
7374 * @param weight is the weight to assign to this particular element for execution in iterations.
74- * Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add
75- * samplers or controllers, their default assigned weight will be 100.
76- * @param child is the element to add as controller child that will be selected for execution
77- * during iterations according to given weight.
75+ * Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add samplers or
76+ * controllers, their default assigned weight will be 100.
77+ * @param child is the element to add as controller child that will be selected for execution
78+ * during iterations according to given weight.
7879 * @return the controller for further configuration and usage.
7980 */
8081 public DslWeightedSwitchController child (long weight , DslSampler child ) {
@@ -84,14 +85,17 @@ public DslWeightedSwitchController child(long weight, DslSampler child) {
8485 /**
8586 * Sets the random choice mode for child elements.
8687 * <p>
87- * When random choice mode is enabled (randomChoice = true), the controller will select child elements
88- * randomly, according to their weights. When disabled (randomChoice = false), selection will occur
89- * sequentially based on weights.
88+ * When random choice mode is enabled (randomChoice = true), the controller will select child
89+ * elements randomly, according to their weights. When disabled (randomChoice = false), selection
90+ * will occur sequentially based on weights.
91+ * <p>
92+ * The randomChoice(true) method cannot guarantee that the actual execution percentages of its
93+ * child elements will exactly match the expected distribution.
9094 *
9195 * @param randomChoice true - to enable random selection, false - for sequential selection
9296 * @return current controller instance for method chaining
9397 */
94- public DslWeightedSwitchController randomChoice (boolean randomChoice ){
98+ public DslWeightedSwitchController randomChoice (boolean randomChoice ) {
9599 this .isRandomChoice = randomChoice ;
96100 return this ;
97101 }
@@ -192,7 +196,10 @@ public CodeBuilder(List<Method> builderMethods) {
192196 @ Override
193197 protected MethodCall buildMethodCall (WeightedSwitchController testElement ,
194198 MethodCallContext context ) {
199+ TestElementParamBuilder paramBuilder = new TestElementParamBuilder (testElement );
195200 MethodCall ret = buildMethodCall ();
201+ ret .chain ("randomChoice" ,
202+ paramBuilder .boolParam (WeightedSwitchController .IS_RANDOM_CHOICE , false ));
196203 Map <String , Long > weights = extractSamplersWeights (testElement );
197204 chainChildren (ret , context , weights );
198205 return ret ;
0 commit comments