Tutorial by Vinod Kumat

Tutorial for jmeter with database testing


Note: Before reading tutorial for jmeter with JDBC *, go to my post jmeter tutorial for understand the basis thing. In this I'll explain more about database connectivity, database connection configuration and JDBC request.

Let's start for JMeter tutorial, how to connect database and all:
Start the jmeter from */*/bin/jmeter.bat. Where * indicate the your dir in windows.
A window will appear with title bar Apache jmeter.










For accessing any database need to configure respective driver (lib ojdbc6.jar).

INFO  - jmeter.engine.StandardJMeterEngine: Running the test!
INFO  - jmeter.samplers.SampleEvent: List of sample_variables: []
WARN  - jmeter.protocol.jdbc.config.DataSourceElement: Could not load driver: oracle.jdbc.OracleDriver java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)


Simple need to place the jdbc jar file in jmeter lib dir. After that need to start again jmeter for further development, once you restart copy jar file will load in jmeter container and available for further use.

Now, create the JDBC Connection Configuration, for this need to Right Click on Test Plan >
Add > Config Element > JDBC Connection Configuration.

Note: This will be there for project or Thread group level.
















Enter the data base details as mention in below image,
Name: JDBCConnectionConfiguration
Variable Name: nameofconnectionordatabase

Connection pool Configuration:

Max Number of Connections: 1 or n as per your db support.

In database connection configuration section:
Database URL: jdbc:oracle:thin:@//IPAddressofdatabase:port/sid
e.g: jdbc:oracle:thin:@//1.1.1.0:1234/nameofsid
JDBC Drive Class: oracle.jdbc.OracleDriver
User name and Password














For more details about driver and connection details you can refer the jmeter help.











Right click on the My Thread Group > Sampler > JDBC Request
Enter the name of connect variable what we have added for JDBC Connection Configuration.
In Variable Name: nameofconnectionordatabase
Select the respective DML for me I selected the select statement.
Whatever query you have in query section.
e.g select * from dual;












Create the summary report > right click on the My Thread Group > Add > Listener > Summary Report.









Save it with your love name.
Click on the Test Plan and run it from tab button or from Run > Start.
You will able to see some result like above screen.

JDBCOracle.jxm file will same, We can use this file for running from Unxi system:
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="My Thread Group" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">1</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1421937486000</longProp>
        <longProp name="ThreadGroup.end_time">1421937486000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <JDBCSampler guiclass="TestBeanGUI" testclass="JDBCSampler" testname="JDBC Request" enabled="true">
          <stringProp name="dataSource">nameofconnectionordatabase</stringProp>
          <stringProp name="query">select * from dual</stringProp>
          <stringProp name="queryArguments"></stringProp>
          <stringProp name="queryArgumentsTypes"></stringProp>
          <stringProp name="queryTimeout"></stringProp>
          <stringProp name="queryType">Select Statement</stringProp>
          <stringProp name="resultVariable"></stringProp>
          <stringProp name="variableNames"></stringProp>
        </JDBCSampler>
        <hashTree/>
        <ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" enabled="true">
          <boolProp name="ResultCollector.error_logging">false</boolProp>
          <objProp>
            <name>saveConfig</name>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>false</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
              <bytes>true</bytes>
            </value>
          </objProp>
          <stringProp name="filename"></stringProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
      <JDBCDataSource guiclass="TestBeanGUI" testclass="JDBCDataSource" testname="JDBCConnectionConfiguration" enabled="true">
        <boolProp name="autocommit">true</boolProp>
        <stringProp name="checkQuery">Select 1</stringProp>
        <stringProp name="connectionAge">5000</stringProp>
        <stringProp name="dataSource">nameofconnectionordatabase</stringProp>
        <stringProp name="dbUrl">jdbc:oracle:thin:@//IPAddress:Port/SID</stringProp>
        <stringProp name="driver">oracle.jdbc.OracleDriver</stringProp>
        <boolProp name="keepAlive">true</boolProp>
        <stringProp name="password">Password_schema</stringProp>
        <stringProp name="poolMax">1</stringProp>
        <stringProp name="timeout">10000</stringProp>
        <stringProp name="transactionIsolation">DEFAULT</stringProp>
        <stringProp name="trimInterval">60000</stringProp>
        <stringProp name="username">User_Schema</stringProp>
      </JDBCDataSource>
      <hashTree/>
    </hashTree>
  </hashTree>
</jmeterTestPlan>


Last Word!

Thanks! Have good day ahead! Like or share it if looks good.
Happy learning and implementation.

No comments:

Post a Comment