I want to perform jdbc query which returns 700K+ rows, then build my logic based on that, but when try to execute response time is too long, so i need to break down on multiple queries, each returning ex:1000 results.
My architecture is like:
001_1 JDBC max_value - Defines the maximum value, of that 700K, which is increasing all the time.
001_1 JDBC MAIN - This JDBC i want to break down into multiple JDBC requests.
InIt counter = vars.put("counter","1");
offset_value - counter element
While controller - ${__javaScript(parseInt(vars.get("counter"))<=700)}
If i put hard-code value into the While controller, everything works fine, and my script is working; But when data-base increase the records size, then i need manually to amend the number of the while controller 700, so can cover the next records.
Based on my understanding here i have 3 variables:
max_value = 714K
counter = 1
offset_value = 0
If i try: ${__javaScript(parseInt(vars.get("offset_value")<=parseInt(vars.get("max_value")))== true)}
as a while controller statement, offset_value is still not evaluated, and while controller is not working properly.
How can i compare offset_value vs. max_value, so i can drive my While controller?
Any help is appreciated!
If your parseInt(vars.get("offset_value")) expression is being executed against not-initialised variable it will return NaN so comparing it with a number doesn't make a lot of sense, you need to amend it to something like parseInt(vars.get("offset_value")) || 0 so it would return zero on first iteration.
Also be aware that starting from JMeter 3.1 you should be using JSR223 Test Elements for scripting and correspondingly __groovy() function in the While Controller. More information: Apache Groovy - Why and How You Should Use It
Thanks for the help #Dmitri T; However solution for me was:
1. Initialize the compare value as: JRS233 sample -> vars.put("offset_value","0");
2. ${__javaScript(parseInt(vars.get("offset_value"))<=parseInt(vars.get("max_value_1")),)} -> inside while controller.
3. Counter: Track counter & Reset counter: must me checked both
Related
I have a requirement to load the dynamic assets(Images) parallelly which got extracted from the for each loop as there is only one sampler with variable passed. I cant use the parallel controller here, also I don't know the exact number of assets loaded to pass in parallel sampler.
As suggested by you in one of similar issues I have used that approach(add pre sampler) below script and try to execute it in, It is able to pick the values but the child element is always only one(Parallel requests are not happening) however I see the URL's passed main request has multiple passed.
Pre-Processor script used:
String var2 = vars.get("tokens");
String var3 = vars.get("Token");
vars.put("var3", "https://stagingassets.ovid.com"+"/"+var2+"/t/width-150-png?"+var3);
urlsList = vars.get("var3").tokenize(",")
for (int i = 0; i < urlsList.size(); i++) {
def row = new org.apache.jmeter.testelement.property.CollectionProperty()
row.addItem(urlsList[i])
sampler.data.addItem(row)
log.info("ROWS ${row}")
}
variables are coming from CSV where values are saved into a file from each loop using a Flexible File Writer.
please suggest , My requirement is to execute the images parallelly as it happens in the browser.
[JMeter script image][1]
Use Parallel Sampler, the URLs can be added dynamically via JSR223 PreProcessor using the following code snippet:
sampler.addURL('your-first-url')
sampler.addURL('your-second-url')
If you want to mimic browser-like behaviour you need to put the Parallel Sampler under the Loop Controller and set the number of loops to the number of your URLs / 6
I have an issue I have been struggeling with for some time.
In my script I'm calculating a max and min value. I save it using:
int minWaitPregancy_acutall=0.2*maxWaitPregancyWait;
int maxWaitPregancy_acutall=0.8*maxWaitPregancyWait;
vars.putObject("minWaitPregancy_acutall", minWaitPregancy_acutall);
vars.putObject("maxWaitPregancy_acutall", maxWaitPregancy_acutall);
So far so good, it is saved and I can see it using the debugger.
Now I would like to use it in say a "Uniform Random timer".
I set the constant delay to 0 and in the Random Delay Maximum I try thing like:
${__Random(${__eval(vars.getObject("minWaitPregancy_acutall"))},${__eval(vars.get("maxWaitPregancy_acutall"))})}
For some reason that (and other variations, like skipping __eval) doesn't work I get variations of:
"java.lang.NumberFormatException: For input string: "vars.getObject("minWaitPregancy_acutall")""
So I guess I don't understand how to retrieve and use the data from the user defined variables. Any help??
As per Elements of Test Plan -> Execution Order
0. Configuration elements
1. Pre-Processors
2. Timers
3. Sampler
4. Post-Processors (unless SampleResult is null)
5. Assertions (unless SampleResult is null)
6. Listeners (unless SampleResult is null)
As per User Defined Variables documentation:
The User Defined Variables element lets you define an initial set of variables, just as in the Test Plan.
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
It looks like you're using the wrong test element, if you want to calculate a random variable and save it you need to use a PreProcessor, for example User Parameters
I have a JMeter 5.2.1 project where in the SetUp thread I generate properties with names like ThreadGroupName1-NumberOfThreads, ThreadGroupName2-NumberOfThreads, etc. with values representing integers.
Now, I wish to access these properties in thread groups named ThreadGroupName1, ThreadGroupName2, etc. to parametrize the number of threads. I tried something like ${__jexl3(props.get(threadName + "-NumberOfThreads"))} but it fails as threadName evaluates to standardjmeterengine.
Also, I tried to use ctx but ctx.getThread() and ctx.getThreadGroup() but they evaluate to null.
So far what 'works' for me is ${__jexl3(props.get("ThreadGroupName1-NumberOfThreads"))} but I want it be parametrized by the name of the thread group.
Is it possible to do this?
Is this threadName returning standardjmeterengine a bug?
Update: In fact, the easiest 'solution' that provides the parametrized number of threads there is ${__P(ThreadGroupName1-NumberOfThreads)} and what I want is to generate this key ThreadGroupName1-NumberOfThreads to be something like ${MyCurrentGroupName}-NumberOfThreads, effectively providing a way to have an abstract method like
int GetNumberOfThreads(string threadGroupName)
{
return properties.get(threadGroupName + "-NumberOfThreads";
}
Similarly, I wish to use this patter in Constant Throughput Timer as well with another prefix like -Rpm.
I don't think you can use any JMeter Function in the "Number of Threads" field of the Thread Group so this is not something you can do via UI. If you believe this is something everyone needs you can consider raising an enhancement request
As a workaround you can
Set the number of threads to 1
Add If Controller to the Thread Group and use the following __groovy() function as the condition:
${__groovy(ctx.getThreadNum() == 0 && vars.getIteration() == 1,)}
Add JSR223 Sampler as a child of the If Controller and put the following code into "Script" area:
SampleResult.setIgnore()
2.upto(props.get(ctx.getThreadGroup().getName() + '-NumberOfThreads') as int, { ctx.getThreadGroup().addNewThread(0, ctx.getEngine()) })
This way each thread Group will normally start with 1 thread, however this thread will read the property you defined earlier and add as many threads as needed.
You can use JMeterContext's getThreadNum to get thread number (increment, because it starts with 0)
${__jexl3(props.get("ThreadGroupName"))}${__jexl3((ctx.getThreadNum()+1) + "-NumberOfThreads" )}
I am trying to create a jmx to test some database entries. The exact queries are not known beforehand and need to be picked from one of many sets of queries, that I have declared in separate pre-processor units.
For eg. one of the set of queries is:
String[][] animals = new String[][]{
{"VLS_CATS_ASSOC","CAT_ID_AS = '${CAT_ID_AS}'"},
{"VLS_DOGS_EXCH","DOG_ID_ST = '${DOG_ID_ST}' and DOG_TXT_REF = '${DOG_TXT_REF}'"},
};
The 2D array has two entries, the 'table name' and the 'where clause'
So, the jdbc request is select * from ${table_name} where ${where_clause}
I've set up a loop controller for iterating through the tables one by one, and as a child i have jdbc sampler, that has the csv table config which will contain data for CAT_ID_AS, DOG_ID_ST, DOG_TXT_REF.
Currently, when i see my requests through a results listener, i see that the queries sent are:
select * from VLS_CATS_ASSOC where DOG_ID_ST = '${DOG_ID_ST}' and DOG_TXT_REF = '${DOG_TXT_REF}'
It is clear from the output that the first level of substitution has worked, but not the second one.
Can anybody please help me on this?
Edit: Adding an image of the test plan. Jmeter Test Plan
Don't use ${CAT_ID_AS} notation in (I presume) the BeanShell strings: while it is generally working, that's an undocumented and error-prone feature.
The legit way is vars.get("CAT_ID_AS")
vars is a pre-defined object available in any BeanShell piece inside your test plan
So your code would be looking like
String[][] animals = new String[][]{ {"VLS_CATS_ASSOC","CAT_ID_AS = '" + vars.get("CAT_ID_AS") + "'"}, ... etc
I am writing a jmeter script that keeps loading data until a table reaches a specified size. I have a while loop, in which I have one HTTP Sampler to loads the data, then another HTTP Sampler with an XPath Post-processor to check the table size (they call two different APIs). The reference variable of the XPath Post Processor is currentSize and I have a user defined variable maxSize, but using ${currentSize} < ${maxSize} as the condition for the while loop creates an infinite loop.
Thinking maybe the problem is that the output of XPath is a string, I've tried doing various things in beanshell to coerce it to a number, but I'm a beanshell noob, so I haven't been successful with that either. Can anyone guide me about how to get jmeter to recognize a variable as a number? (Preferably a decimal, but if I have to round to an int, I can live with that.)
Thanks!
I think using __javascript(parseInt()) should suffice for you to check the condition.
e.g.
${__javaScript(parseInt(${time_elapsed_string}) < parseInt(${duration}))}
Assuming that you have following variables:
currentSize
maxSize
continue
where continue is set via User Defined Variables and has the value of true
You can use following Beanshell code to check if current size is equal or greater than maximum size:
import java.math.BigDecimal;
String currentSize = vars.get("currentSize");
String maxSize = vars.get("maxSize");
BigDecimal currentSizeNumber = new BigDecimal(currentSize);
BigDecimal maxSizeNumber = new BigDecimal(maxSize);
if (currentSizeNumber.compareTo(maxSizeNumber) > -1){
vars.put("continue", "false");
}
Make sure that following criteria are met:
Your While Controller has ${continue} as a condition
Beanshell Sampler, Pre / Post Processor or Assertion with the code above is added as a child of the While Controller
See How to use BeanShell guide for more details and kind of Beanshell cookbook.
Everything should work this way.
Hope this helps.