Jmeter - JSR223 PostProcessor operates on the following ForEach iteration - foreach

Problem
The JSR223 shifts its processing. On the first ForEach iteration I expect the JSR223 to produce a given value, but I see that expected value on the debug postprocessor of the following interation instead.
Why is this happening?
Scenario
I have a set of companies (thread group). Each company has a set of Stores (ForEach #1). Each store has a set of "location groups" (ForEach #2). Each location group has its own type.
Scenario outline
The location group type is a numeric value, from 1 to 12. Let's say the ForEach controller iterating these location groups produce this sequence of types: 6, 9, 5, 11, 7, 12, 10 and JSR223's code is as follows:
if (vars.get("locationGroupType") == "6"){
log.info("Store:" + vars.get("anUnit"))
log.info("location group ID:" + vars.get("aLocationGroupId"))
vars.put("aux", "SIX")
log.info("location group type:" + vars.get("locationGroupType"))
}
if (vars.get("locationGroupType") == "9"){
log.info("Store:" + vars.get("anUnit"))
log.info("location group ID:" + vars.get("aLocationGroupId"))
vars.put("aux", "NINE")
log.info("location group type:" + vars.get("locationGroupType"))
}
I would expect aux to be SIX on the first iteration, then NINE on the second.
Output
This is JSR223's output to console:
Console output
You can see the store 292 has a location group id of 3803 which has a type value 6. But this information is NOT correct.
Request output for location group id 3803, which has a type value of 9:
location group 3803 response
Debug postprocessor dump where I can see 'aux' set to SIX:
debug postprocessor
Oddly enough, the previous request to 3803 is the one that has the type value 6, and this is where I expect aux to be SIX:
Response for 3635 where the type value 6 is found
And the debug postprocessor for 3635 showing 'aux' to be empty:
enter image description here

If you plan to use all these values: 6, 9, 5, 11, 7, 12, 10 it's better to go for switch statement instead of multiple if's.
Isn't it a copy-paste issue and shouldn't your code look like:
switch (vars.get(('locationGroupType'))) {
case '6':
log.info("Store:" + vars.get("anUnit"))
log.info("location group ID:" + vars.get("aLocationGroupId"))
vars.put("aux", "SIX")
log.info("location group type:" + vars.get("locationGroupType"))
break
case '9':
log.info("Store:" + vars.get("anUnit"))
log.info("location group ID:" + vars.get("aLocationGroupId"))
vars.put("aux", "NINE")
log.info("location group type:" + vars.get("locationGroupType"))
break
default:
log.info('default branch')
break
}
Otherwise I can think of the following reasons:
JMeter Post-Processor placement matters, i.e. if your have Debug Post-Processor before the JSR223 Post-Processor you won't see the variables generated in the JSR223 Post-Processor until next iteration
JSR223 PreProcessor is executed after each Sampler in its scope so make sure that it's placed correctly and fired only where it's supposed to fire.
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Ok, what I describe in my thread was a Jmeter issue. I just tried the same exact script in Jmeter 5.5 and the shifting problem has been resolved.

Related

ForEachController is picking duplicate values from regular expression variable results when match count set to -1 when executing with more than 1 user

Jmeter ForEach controller is picking duplicate values from regular expression variable results when match count set to -1.
ThreadGroup
--Req1
--Req2
---RegEx: with Match No. -1 (Debug Sampler shows match count: 40 )
---ForEach Controller
----Http req using ForEach controller's output variable
It is picking correctly for single user and when executing with more than 1 user, its picking duplicate values
Please guide
Of course it does.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So each thread (virtual user) executes Req2 and Regular Expression Extractor returns 40 variables. So each user has its own set of 40 variables and uses the ForEach Controller to iterate them
If you have more than one user and need each user to have it's own variable or set of variables you could:
Perform the extraction of these 40 variables with 1 thread somewhere in setUp Thread Group
Convert the JMeter Variables into JMeter Properties using JSR223 Post-Processor and the code like:
1.upto(vars.get('myVar_matchNr') as int, {
props.put('myVar_' + it, vars.get('myVar_' + it))
})
props.put('myVar_matchNr', vars.get('myVar_matchNr'))
That's it, you should be able to access 1st variable where required using __P() function like ${__P(myVar_1,)}, 2nd variable as ${__P(myVar_2,)}, etc.
Counter is the cause of problem in my request,
Track counter independently for each user --> Unchecked, causing the issue

How to fix an output error in Python ? It keeps displaying 'None'

I've written a code for 20 Questions Game that should guess the number a user has selected from 1 to 100. But, it keeps displaying the same output again and again which is as given below. Please help me find the error.
The Code is:
a=1
b=10
for i in range(a,101):
y=input(print("Is your number b/w",a,"to",b,"including both ? Answer Yes or No"))
if(y==Yes):
j=a
for j in range(a,b+1):
x=input(print("Is your no.",j,"?"))
if(x==Yes):
print("Your number is",j)
else:
j=j+1
if(y==No):
break
a=a+10
b=b+10
The Output looks like this
Is your number b/w 1 to 10 including both ? Answer Yes or No
None
Take a look at some examples online of how the input function is used and what it takes as a parameter.
The value None you are seeing is the return of the print statement.
input(print("Is your number b/w",a,"to",b,"including both ? Answer Yes or No"))
Should be:
input("Is your number b/w " + str(a) + " to " + str(b) + " including both ? Answer Yes or No")
input accepts a string as a parameter, that gets printed. You passed print as the parameter.
Since print doesn't return anything, hence you get the output as None
Also, unless you have defined Yes and No as variables, they should be enclosed in single or double quotes:
Either this way (not recommended):
Yes = 'Yes'
No = 'No'
....
Or this way(recommended):
if y=='Yes':
....
You need to make changes in this manner for all your input and if statements.

JQL for this condition

how would the JQL look like for this condition?:
Generate a report of all HIGH severity JIRA tickets for a project with key X (or name X) that were created from 9 PM EST to 12 AM EST from the start of the year?
I tried something like :
Project = X AND Severity = "HIGH" AND created > "2015/01/01 21:00" and created < "2015/09/09",
but I need only those issues that are created between 9 PM and 12 AM everyday, from the beginning of the year.
Any ideas would be greatly appreciated.
Unfortunately there seems to be no tool to get the hour from created date but you can workaround it.
My two ideas are:
find these tickets directly on Jira database (if you have access) it should be very easy since there are functions like hour (mySQL) or truncate (postgres)
prepare JQL filter using some generator script - it is definetely less comfortable but possible to achieve even when you have not acces to database. The worst thing is that Jira filter fields accepts only 2000 characters string so you would need to copy that filter few lines by few lines.
Little crazy but ok - it works so what's the idea? The idea is to use startOfYear() JQL function and its *offset version**. For example:
created >= startOfYear(21h) and created < startOfYear(24h)
will give you all tickets from 1 Jan 21:00 - 2 Jan 00:00
then you can use this Python script:
step = 27
maxDay = 1
while maxDay <= 365 + step:
maxDay += step
output = "project = X and Severity = HIGH and ("
for i in range(maxDay-step, maxDay):
output += " (created >= startOfYear(" + str( ( (i-1) * 24 ) + 21) + "h) and created < startOfYear(" + str(i*24) + "h)) or"
output = output[:-3]
output += ")"
print output
print
which will generate you set of JQL requests to copy-paste and execute (it is actually 15 of them - you can see here). Every set bounds 28 days because of 2000 limit of filter input in Jira.
I fixed this issue by writing a custom JQL function and then using that function with a JQL query, which fits well with our requirements :
created >= "2015-01-01" and created <= "2015-12-31" and issue in getIssuesForTimeRange("21", "24")

Can we create the targets at run time using informatica Powercenter

When we do not know the number of targets, Can we create the targets at run time using informatica Powercenter.
Suppose we have below source:
Employee:
Dept_ID EmpName Sal
10 A 200
11 B 100
10 C 200
10 D 400
12 E 500
12 F 400
...
It can have any number of distinct Dept_ID.
I want to load all EmpName and Sal of a particular Dept_ID into a separate target table (i.e target name should be as Tar_10 or Tar_11 where 10 & 11 are Dept_ID).
You can achieve this by the following method:
While creating the target check the include file name port checkbox.
Use an expression to create the file name port name, something like " 'Tar' || Dept_ID" should do.
Use a sorter to sort your input with respect to Dept_ID.
Use a transaction control transformation on the condition that when Dept_ID is different from previous Dept_ID use "TC_COMMIT_AFTER", this will keep changing the file name depending on your input.
Your Output will look like this :
TAR_10
10 A 200
10 C 200
10 D 400
TAR_11
11 B 100
TAR_12
12 E 500
12 F 400
Yes Sumit is right. You can achieve this by creating the File name port and Transaction control. Also if your target is file then you can write the whole record in 1 port so there is no need to worry about the target structure either.

How do I get a random number in template toolkit?

I want to get a random number using template toolkit. It doesn't have to be particularly random. How do I do it?
Hmm, you might have issues if you don't have (or cannot import) Slash::Test.
From a "vanilla" installation of TT, you can simply use the Math plugin:
USE Math;
GET Math.rand; # outputs a random number from 0 to 1
See this link in the template toolkit manual for more information on the Math plugin and the various methods.
Update: Math.rand requires a parameter. Therefore to get a random number from 0 to 1, use:
GET Math.rand(1);
From this post at Slashcode:
[slash#yaz slash]$ perl -MSlash::Test -leDisplay
[%
digits = [ 0 .. 9 ];
anumber = digits.rand _ digits.rand _ digits.rand;
anumber;
%]
^D
769

Resources