-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35fb8d0
commit 6ae9ee9
Showing
7 changed files
with
176 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ava-dsl/src/main/java/us/abstracta/jmeter/javadsl/core/controllers/ForLoopController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package us.abstracta.jmeter.javadsl.core.controllers; | ||
|
||
import java.util.List; | ||
import org.apache.jmeter.control.LoopController; | ||
import org.apache.jmeter.control.gui.ForeachControlPanel; | ||
import org.apache.jmeter.testelement.TestElement; | ||
import us.abstracta.jmeter.javadsl.core.DslThreadGroup.ThreadGroupChild; | ||
|
||
/** | ||
* Allows running part of a test plan a given number of times inside one thread group iteration. | ||
* | ||
* Internally this uses JMeter Loop Controller. | ||
* | ||
* JMeter automatically creates a variable named {@code __jm__<controllerName>__idx} which contains | ||
* the index of the iteration starting with zero. | ||
* | ||
* @since 0.27 | ||
*/ | ||
public class ForLoopController extends DslController { | ||
|
||
private final int count; | ||
|
||
public ForLoopController(String name, int count, List<ThreadGroupChild> children) { | ||
super(name != null ? name : "for", ForeachControlPanel.class, children); | ||
this.count = count; | ||
} | ||
|
||
@Override | ||
protected TestElement buildTestElement() { | ||
LoopController ret = new LoopController(); | ||
ret.setLoops(count); | ||
return ret; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...dsl/src/test/java/us/abstracta/jmeter/javadsl/core/controllers/ForLoopControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package us.abstracta.jmeter.javadsl.core.controllers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.forLoopController; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.httpSampler; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.testPlan; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.threadGroup; | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import org.junit.jupiter.api.Test; | ||
import us.abstracta.jmeter.javadsl.JmeterDslTest; | ||
import us.abstracta.jmeter.javadsl.core.TestPlanStats; | ||
|
||
public class ForLoopControllerTest extends JmeterDslTest { | ||
|
||
private static final int LOOP_ITERATIONS = 3; | ||
|
||
@Test | ||
public void shouldExecuteExpectedNumberOfTimesWhenLoopControllerInPlan() throws Exception { | ||
TestPlanStats stats = testPlan( | ||
threadGroup(1, TEST_ITERATIONS, | ||
forLoopController(LOOP_ITERATIONS, | ||
httpSampler(wiremockUri) | ||
) | ||
) | ||
).run(); | ||
assertThat(stats.overall().samplesCount()).isEqualTo(TEST_ITERATIONS * LOOP_ITERATIONS); | ||
} | ||
|
||
@Test | ||
public void shouldExposeJMeterVariableWithControllerNameWhenLoopControllerInPlan() | ||
throws Exception { | ||
String loopName = "COUNT"; | ||
TestPlanStats stats = testPlan( | ||
threadGroup(1, 1, | ||
forLoopController(loopName, LOOP_ITERATIONS, | ||
httpSampler(wiremockUri + "/${__jm__" + loopName + "__idx}") | ||
) | ||
) | ||
).run(); | ||
verifyRequestMadeForPath("/0"); | ||
verifyRequestMadeForPath("/1"); | ||
verifyRequestMadeForPath("/2"); | ||
} | ||
|
||
private void verifyRequestMadeForPath(String path) { | ||
wiremockServer.verify(WireMock.getRequestedFor(WireMock.urlPathEqualTo(path))); | ||
} | ||
|
||
} |