abstracta / jmeter-java-dsl

Simple JMeter performance tests API
https://abstracta.github.io/jmeter-java-dsl/
Apache License 2.0
477 stars 59 forks source link

cloneable samplers #162

Closed alenakag closed 1 year ago

alenakag commented 1 year ago

The main reason for this change - to get a sampler name. The second reason - to get a cloned sampler. So I added getters and setters for fields in classes: DslBaseHttpSampler, DslHttpSampler, DslJsr223Sampler, DslJsr223TestElement, TestElementContainer, BaseTestElement. And I added method clone() in classes: DslHttpSampler, DslJsr223Sampler. Also I deleted attribute 'final' for fields 'children' and 'headers', so later I could filter sampler children for cloned object (for example, I need cloned sampler without origin sampler postprocessors).

rabelenda commented 1 year ago

Hello,

Thank you very much for taking the time to submit this PR and propose changes!

Can you further explain how you plan to use the sampler name? Why do you need such feature? Same questions for clone :).

We had something similar in the past and we decided to remove it to keep the API at the minimum to reduce the number of methods to look from (and understand) when using the API from most common users. Would be interesting to understand if there is any other scenario that would be interesting to support and plan to change the API accordingly in that regard.

Here is some explanation of past decisions that relate to this item.

alenakag commented 1 year ago

Hello, Thank you for your response. 1) Supplier could work for our project, if you could add method 'clear_children()' for classes: DslHttpSampler (class BaseSampler) and DslJsr223Sampler. Current implemantation 'this.children.addAll(Arrays.asList(children))' just appends new children for the sampler instead of replacement that we need . we use two identical samplers with different children. so it requires to clear or replace initial children. 2) our test logic depends on sampler name. for example: we add general jsr223PostProcessor that runs after every test sampler and checks if the sampler name contains some substring. so if it does it will do something specific. and we don't know when it happens

rabelenda commented 1 year ago

Hello, I have not been able to follow up on this due to vacations.

  1. Can you describe a little further how is your scenario? why not creating a base sampler method with the minimum amount of children, and then append the proper ones in each chase instead of "replacing" them from the base one?
  2. Can you give a little example of this case too? If you use jsr223PostProcessor you can use prev.getSampleLabel() or sampler.getName() to get the name inside it's execution. Having the get name on the DslSampler could allow you to build some logic when the JMeter tree is built, but would be not as accurate for jsr223PostProcessor logic, since sampler name may be solved in JMeter execution time (and not in JMeter "tree build time").

Thank you very much for the detailed answer and taking time to give reasons to every request, this helps not only in driving the design of the library with care on reasons and trying to keep it simple but also allows other users to find out different ways of using the library, understand how it works, and think of new improvements as well.

rabelenda commented 1 year ago

I am closing this PR since had no answer. We can re open it if we see that is still relevant after the comments I left.