Jmeter jdbc results variable to http - jmeter

So i a using this query
select f_authority, username from account where username like 'jmca_%' and status = 'account.status.active' order by f_principal;
My data Are :
f_authority username
1002 jmca_1000
1003 jmca_1001
1004 jmca_1002
i Want to use every f_authority and useranme in same for each loop in deferent http call..
i am using
vars.put("credentials",vars.get("username"));
the think is that i cant get f_authority from for each controller but how i can get username or both variable with beanShell???

You will get the following JMeter Variables defined as the result of the JDBC Sampler call:
f_authority_1=1002
f_authority_2=1003
f_authority_3=1004
f_authority_#=3
username_1=jmca_1000
username_2=jmca_1001
username_3=jmca_1002
username_#=3
If you want to iterate both of them in a single ForEach Controller:
For f_authority just put it into "Input variable prefix" and Output Variable Name fields
For username you can use __V() and __intSum() functions combination
${__V(username_${__intSum(${__jm__ForEach Controller__idx},1,)},)}
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Related

Passing one api parameters value to another api

In JMeter I have two Api , one api generate filename and id then these parameters pass to another api here I used plugin path extractor and also use csv data set config to extract , save and pass parameters and its value to another api but problem is when multiple user it generate multiple filename and id but how to pass those file name and id to every httprequest to another api.
You don't need any CSV Data Set Config, it will be sufficient to
Add a suitable Post-Processor to extract the generated file name
The Post-Processor will store the generated name into a JMeter Variable
You should be able to use the variable in the "2nd API"
As per JMeter Documentation Variables are local to a thread so each thread (virtual user) you define in the Thread Group will have its own value.
Demo:
More information on JMeter Correlation concept: Advanced Load Testing Scenarios with JMeter: Part 1 - Correlations

Using JMETER GUI JDBC Request with Callable Statement – how do I getResultSet/MetaData?

I’ve got a call to my database working as a SQL select statement. But I am working to call a stored procedure using JMeter for further testing. I’m strictly working off of the JMX files and do not have JMETER integrated into our main Java project at this time.
I’ve setup the JMETER GUI with the JDBC Connection Configuration and the JDBC Request. I’ve made a successful call to my database with my callable statement with my string INPUT and get the string OUTPUT parameter string.
The OUTPUT parameter string only contains information about the call (user,system, success, etc…), but none of the values/data from the table -- which are found in the ResultSet/MetaData. But I cannot figure out how to get the ResultSet or the Metadata using the JDBC Request in JMETER.
In Java, I know I use the statement and just call statement.getResultSet() and perform a loop while resultSet.next() exists. How do I do this in JMETER?
I've tried adding an additional out parameter but then my statement rejects the call, because there is only one in-parameter. I've tried a variety of JMeter Assertions - but because the main call is only returning the out parameter, I cannot grab additional data.
Query: call XXXXX.readUser(?)
Parameter Values: ${inputJSONString}
Parameter Types: INOUT VARCHAR
Variable Names: ouputJSONString
Result Variable Name: ouputJSONString
View Results Tree: Response code: 200, Response message: OK, Output variables by position: Contains the whole JSON out parameter string with user, system, and success. Returns the table column headers but no values.
I do not have errors - the call is being made successfully. I just cannot figure out how to access the Result Set from JMETER.
Don't use the same reference name for the Variable Names and the Result Variable Name as the latter one will be overwritten.
So
Change ouputJSONString to i.e. ouputJSONStringObject
Add JSR223 PostProcessor as the child of the request
You will be able to access the JMeter's representation of the ResultSet as vars.getObject('ouputJSONStringObject') (basically ArrayList of HashMaps
See Debugging JDBC Sampler Results in JMeter article for more details.
Unfortunately you cannot access the normal ResultSet as it is not exposed anywhere and being converted via private function

Looping in Jmeter

