-
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.
Implemented Simple Controller (#222)
- Loading branch information
1 parent
174d7bf
commit 83bc6df
Showing
4 changed files
with
172 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
### Organization | ||
|
||
Simple controllers offer a way of organizing your test plan into individual modules, | ||
controllers, assertions, samplers etc. can all be added, even more Simple Controllers for further organization, | ||
simple controllers will run each child sequentially from top to bottom | ||
|
||
Look at the bellow example of how to use a `simpleController`: | ||
|
||
```java | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.*; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import org.apache.http.entity.ContentType; | ||
import org.junit.jupiter.api.Test; | ||
import us.abstracta.jmeter.javadsl.core.TestPlanStats; | ||
|
||
public class PerformanceTest { | ||
|
||
@Test | ||
public void testPerformance() throws Exception { | ||
TestPlanStats testPlanStats = testPlan( | ||
threadGroup(1, 1, | ||
simpleController("Simple Controller", | ||
httpSampler(wiremockUri), | ||
dummySampler("Test") | ||
) | ||
) | ||
).run(); | ||
} | ||
|
||
} | ||
``` | ||
|
||
Check [DslSimpleController](/jmeter-java-dsl/src/main/java/us/abstracta/jmeter/javadsl/core/controllers/DslSimpleController.java) and [JMeter Component documentation](https://jmeter.apache.org/usermanual/component_reference.html#Simple_Controller) for more details. |
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
48 changes: 48 additions & 0 deletions
48
...a-dsl/src/main/java/us/abstracta/jmeter/javadsl/core/controllers/DslSimpleController.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,48 @@ | ||
package us.abstracta.jmeter.javadsl.core.controllers; | ||
|
||
import org.apache.jmeter.control.GenericController; | ||
import org.apache.jmeter.control.gui.LogicControllerGui; | ||
import org.apache.jmeter.testelement.TestElement; | ||
import us.abstracta.jmeter.javadsl.codegeneration.MethodCall; | ||
import us.abstracta.jmeter.javadsl.codegeneration.MethodCallContext; | ||
import us.abstracta.jmeter.javadsl.codegeneration.SingleTestElementCallBuilder; | ||
import us.abstracta.jmeter.javadsl.codegeneration.params.ChildrenParam; | ||
import us.abstracta.jmeter.javadsl.codegeneration.params.StringParam; | ||
import us.abstracta.jmeter.javadsl.core.threadgroups.BaseThreadGroup.ThreadGroupChild; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
/** | ||
* The Simple Logic Controller lets you organize your Samplers and other Logic Controllers. | ||
* This controller provides no additional functionality | ||
* <p> | ||
* Used primarily to organize other controllers and samples | ||
* | ||
* @since 1.21 | ||
*/ | ||
public class DslSimpleController extends BaseController<DslSimpleController> { | ||
|
||
public DslSimpleController(String name, List<ThreadGroupChild> children) { | ||
super(name, LogicControllerGui.class, children); | ||
} | ||
|
||
@Override | ||
protected TestElement buildTestElement() { | ||
return new GenericController(); | ||
} | ||
|
||
public static class CodeBuilder extends SingleTestElementCallBuilder<GenericController> { | ||
|
||
public CodeBuilder(List<Method> builderMethods) { | ||
super(GenericController.class, builderMethods); | ||
} | ||
|
||
@Override | ||
protected MethodCall buildMethodCall(GenericController testElement, MethodCallContext context) { | ||
return buildMethodCall(new StringParam(testElement.getName()), new ChildrenParam<>(ThreadGroupChild[].class)); | ||
} | ||
|
||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...l/src/test/java/us/abstracta/jmeter/javadsl/core/controllers/DslSimpleControllerTest.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,74 @@ | ||
package us.abstracta.jmeter.javadsl.core.controllers; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import us.abstracta.jmeter.javadsl.JmeterDslTest; | ||
import us.abstracta.jmeter.javadsl.codegeneration.MethodCallBuilderTest; | ||
import us.abstracta.jmeter.javadsl.core.DslTestPlan; | ||
import us.abstracta.jmeter.javadsl.core.TestPlanStats; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.dummySampler; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.httpSampler; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.simpleController; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.testPlan; | ||
import static us.abstracta.jmeter.javadsl.JmeterDsl.threadGroup; | ||
|
||
public class DslSimpleControllerTest extends JmeterDslTest { | ||
|
||
@Test | ||
public void shouldOnlyIncludeSpecifiedSamples() | ||
throws Exception { | ||
|
||
TestPlanStats testPlanStats = testPlan( | ||
threadGroup(1, 1, | ||
simpleController("Simple Controller", | ||
httpSampler(wiremockUri), | ||
dummySampler("Test") | ||
) | ||
) | ||
).run(); | ||
assertThat(testPlanStats.overall().samplesCount()).isEqualTo(2); | ||
assertThat(testPlanStats.byLabel("jp@gc - Dummy Sampler").samplesCount()).isEqualTo(1); | ||
assertThat(testPlanStats.byLabel("HTTP Request").samplesCount()).isEqualTo(1); | ||
assertThat(testPlanStats.byLabel("Simple Controller")).isNull(); | ||
} | ||
|
||
@Test | ||
public void allowsNestedSimpleControllers() | ||
throws Exception { | ||
|
||
TestPlanStats testPlanStats = testPlan( | ||
threadGroup(1, 1, | ||
simpleController("Simple Controller", | ||
simpleController("Simple Controller", | ||
httpSampler(wiremockUri) | ||
), | ||
httpSampler(wiremockUri), | ||
dummySampler("Test") | ||
) | ||
) | ||
).run(); | ||
assertThat(testPlanStats.overall().samplesCount()).isEqualTo(3); | ||
assertThat(testPlanStats.byLabel("jp@gc - Dummy Sampler").samplesCount()).isEqualTo(1); | ||
assertThat(testPlanStats.byLabel("HTTP Request").samplesCount()).isEqualTo(2); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@Nested | ||
public class CodeBuilderTest extends MethodCallBuilderTest { | ||
|
||
public DslTestPlan testPlanWithSimpleController() { | ||
return testPlan( | ||
threadGroup(1, 1, | ||
simpleController("test", | ||
httpSampler("http://localhost"), | ||
httpSampler("http://mysite.com") | ||
) | ||
) | ||
); | ||
} | ||
|
||
} | ||
|
||
} |