Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
* Selects a child in each iteration according to specified relative weights.
* <p>
* Internally this uses <a
* href="https://github.com/Blazemeter/jmeter-bzm-plugins/blob/master/wsc/WeightedSwitchController.md">
* href="https://github.com/Blazemeter/jmeter-bzm-plugins/blob/master/wsc
* /WeightedSwitchController.md">
* BlazeMeter Weighted Switch Controller plugin</a>.
* <p>
* This controller is handy when you want part of the test plan to act in a probabilistic manner
Expand Down Expand Up @@ -57,10 +58,10 @@ public DslWeightedSwitchController() {
* Adds a child to the controller with a configured weight for selecting it in iterations.
*
* @param weight is the weight to assign to this particular element for execution in iterations.
* Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add
* samplers or controllers, their default assigned weight will be 100.
* @param child is the element to add as controller child that will be selected for execution
* during iterations according to given weight.
* Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add samplers or
* controllers, their default assigned weight will be 100.
* @param child is the element to add as controller child that will be selected for execution
* during iterations according to given weight.
* @return the controller for further configuration and usage.
*/
public DslWeightedSwitchController child(long weight, DslController child) {
Expand All @@ -71,10 +72,10 @@ public DslWeightedSwitchController child(long weight, DslController child) {
* Adds a child to the controller with a configured weight for selecting it in iterations.
*
* @param weight is the weight to assign to this particular element for execution in iterations.
* Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add
* samplers or controllers, their default assigned weight will be 100.
* @param child is the element to add as controller child that will be selected for execution
* during iterations according to given weight.
* Keep in mind that if you use {@link #children(ThreadGroupChild...)} to add samplers or
* controllers, their default assigned weight will be 100.
* @param child is the element to add as controller child that will be selected for execution
* during iterations according to given weight.
* @return the controller for further configuration and usage.
*/
public DslWeightedSwitchController child(long weight, DslSampler child) {
Expand All @@ -84,14 +85,17 @@ public DslWeightedSwitchController child(long weight, DslSampler child) {
/**
* Sets the random choice mode for child elements.
* <p>
* When random choice mode is enabled (randomChoice = true), the controller will select child elements
* randomly, according to their weights. When disabled (randomChoice = false), selection will occur
* sequentially based on weights.
* When random choice mode is enabled (randomChoice = true), the controller will select child
* elements randomly, according to their weights. When disabled (randomChoice = false), selection
* will occur sequentially based on weights.
* <p>
* The randomChoice(true) method cannot guarantee that the actual execution percentages of its
* child elements will exactly match the expected distribution.
*
* @param randomChoice true - to enable random selection, false - for sequential selection
* @return current controller instance for method chaining
*/
public DslWeightedSwitchController randomChoice(boolean randomChoice){
public DslWeightedSwitchController randomChoice(boolean randomChoice) {
this.isRandomChoice = randomChoice;
return this;
}
Expand Down Expand Up @@ -192,7 +196,10 @@ public CodeBuilder(List<Method> builderMethods) {
@Override
protected MethodCall buildMethodCall(WeightedSwitchController testElement,
MethodCallContext context) {
TestElementParamBuilder paramBuilder = new TestElementParamBuilder(testElement);
MethodCall ret = buildMethodCall();
ret.chain("randomChoice",
paramBuilder.boolParam(WeightedSwitchController.IS_RANDOM_CHOICE, false));
Map<String, Long> weights = extractSamplersWeights(testElement);
chainChildren(ret, context, weights);
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public DslTestPlan testPlanWithWeightedSwitchController() {
);
}

public DslTestPlan testPlanWithWeightedSwitchControllerAndRandomChoice() {
return testPlan(
threadGroup(1, 1,
weightedSwitchController()
.randomChoice(true)
.child(2, httpSampler("sample1", "http://localhost"))
.child(3, httpSampler("sample2", "http://localhost"))
)
);
}

public DslTestPlan testPlanWithWeightedSwitchControllerAndUnweightedElements() {
return testPlan(
threadGroup(1, 1,
Expand Down
4 changes: 2 additions & 2 deletions jmeter-java-dsl/src/test/resources/test-plan.template.jmx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<stringProp name="HTTPSampler.port">{{port:}}</stringProp>
<stringProp name="HTTPSampler.path">/</stringProp>
<stringProp name="HTTPSampler.method">POST</stringProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
</HTTPSamplerProxy>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager">
Expand All @@ -58,8 +58,8 @@
<stringProp name="HTTPSampler.port">{{port:}}</stringProp>
<stringProp name="HTTPSampler.path">/</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
</HTTPSamplerProxy>
<hashTree/>
</hashTree>
Expand Down
Loading