Looping test occurrence based on the data count retrieved from the JDBC request and also as input data for the HTTP request
I have test scenario where i need to use the DB output as the input criteria for the HTTP request. Based on the DB output count( from the first request) i need to loop the HTTP request and it data accordingly
I tried the logical Loop Count by passing the count variable from run time as ${TEST_ID_#}, still its not working.
I tried the logical Loop Count by passing the count variable from run time as ${TEST_ID_#}, still its not working.
Debug Sampler Output
You can extract the counter using Post Processor [either Regular Expression Extractor or JSON Extractor etc.]
Once you have extracted that count, now place a Loop controller as a parent of HTTP request.
For example. I am using User Defined Variable for loop Count:
Any reason for using ${TEST_ID_#} variable? If your Debug Sampler screenshot is full and correct you should be using ${KEY_ID_#} instead.
Also it might be a better idea to use ForEach Controller instead of the Loop Controller, the relevant configuration would be something like:
References:
How to Use ForEach Controller in JMeter
Using Regular Expressions in JMeter

JMeter: Passing Results of SQL Query as a Variable

I've been reading through the forums, the Apache JMeter guide, and BlazeMeter's The Real Secret to Building a Database Test Plan With JMeter and Using JDBC Sampler In JMeter, but I'm still kind of lost.
I need to issue a query to extract an Obj ID value from a table and pass that value into an HTTP READ Request. I've done the following setup:
JDBC Request
Variable Name: Pool-1
Query Type: Select Statement
Query: select distinct ObjId from dbo.CommonRuleSet where Name like '%ABC%';
Param. values:
Param. types:
Variable names: abcObjId
Result variable name: abcCommonRule = vars.getObject("resultObject").get(0).get("ObjId");
Query Timeout (s): 5000
Handle Result Set: Store as Object
When executed results in:
ObjId
1136682203
I'm trying to figure out how to pass in this ObjId value as a variable to append the URL.
HTTP REQUEST
database:port/applicationServer/../../crud/CommonRuleSet/????
I've tried appending using:
the Variable names value: ${abcObjId}
the Result Variable Name: ${abcResult}
Each time, JMeter is not translating the variable resulting in a parser error. (e.g., http://database:port/.../.../.../crud/CommonRuleSet/${abcResult})
I'm just not understanding how to take the results of my successful query and pass it as a variable to an HTTP Request. Any insight/enlightenment is much appreciated!
The solution was:
//database:port/.../.../.../crud/CommonRuleSet/${abcObjId_1}).
I guess I didn't go through enough BlazeMeter pages before posting my question. I found the solution on Debugging JDBC Sampler Results in JMeter.
The section explaining the difference and usage between Variable Names and Result Variable Name made all the difference. I now understand the Result Variable Name is an ArrayList of HashMaps, which I don't need in this scenario.
So I changed the Result Variable Name field from: abcCommonRule = vars.getObject("resultObject").get(0).get("ObjId"); to: result,
Next, since I want to directly access the Variable Name 'abcObjId', I modified the variable that appends my URLfrom: ${abcObjId}to: ${abcObjId_1}. I was so close... so close....
Thanks to dmitri-t and the folks at Blazemeter.

Jmeter: Capture JDBC value in global variable

I'm very new to Jmeter and I'd like to know if there is some way to store the result of a query in a global variable to use in a different thread.
In other words, I need a set-up thread that sets a start-date and end-date (2 values) from the DB.
Then, in a second thread (the main thread), I have to use the start-date and end-date as parameters for the tests.
Is this possible?
Thanks in advance!,
Nahuel
Use the following elements:
JDBC_Connection_Configuration
JDBC Request
BeanShell Sampler
setUp Thread Group
Organize them as following:
It will work as following:
JDBC Connection Configuration will setup the connection to DB, name Variable name so that it matches Variable name of JDBC Request, in my case I name it conn
Setup Thread Group will run query through JDBC Request and store result in variables
Beanshell sampler with use the value and store it as a property so it can be shared by all threads.
Note the following:
The variable names of JDBC Request must match the number of columns returned by your SQL Query, note in example I have 3 columns, I put 3 variables, and will use clt_nom_1 name as I ensure there is only row returned by query
In Bean Shell sampler I put the following code:
props.put("toto",vars.get("clt_nom_1"));
clt_nom_1 is named like this because it's the first row value
Finally in Thread Group I can use property toto through:
${__P(toto)}
You could also replace BeanShell sampler by a debug sampler named:
${__setProperty(toto,${clt_nom_1})};
which would store variable in property
I have done it differently:
I created a BSF PostProcesser use 'Javascript' as the language:
var strData = prev.getResponseDataAsString(); //This is a string delimited with character return
var listData = strData.split('\n');
Then you can do all sort of things like from your list data, such as vars.putObject.
NOTE:It works with SELECT query on JDBC request.

Resources