How to connect with My Sql database without using JDBC Connection Configuration and JDBC Samplers?
I want to establish connection with My SQL database without using JDBC Connection Configuration and JDBC Samplers as I don't want to keep the database credentials in .JMX file for security reasons.
You don't need to put password (/user) inside jmx file, you can load values using property
For example use __property to get value from property instead of hardcoded value:
${__property(password)}
The property function returns the value of a JMeter property
properties can be set adding to properties file or command line parameter
Java system properties and JMeter properties can be overridden directly on the command line (instead of modifying jmeter.properties).
-J[prop_name]=[value]
defines a local JMeter property.
If you don't want to use JDBC test elements for building a database test plan you can always switch to JSR223 Test Elements and program whatever you want using Groovy language, in your case your friend is groovy.sql.Sql
Example code:
def dburl = 'jdbc:mysql://192.168.99.100:3306/mysql'
def user = 'root'
def password = props.get('db.password')
def driver = 'com.mysql.cj.jdbc.Driver'
groovy.sql.Sql.withInstance(dburl, user, password, driver) { sql ->
sql.query('select name,url from help_topic order by rand() limit 2;') { resultSet ->
while (resultSet.next()) {
def name = resultSet.getString(1)
def url = resultSet.getString('url')
log.info('Topic name: ' + name + ' topic url: ' + url)
}
}
}
Example output:
This line: props.get('db.password') is reading the value from JMeter Properties, you can set the property value using -J command-line argument like:
jmeter -Jdb.password=secret -n -t test.jmx -l result.jtl
Check out Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in Jmeter
You will still need to have MySQL Connector/J in JMeter Classpath
Related
When using the WebDriver plugin for JMeter and using subsamples the labels that are set during the test do not appear in the results jtl file (and therefore the results tree/aggregate report etc.
WebDriver code (name = TestSampler):
WDS.sampleResult.subSampleStart('First SubSample')
...
WDS.sampleResult.subSampleEnd(true)
WDS.sampleResult.subSampleStart('Second SubSample')
...
WDS.sampleResult.subSampleEnd(true)
Desired outcome:
result.jtl file:
...
1603546255925,1000,First SubSample,,,ThreadGroup 1-1,text,true,,0,0,1,1,null,0,0,0
1603546257658,1000,Second SubSample,,,ThreadGroup 1-1,text,true,,0,0,1,1,null,0,0,0
Actual outcome:
result.jtl file:
...
1603546255925,1000,TestSampler-0,,,ThreadGroup 1-1,text,true,,0,0,1,1,null,0,0,0
1603546257658,1000,TestSampler-1,,,ThreadGroup 1-1,text,true,,0,0,1,1,null,0,0,0
note that the only difference is that the value passed to the ...subSampleStart(label) function appears in the result file instead of an indexed version of the sampler name.
Add the next line to user.properties file:
subresults.disable_renaming=true
Restart JMeter to pick the property up
Next time you will run your test you will see expected names
For GUI mode you can tick Functional Test Mode box on Test Plan level:
More information:
JMeter Bug 62550 - Modify SubResult Naming Policy
Apache JMeter Properties Customization Guide
Configuring JMeter
${__P(thread,1)---- using this function in "number of threads" at JMX file, the following java code run incorrectly. While using correct numbers it worked. But I want this place can be changeable.
I'm developing a performance testing platform using Jmeter API.
StandardJMeterEngine standardJMeterEngine=new StandardJMeterEngine();
System.setProperty(JMeter.JMETER_NON_GUI, "true");
JMeterUtils.loadJMeterProperties("D:\software\java\apache-jmeter-5.1\bin\jmeter.properties");
JMeterUtils.loadJMeterProperties("D:\software\java\apache-jmeter-5.1\bin\system.properties");
JMeterUtils.loadJMeterProperties("D:\software\java\apache-jmeter-5.1\bin\user.properties");
JMeterUtils.loadJMeterProperties("D:\software\java\apache-jmeter-5.1\bin\saveservice.properties");
JMeterUtils.setJMeterHome("D:\software\java\apache-jmeter-5.1");
JMeterUtils.initLocale();
JMeterUtils.initLogging();
SaveService.loadProperties();
Properties jmeterProps = JMeterUtils.getJMeterProperties();
jmeterProps.put("thread","10");//
File file=new File("F:\a.jmx");
FileServer.getFileServer().setBase(file);
FileServer.getFileServer().setScriptName(file.getName());
Field baseField = FileServer.getFileServer().getClass().getDeclaredField("base");
baseField.setAccessible(true);//
baseField.set(FileServer.getFileServer(), file.getAbsoluteFile().getParentFile());
HashTree scripts=SaveService.loadTree(file);
Summariser summariser = new Summariser(JMeterUtils.getPropDefault("summariser.name", "summary"));
ResultCollector logger = new ResultCollector(summariser);
logger.setFilename("F:\a.jtl");
scripts.add(scripts.getArray()[0],logger);
JMeter.convertSubTree(scripts);
standardJMeterEngine.configure(scripts);
standardJMeterEngine.runTest();
You need to close your {
${__P(thread,1)}
And 1 is the default so you can use
${__P(thread)}
The default value for the property. If omitted, the default is set to "1".
Make sure to explicitly add ApacheJMeter_functions.jar to your project CLASSPATH otherwise neither __P() nor other JMeter Functions will work properly.
Also make sure to escape backslashes like change:
logger.setFilename("F:\a.jtl");
to
logger.setFilename("F:\\a.jtl");
or use forward slashes instead:
logger.setFilename("F:/a.jtl");
More information: Five Ways To Launch a JMeter Test without Using the JMeter GUI
i am facing multiple problems with my .jmx file.
I am working with bzm-concurrency thread group
1) it is not recognising the standard format of passing the user defined values
like: ${__P(SERVER_NAME,localhost)} instead of passing "localhost" to my script it is appending "${__P(SERVER_NAME,localhost)}" to my url.
After passing only the value i.e (localhost) it is working fine
2) Also, iam running my jmeter script from build.gradle file and iam unable to pass the url and other details from them
|SERVER_NAME|${__P(SERVER_NAME,localhost)}| --> this code is not working
|SERVER_NAME|localhost| --> this code is working fine
jmeter {
jmTestFiles = [file("src/main/Jmetrscript.jmx")]
jmSystemPropertiesFiles= [file(path of my properties file)] //to add additional system properties
jmUserProperties = ["SERVER_NAME ="+System.getProperty('SERVER_NAME','localhost'), "SERVER_PORT ="+System.getProperty('SERVER_PORT','9080') ]
enableExtendedReports = true //produce Graphical and CSV reports
}
when i run this using gradlew jmRun -DSERVER_NAME=localhost it is not passing the value.
As per JMeter Gradle Plugin - Advanced Usage
Supported JMeter commandline arguments (see full list here):
-p, --propfile {argument}, the jmeter property file to use
-q, --addprop {argument}, additional property file(s)
-t, --testfile {argument}, the jmeter test(.jmx) file to run
-J, --jmeterproperty {argument}={value}, Define additional JMeter properties
-D, --systemproperty {argument}={value}, Define additional System properties
-S, --systemPropertyFile {filename}, a property file to be added as System properties
-r, --runremote (non-GUI only), Start remote servers (as defined by the jmeter property remote_hosts)
-G, --globalproperty (argument)[=(value)], Define Global properties (sent to servers), e.g. -Gport=123, or -Gglobal.properties
So you should pass JMeter Properties via -J command-line argument like:
jmRun -JSERVER_NAME=localhost etc
References:
Overriding Properties Via The Command Line
Apache JMeter Properties Customization Guide
While executing the test through JMeter I found in Jmeter log:
2017/12/21 02:37:06 INFO - jmeter.services.FileServer: Default base='/u02/project/gold'
2017/12/21 02:37:06 INFO - jmeter.services.FileServer: Set new base='/home/project/gold/JMX'
I am executing the test from /u02/project/gold/apache-jmeter-3.1 but do not know from where JMeter set new base value which is another directory '/home/project/gold/JMX'? Please let me know how I can restrict jmeter to set new base value?
As per Apache JMeter version 3.3 FileServer class source code:
private static final String DEFAULT_BASE = System.getProperty("user.dir");// $NON-NLS-1$
So it should take user.dir (User working directory) Java System Property value as a default
If you need to override this to have another value you can set it by adding the next line to system.properties file (lives in "bin" folder of your JMeter installation)
user.dir=/some/custom/path
JMeter restart will be required to pick the property up.
Another option is setting the property value via -D command-line argument like:
jmeter -Duser.dir=/some/custom/path -n -t test.jmx -l result.jtl
More information:
Configuring JMeter
Apache JMeter Properties Customization Guide
Overriding Properties Via The Command Line
I am running using jmeter 2.13
created test plan with thread group and backend listner.backend listner jmeter
up docker image for influxdb ( tutum/influxdb). I am able to access influxdb dashboard.
I made changes in /config/config.toml.
added following in config.toml
[[graphite]]
enabled = true
bind-address = ":8086"
protocol = "tcp"
consistency-level = "one"
separator = "."
database = "jmeter"
I am not able to get data within jmeter database in influxdb after I run jmeter test cases.
Jmeter generates report with 200 code.
Please help to resolve this issue.
I used windows solution but I think it Should be similar.
Install InfluxDB with a new conf file. I did a copy of the default and overwrite the below properties algon with [data] path.In my case was as below
[data]
enabled = true
dir = "C:\\software\\influxdb-1.0.2-1\\data"
wal-dir = "C:\\software\\influxdb-1.0.2-1\\data\\wa
And run inflix with this configuration.
$influxd -config <path to file.conf>.
This file has the graphite listener opened and linkened to DB
[[graphite]]
enabled = true
database = "jmeter"
bind-address = ":2003"
#protocol = "tcp"
# consistency-level = "one"
Later activate the security because Grafana needs it. I suposse you want to see graphs.
[http]
enabled = true
bind-address = ":8086"
auth-enabled = true
Run Influx and using the browser add databases jmeter,grafana. Do not forget to add one administrative user. You can use QueryTemplate for these tasks. So 3 steps
create two databases and at least one user with password.
Ensure Jmeter have Assertions to distinguish retult of the test and backednListender
You are able to access the InfluxDB - admin interface. But do you get the list of tables/measurements when you Show Measurements for your DB?
If it shows the measurement, only the data is not shown, there is a chance that Jmeter's machine time is ahead of InfluxDB time.
If it does not show the measurements, How do you run the docker image? Do you expose all the ports?
My config file is as shown below. Update the config and restart InfluxDB and try again.
[[graphite]]
enabled = true
bind-address = ":2003"
database = "jmeter"
#protocol = "tcp"
#consistency-level = "one"
#separator = "."