JMeter: Passing Results of SQL Query as a Variable - jdbc

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.

Related

Graphql in jmeter

I am using graphql in jmeter for API testing. Where in graphal we have the query and variable section.
My query would require a client ID which is int. Where as in Variable if I try to pass "{clientid : ${clientid}}"(here I am passing the CSV config variable, for testing the app for multiple users). But it is throwing an error like $ is unauthorised and expecting a (json,null,true or false).
Please help me out how I can pass the clientid which is a csv config variable.
Thanks in advance.
It looks like your CSV Data Set Config setup is not very correct so the JMeter Variable placeholder isn't getting substituted with its respective value from the CSV file.
We cannot help without seeing first couple of lines of the CSV file and your CSV Data Set Config setup so far I can only suggest re-visit the configuration and cross-check it with JMeter Documentation
You can observe JMeter Properties and Variables with their values using Debug Sampler and View Results Tree listener combination, if you don't see clientid line there - the variable is not set and JMeter sends it as it is, to wit "{clientid : ${clientid}}" and doesn't substitute ${clientid} with the value from CSV

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

Using Extracted JSON Value in Another JMeter Thread

First, let me preface this question that I've only been using JMeter for 36 hours.
I've been able to successfully create a thread that performs a POST (json body) to generate a new record.
{
"id":1257697771,
"displayName":"TERM2",
"functionName":"f_1257697771",
"displayableSourceExpression":"TRUE",
"typeId":200,
"groupId":300,
"clobObjId":1257697772,
"typeCode":5,
..........
}
I need to take the new record's ID (1257697771) value returned in order to perform updates, get by ID, delete, etc. on this record in other threads.
After much reading, I've created a Regular Expression Extractor where:
Apply to: Main Sample Only
Field to Check: Body as Document
Reference Name: newRecord
Regular Expression: "id":(.+?)\,"displayName"
Template: $1$
Match No: 1
Default Value: NONE
At this point, I'm not sure if my Regular Expression is formatted correctly where (.+?) is valid.
Also, I'm confused if I can either just specify the new reference (newRecord) in another thread's HTTP request's Parameters or use a BeanShell Post-Processor, or a Response Assertion, etc....
There a lot of answers for the same function of "Passing". Not being a programmer, I've tried to follow the discussion "how to extract json response data in jmeter using regular expression extractor?", but I'm still not clear.
Any insight is appreciated. Thanks.
JMeter Variables are local to Thread Group, you need to convert your variable to JMeter Property.
Use:
__setProperty() function in the Thread Group where you define your newRecord variable like:
${__setProperty(newRecord,${newRecord},)}
__P() function to access property value like:
${__P(newRecord,)}
See Knit One Pearl Two: How to Use Variables in Different Thread Groups article for more detailed explanation.
Also be aware of the Function Helper Dialog as it looks like JMeter functions syntax was developed by aliens.
To pass a value between threads you need to use the jmeter property function.
In a jsr223 postprocessor using groovy the code to get the value is as follows:
def userProperty = props.get('propertyToGet')
vars.put('userProperty', String.valueOf(userProperty))
You would then access the variable in your thread using:
${userProperty}
Or you can use shorthand directly:
${__P('propertyToGet')}
Variables in jmeter are thread specific.
Thanks everyone. I was able to resolve it with your help!
In the first thread:
set the Reg Expression Extractor Regular Expression = "id":(.+?)\,"displayName"
added a Bean Assertion where Parameters = ${__setProperty(newRecord,${newRecord},)}
In the second thread:
appended the Path url with ${__P(newRecord,)}
Executing the first thread (POST) resulted an new record with a unique ID. (1257698108)
Executing the 2nd thread (GET) shows
GET http://server/.../.../.../.../1257698108
And returns the exact data generated in the first thread.
Thanks everyone for your help!

How can I get exatcly one row from database query for every course loop

I creating script which let me to get values from database.
Now, when I'm executing query oracle returning me too many values.
My query looks like that : select * FROM OFFERS
I'm getting:
OFFER_NR_#=101042
OFFER_NR_1=0001G000210
OFFER_NR_10=0001G000411
and many many more...
I want to take exactly one value e.g. OFFER_NR and use it in request
------- request SEARCH_OFFER ${OFFER_NR} = 101042
During next course loop I want to take another value as variable
------- request SEARCH_OFFER ${OFFER_NR} = 0001G000210
It's just like using CSV FILE CONFIGURATION, which can give me exactly each next row for every thread group iteration, but I don't know how can I do this the same using jdbc request.
1 You need to use ForEach Controller configured as follows:
Input Variable Prefix: OFFER_NR
Output Variable Name: anything meaningful, i.e. CURRENT_OFFER
Check `Add "_" before number" box
Place your 2nd request under the ForEach Contoller
Refer each subsequent OFFER_NR as ${CURRENT_OFFER} where required
See Debugging JDBC Sampler Results in JMeter guide for more detailed explanation of your and other situations

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