Repository navigation
Conversation
milamberspace
left a comment
There was a problem hiding this comment.
Thanks for working on #6295, documenting how to actually run a DSL-built plan is a real gap in this page.
Main points
- The new doc section has no code sample. Every other section of this page comes with a
<source>block, and the issue reporter explicitly asked for the equivalent of the Java DSLjtlWriter(...)example. As it stands, readers still have to guessconfigure/runTest/awaitTerminationand how to set the JTL path, which is what the issue complained about. See the inline suggestion. - The test largely duplicates
OpenModelThreadGroupConfigElementTest(same plan, samescheduleString, sameDebugSampler, same engine/await sequence); only theResultCollectorand the JTL check are new. Its main value would be to guarantee that the documented snippet compiles and runs, so I'd suggest keeping the doc snippet and the test code in sync (same code, same idioms). Alternatively, the JTL assertions could be added to the existing test. Thethreads.openmodelpackage is also a slightly odd home for a test whose purpose is the DSL usage example.
Minor
- The JTL check
results.contains("Kotlin DSL sample")passes as soon as a single line is written; asserting 5 data lines (plus header) would verify that all samples were persisted. - The blank line that used to separate the two sections ended up inside the new section; there's now no blank line between
</section>and<section name="Extending Kotlin DSL">.
orimarko
left a comment
There was a problem hiding this comment.
@milamberspace Thank you for reviewing, I fixed the issues and move test to package kotlin/org/apache/jmeter/dsl
milamberspace
left a comment
There was a problem hiding this comment.
Thanks for the update! The documentation now has a proper code sample, the test lives in a better place, and the snippet uses the idiomatic DSL style.
Two things are still needed, and one is a regression introduced by keeping the test in sync with the docs (my earlier wording probably encouraged that, sorry):
- The test no longer asserts anything. All the assertions (number of samples, JTL file content) were removed, so the test would pass even if no sample was run and no file was written. The plan-building code can stay identical to the documentation, but the assertions should come back after it.
- The test writes into the source tree.
filename = "target/results.jtl"is relative, and Gradle runs the tests from the module directory, so each run createssrc/components/target/results.jtl. The repository.gitignoreonly ignores the top-level/target/, so that file shows up as untracked for contributors. The documentation can keeptarget/results.jtl, but the test should use a@TempDir.
See the inline comment for a version of the test I ran locally against this branch (passes, and leaves nothing behind).
- Minor: the indentation of the
<source>block in the documentation is inconsistent (nested blocks are misaligned, and the block starts with 8 spaces whereas the other samples of the page start at column 0). There is a suggestion inline.
| val tree = testTree { | ||
| TestPlan::class { | ||
| ResultCollector::class { | ||
| filename = "target/results.jtl" |
There was a problem hiding this comment.
This relative path makes each test run create src/components/target/results.jtl (not covered by the repository .gitignore), and nothing checks the result anymore. Suggested version, keeping the plan identical to the documentation but writing to a temporary directory and asserting the JTL content:
class KotlinDslRunTest : JMeterTestCase(), JMeterSerialTest {
@TempDir
lateinit var tempDir: Path
@Test
fun `run Kotlin DSL plan and write results`() {
val jtlFile = tempDir.resolve("results.jtl")
// Same code as in build-programmatic-test-plan.xml, except for the JTL location
val tree = testTree {
TestPlan::class {
ResultCollector::class {
filename = jtlFile.toString()
}
OpenModelThreadGroup::class {
name = "Thread Group"
// 5 requests within 100 ms, then a pause so all the threads can finish
scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(2 s)"
DebugSampler::class {
name = "Kotlin DSL sample"
}
}
}
}
StandardJMeterEngine().apply {
configure(tree)
runTest()
awaitTermination(Duration.ofSeconds(10))
}
assertEquals(
5,
Files.readAllLines(jtlFile).count { it.contains("Kotlin DSL sample") },
"The JTL file should contain the 5 samples"
)
}
}(needs org.junit.jupiter.api.Assertions.assertEquals, org.junit.jupiter.api.io.TempDir, java.nio.file.Files and java.nio.file.Path imports)
| <source> | ||
| val tree = testTree { | ||
| TestPlan::class { | ||
| ResultCollector::class { | ||
| filename = "target/results.jtl" | ||
| } | ||
| OpenModelThreadGroup::class { | ||
| name = "Thread Group" | ||
| // 5 requests within 100 ms, then a pause so all the threads can finish | ||
| scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(2 s)" | ||
| DebugSampler::class { | ||
| name = "Kotlin DSL sample" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| StandardJMeterEngine().apply { | ||
| configure(tree) | ||
| runTest() | ||
| awaitTermination(Duration.ofSeconds(10)) | ||
| }</source> |
There was a problem hiding this comment.
Indentation fix, aligned with the other samples of this page:
| <source> | |
| val tree = testTree { | |
| TestPlan::class { | |
| ResultCollector::class { | |
| filename = "target/results.jtl" | |
| } | |
| OpenModelThreadGroup::class { | |
| name = "Thread Group" | |
| // 5 requests within 100 ms, then a pause so all the threads can finish | |
| scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(2 s)" | |
| DebugSampler::class { | |
| name = "Kotlin DSL sample" | |
| } | |
| } | |
| } | |
| } | |
| StandardJMeterEngine().apply { | |
| configure(tree) | |
| runTest() | |
| awaitTermination(Duration.ofSeconds(10)) | |
| }</source> | |
| <source> | |
| val tree = testTree { | |
| TestPlan::class { | |
| ResultCollector::class { | |
| filename = "target/results.jtl" | |
| } | |
| OpenModelThreadGroup::class { | |
| name = "Thread Group" | |
| // 5 requests within 100 ms, then a pause so all the threads can finish | |
| scheduleString = "rate(50 / sec) random_arrivals(100 ms) pause(2 s)" | |
| DebugSampler::class { | |
| name = "Kotlin DSL sample" | |
| } | |
| } | |
| } | |
| } | |
| StandardJMeterEngine().apply { | |
| configure(tree) | |
| runTest() | |
| awaitTermination(Duration.ofSeconds(10)) | |
| }</source> |
Description
Document how to run a Kotlin DSL test plan
Motivation and Context
Part of #6295
Document how to execute a test plan built with the Kotlin DSL and write
sample results to a JTL file. Add a test that builds and runs a plan,
waits for completion, and checks the generated results.
How Has This Been Tested?
./gradlew :src:components:test --tests "*KotlinDslRunTest"
Types of changes
Checklist: