Pass DBID value twice in single request - jmeter

I need to pass the DBID value two times in the single request, I have tried placing _counter function twice, but it is updating the counter value every time when it is hitting
<v13:taskIdentifier>${__evalVar(taskcounter)}</v13:taskIdentifier>
<v13:databaseId>${__evalVar(dbid_${__counter(TRUE,)})}</v13:databaseId>
</v12:uniqueTaskIdentifier>
<v14:executionTime>
<v15:value>${__time(YYYY-MM-dd)}T13:00:00</v15:value>
</v14:executionTime>
<v14:resourceLocation>
<v16:identifierLocation>
<v17:type>Unique Task Identifier</v17:type>
<v17:identifier>${__evalVar(dbid_${__counter(TRUE,)})}${__evalVar(taskcounter)}</v17:identifier>
Is there any other option to get the same counter value second time ?

I suggest you save the value in User Parameters which will be a child of the request
allows you to specify a series of values for any User Variable. For each thread, the variable will be assigned one of the values from the series in sequence. If there are more threads than values, the values get re-used.
Define parameter value as ${__counter(TRUE,)} and for example name c
Then use in XML ${c} instead
<v13:taskIdentifier>${__evalVar(taskcounter)}</v13:taskIdentifier>
<v13:databaseId>${__evalVar(dbid_${c})}</v13:databaseId>
</v12:uniqueTaskIdentifier>
<v14:executionTime>
<v15:value>${__time(YYYY-MM-dd)}T13:00:00</v15:value>
</v14:executionTime>
<v14:resourceLocation>
<v16:identifierLocation>
<v17:type>Unique Task Identifier</v17:type>
<v17:identifier>${__evalVar(dbid_${c})}${__evalVar(taskcounter)}</v17:identifier>

Your __counter() function generates an incremented value each time it's being called
The options are in:
Switch to Counter configuration element
Amend your current setup as follows:
1st occurrence: ${__evalVar(dbid_${__counter(TRUE,dbid)})}
this will store the generated counter number into ${dbid} JMeter Variable
2nd, 3rd, etc. occurrences: ${__evalVar(dbid_${dbid})}
More information: How to Use a Counter in a JMeter Test

Related

Jmeter - Break down huge JDBC query into multiple JDBC queries

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

postman - locking random value, same value for every test in same collection

Is there a way to 'lock' random value in postman? I would like to generate one random value and use same value for every test in same collection.
this code generate different random value for every test:
pm.environment.set("random", _.random(0,9999999));
You could you use this in the pre-request:
let randomNum = pm.variables.replaceIn("{{$randomInt}}")
pm.variables.set("randomNum", randomNum)
Then use {{randomNum}} in the requests.
Solution to my problem was setting global variable in 'pre-request script' only for first request of the collection, and leaving 'pre-request script' empty for every next request:
pm.globals.set("randomNum", _.random(0,9999999));
But thanks for your comment anyway #Danny Dainton. I should use 'request' instead of 'test' in my question. What probably misleaded your thinking.

Jmeter $__Random() with user defined variables

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

How to parametrize number of threads in JMeter 5.2.1

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" )}

How to read JMeter Test Cmd Line Parameters from JSR223/Beanshell

I have wrote a JMeter test and I want to run it in Command Line with some parameters, let's say ThreadNumber.
How do I read it in JSR223/BeanShell?
Send property in command line using -J which adds new property
-JthreadNum=100
Inside Thread Group use the value using __P function in Number of Users(threads) field
${__P(threadNum)}
simplified property function which is intended for use with properties defined on the command line.
Use props to get properry in JSR223/BeanShell
props.get("threadNum")
Note you may set ramp up same as thread number property
Start with Ramp-up = number of threads and adjust up or down as needed.

Resources