Thursday, July 9, 2015

How to loop through multiple CSV files in JMeter


Here is a simple way to play with multiple CSV files in JMeter! Just copy and save the given code as a JMX file and load it into JMeter, you would probable be having a view something like shown here! And Enjoy!

<?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="APICloudBenchMarking-PreRequisites" 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 name="requestUrlForAccountProvisionAPI" elementType="Argument">
            <stringProp name="Argument.name">requestUrlForAccountProvisionAPI</stringProp>
            <stringProp name="Argument.value">api-dev1.trimble.com/t/trimble.com/testaccountIdentityService/1.0/account</stringProp>
            <stringProp name="Argument.metadata">=</stringProp>
          </elementProp>
          <elementProp name="requestUrlForUserProvisionAPI" elementType="Argument">
            <stringProp name="Argument.name">requestUrlForUserProvisionAPI</stringProp>
            <stringProp name="Argument.value">api-dev1.trimble.com/t/trimble.com/testuserIdentityService/1.0/user</stringProp>
            <stringProp name="Argument.metadata">=</stringProp>
          </elementProp>
          <elementProp name="Testdata_LoopCount" elementType="Argument">
            <stringProp name="Argument.name">Testdata_LoopCount</stringProp>
            <stringProp name="Argument.value">2</stringProp>
            <stringProp name="Argument.metadata">=</stringProp>
          </elementProp>
          <elementProp name="AddAccount_Datasource" elementType="Argument">
            <stringProp name="Argument.name">AddAccount_Datasource</stringProp>
            <stringProp name="Argument.value">Account_Test_Data.csv</stringProp>
            <stringProp name="Argument.metadata">=</stringProp>
          </elementProp>
          <elementProp name="AddUser_Datasource" elementType="Argument">
            <stringProp name="Argument.name">AddUser_Datasource</stringProp>
            <stringProp name="Argument.value">User_Test_Data.csv</stringProp>
            <stringProp name="Argument.metadata">=</stringProp>
          </elementProp>
        </collectionProp>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="LoadApis" enabled="false">
        <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>
          <intProp name="LoopController.loops">-1</intProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1414742816000</longProp>
        <longProp name="ThreadGroup.end_time">1414742816000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration">900</stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <BeanShellPreProcessor guiclass="TestBeanGUI" testclass="BeanShellPreProcessor" testname="UserCountProcessor" enabled="true">
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <boolProp name="resetInterpreter">false</boolProp>
          <stringProp name="script">import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
 
FileReader fileReader = new FileReader(new File(&quot;C:\\Users\\rareddy\\Desktop\\shared-services\\jmx-test\\TID Perf Test\\krishna\\APICloud\\UserDetails.csv&quot;));
LineNumberReader lineReader = new LineNumberReader(fileReader);
int linenumber = 0;
while (lineReader.readLine() != null){
   linenumber++;
}
//linenumber--; // do not include header row
props.put(&quot;LineCount&quot;, Integer.toString(linenumber));
lineReader.close();</stringProp>
        </BeanShellPreProcessor>
        <hashTree/>
        <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="Api Data Config" enabled="true">
          <stringProp name="delimiter">,</stringProp>
          <stringProp name="fileEncoding"></stringProp>
          <stringProp name="filename">ApiDetails.csv</stringProp>
          <boolProp name="quotedData">false</boolProp>
          <boolProp name="recycle">false</boolProp>
          <stringProp name="shareMode">shareMode.all</stringProp>
          <boolProp name="stopThread">true</boolProp>
          <stringProp name="variableNames">ApiName</stringProp>
        </CSVDataSet>
        <hashTree/>
        <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="User Count Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">true</boolProp>
          <stringProp name="LoopController.loops">${__P(LineCount)}</stringProp>
        </LoopController>
        <hashTree>
          <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="User Data Config" enabled="true">
            <stringProp name="delimiter">,</stringProp>
            <stringProp name="fileEncoding"></stringProp>
            <stringProp name="filename">UserDetails.csv</stringProp>
            <boolProp name="quotedData">false</boolProp>
            <boolProp name="recycle">true</boolProp>
            <stringProp name="shareMode">shareMode.all</stringProp>
            <boolProp name="stopThread">false</boolProp>
            <stringProp name="variableNames">userName</stringProp>
          </CSVDataSet>
          <hashTree/>
          <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="AddApi" enabled="true">
            <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
              <collectionProp name="Arguments.arguments">
                <elementProp name="" elementType="HTTPArgument">
                  <boolProp name="HTTPArgument.always_encode">false</boolProp>
                  <stringProp name="Argument.value">{&quot;userName&quot;:&quot;${ApiName}&quot;,&quot;firstName&quot;:&quot;${userName}&quot;,&quot;userCount&quot;:&quot;${__P(LineCount)}&quot;}</stringProp>
                  <stringProp name="Argument.metadata">=</stringProp>
                </elementProp>
              </collectionProp>
            </elementProp>
            <stringProp name="HTTPSampler.domain">api-pp.trimblepaas.com</stringProp>
            <stringProp name="HTTPSampler.port"></stringProp>
            <stringProp name="HTTPSampler.connect_timeout"></stringProp>
            <stringProp name="HTTPSampler.response_timeout"></stringProp>
            <stringProp name="HTTPSampler.protocol">https</stringProp>
            <stringProp name="HTTPSampler.contentEncoding"></stringProp>
            <stringProp name="HTTPSampler.path">publisher</stringProp>
            <stringProp name="HTTPSampler.method">POST</stringProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
            <stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
            <boolProp name="HTTPSampler.monitor">false</boolProp>
            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
          </HTTPSamplerProxy>
          <hashTree>
            <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
              <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>
        </hashTree>
      </hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="LoadAppplications" enabled="false">
        <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>
          <intProp name="LoopController.loops">-1</intProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1414742816000</longProp>
        <longProp name="ThreadGroup.end_time">1414742816000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration">900</stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <BeanShellPreProcessor guiclass="TestBeanGUI" testclass="BeanShellPreProcessor" testname="UserCountProcessor" enabled="true">
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <boolProp name="resetInterpreter">false</boolProp>
          <stringProp name="script">import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
 
FileReader fileReader = new FileReader(new File(&quot;C:\\Users\\rareddy\\Desktop\\shared-services\\jmx-test\\TID Perf Test\\krishna\\APICloud\\UserDetails.csv&quot;));
LineNumberReader lineReader = new LineNumberReader(fileReader);
int linenumber = 0;
while (lineReader.readLine() != null){
   linenumber++;
}
//linenumber--; // do not include header row
props.put(&quot;LineCount&quot;, Integer.toString(linenumber));
lineReader.close();</stringProp>
        </BeanShellPreProcessor>
        <hashTree/>
        <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="Appplication Data Config" enabled="true">
          <stringProp name="delimiter">,</stringProp>
          <stringProp name="fileEncoding"></stringProp>
          <stringProp name="filename">ApplicationDetails.csv</stringProp>
          <boolProp name="quotedData">false</boolProp>
          <boolProp name="recycle">false</boolProp>
          <stringProp name="shareMode">shareMode.all</stringProp>
          <boolProp name="stopThread">true</boolProp>
          <stringProp name="variableNames">ApiName</stringProp>
        </CSVDataSet>
        <hashTree/>
        <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="User Count Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">true</boolProp>
          <stringProp name="LoopController.loops">${__P(LineCount)}</stringProp>
        </LoopController>
        <hashTree>
          <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="User Data Config" enabled="true">
            <stringProp name="delimiter">,</stringProp>
            <stringProp name="fileEncoding"></stringProp>
            <stringProp name="filename">UserDetails.csv</stringProp>
            <boolProp name="quotedData">false</boolProp>
            <boolProp name="recycle">true</boolProp>
            <stringProp name="shareMode">shareMode.all</stringProp>
            <boolProp name="stopThread">false</boolProp>
            <stringProp name="variableNames">userName</stringProp>
          </CSVDataSet>
          <hashTree/>
          <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="AddApplication" enabled="true">
            <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
              <collectionProp name="Arguments.arguments">
                <elementProp name="" elementType="HTTPArgument">
                  <boolProp name="HTTPArgument.always_encode">false</boolProp>
                  <stringProp name="Argument.value">{&quot;userName&quot;:&quot;${ApiName}&quot;,&quot;firstName&quot;:&quot;${userName}&quot;,&quot;userCount&quot;:&quot;${__P(LineCount)}&quot;}</stringProp>
                  <stringProp name="Argument.metadata">=</stringProp>
                </elementProp>
              </collectionProp>
            </elementProp>
            <stringProp name="HTTPSampler.domain">api-pp.trimblepaas.com</stringProp>
            <stringProp name="HTTPSampler.port"></stringProp>
            <stringProp name="HTTPSampler.connect_timeout"></stringProp>
            <stringProp name="HTTPSampler.response_timeout"></stringProp>
            <stringProp name="HTTPSampler.protocol">https</stringProp>
            <stringProp name="HTTPSampler.contentEncoding"></stringProp>
            <stringProp name="HTTPSampler.path">publisher</stringProp>
            <stringProp name="HTTPSampler.method">POST</stringProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
            <stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
            <boolProp name="HTTPSampler.monitor">false</boolProp>
            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
          </HTTPSamplerProxy>
          <hashTree>
            <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
              <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>
        </hashTree>
      </hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Subscription" 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>
          <intProp name="LoopController.loops">-1</intProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1414742816000</longProp>
        <longProp name="ThreadGroup.end_time">1414742816000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration">900</stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <BeanShellPreProcessor guiclass="TestBeanGUI" testclass="BeanShellPreProcessor" testname="UserCountProcessor" enabled="true">
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <boolProp name="resetInterpreter">false</boolProp>
          <stringProp name="script">import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
 
FileReader fileReader = new FileReader(new File(&quot;C:\\Users\\rareddy\\Desktop\\shared-services\\jmx-test\\TID Perf Test\\krishna\\APICloud\\UserDetails.csv&quot;));
LineNumberReader lineReader = new LineNumberReader(fileReader);
int linenumber = 0;
while (lineReader.readLine() != null){
   linenumber++;
}
//linenumber--; // do not include header row
props.put(&quot;UserCount&quot;, Integer.toString(linenumber));
lineReader.close();</stringProp>
        </BeanShellPreProcessor>
        <hashTree/>
        <BeanShellPreProcessor guiclass="TestBeanGUI" testclass="BeanShellPreProcessor" testname="ApiCountProcessor" enabled="true">
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <boolProp name="resetInterpreter">false</boolProp>
          <stringProp name="script">import java.io.File;
import java.io.FileReader;
import java.io.LineNumberReader;
 
FileReader fileReader = new FileReader(new File(&quot;C:\\Users\\rareddy\\Desktop\\shared-services\\jmx-test\\TID Perf Test\\krishna\\APICloud\\ApiDetails.csv&quot;));
LineNumberReader lineReader = new LineNumberReader(fileReader);
int linenumber = 0;
while (lineReader.readLine() != null){
   linenumber++;
}
//linenumber--; // do not include header row
props.put(&quot;ApiCount&quot;, Integer.toString(linenumber));
lineReader.close();</stringProp>
        </BeanShellPreProcessor>
        <hashTree/>
        <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="Appplication Data Config" enabled="true">
          <stringProp name="delimiter">,</stringProp>
          <stringProp name="fileEncoding"></stringProp>
          <stringProp name="filename">ApplicationDetails.csv</stringProp>
          <boolProp name="quotedData">false</boolProp>
          <boolProp name="recycle">false</boolProp>
          <stringProp name="shareMode">shareMode.all</stringProp>
          <boolProp name="stopThread">true</boolProp>
          <stringProp name="variableNames">ApiName</stringProp>
        </CSVDataSet>
        <hashTree/>
        <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="Api Count Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">true</boolProp>
          <stringProp name="LoopController.loops">${__P(ApiCount)}</stringProp>
        </LoopController>
        <hashTree>
          <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="Api Data Config" enabled="true">
            <stringProp name="delimiter">,</stringProp>
            <stringProp name="fileEncoding"></stringProp>
            <stringProp name="filename">ApiDetails.csv</stringProp>
            <boolProp name="quotedData">false</boolProp>
            <boolProp name="recycle">true</boolProp>
            <stringProp name="shareMode">shareMode.all</stringProp>
            <boolProp name="stopThread">false</boolProp>
            <stringProp name="variableNames">ApiName</stringProp>
          </CSVDataSet>
          <hashTree/>
          <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="User Count Controller" enabled="true">
            <boolProp name="LoopController.continue_forever">true</boolProp>
            <stringProp name="LoopController.loops">${__P(UserCount)}</stringProp>
          </LoopController>
          <hashTree>
            <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="User Data Config" enabled="true">
              <stringProp name="delimiter">,</stringProp>
              <stringProp name="fileEncoding"></stringProp>
              <stringProp name="filename">UserDetails.csv</stringProp>
              <boolProp name="quotedData">false</boolProp>
              <boolProp name="recycle">true</boolProp>
              <stringProp name="shareMode">shareMode.all</stringProp>
              <boolProp name="stopThread">false</boolProp>
              <stringProp name="variableNames">userName</stringProp>
            </CSVDataSet>
            <hashTree/>
            <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="AddApplication" enabled="true">
              <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
              <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
                <collectionProp name="Arguments.arguments">
                  <elementProp name="" elementType="HTTPArgument">
                    <boolProp name="HTTPArgument.always_encode">false</boolProp>
                    <stringProp name="Argument.value">{&quot;userName&quot;:&quot;${ApiName}&quot;,&quot;firstName&quot;:&quot;${userName}&quot;,&quot;userCount&quot;:&quot;${__P(LineCount)}&quot;}</stringProp>
                    <stringProp name="Argument.metadata">=</stringProp>
                  </elementProp>
                </collectionProp>
              </elementProp>
              <stringProp name="HTTPSampler.domain">api-pp.trimblepaas.com</stringProp>
              <stringProp name="HTTPSampler.port"></stringProp>
              <stringProp name="HTTPSampler.connect_timeout"></stringProp>
              <stringProp name="HTTPSampler.response_timeout"></stringProp>
              <stringProp name="HTTPSampler.protocol">https</stringProp>
              <stringProp name="HTTPSampler.contentEncoding"></stringProp>
              <stringProp name="HTTPSampler.path">publisher</stringProp>
              <stringProp name="HTTPSampler.method">POST</stringProp>
              <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
              <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
              <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
              <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
              <stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
              <boolProp name="HTTPSampler.monitor">false</boolProp>
              <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
            </HTTPSamplerProxy>
            <hashTree>
              <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
                <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>
          </hashTree>
          <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="User Data Config" enabled="true">
            <stringProp name="delimiter">,</stringProp>
            <stringProp name="fileEncoding"></stringProp>
            <stringProp name="filename">UserDetails.csv</stringProp>
            <boolProp name="quotedData">false</boolProp>
            <boolProp name="recycle">true</boolProp>
            <stringProp name="shareMode">shareMode.all</stringProp>
            <boolProp name="stopThread">false</boolProp>
            <stringProp name="variableNames">userName</stringProp>
          </CSVDataSet>
          <hashTree/>
        </hashTree>
      </hashTree>
      <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" 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">1436438845555</stringProp>
      </ResultCollector>
      <hashTree/>
      <ResultCollector guiclass="TableVisualizer" testclass="ResultCollector" testname="View Results in Table" 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>
  </hashTree>
</jmeterTestPlan>





Have a nice time!

Thursday, June 18, 2015

How to push build artifacts to remote repository using Maven

Hello! After a bit long time, I am writing a post in this "Gyan of Java" blog. Today, we will look into few concepts of Apache Maven building tool. Have you ever come across a situation where you need to push build artifacts to a remote repository? Have you ever come across a situation where you need to push third party artifacts to a remote repository? Let's look into these now.


To answer first query, need to add a <distributionManagement> tag entries in the pom.xml of the application.

Step: 1
 
<!-- remote repository server info where artifacts would be pushed -->
 <distributionManagement>
  <repository>
   <id>remoteRepo</id>
   <name>Internal Nexus Repository</name>
   <url>http://<remote host name>:<port name>/<remote repository path>/</url>
  </repository>
</distributionManagement>


Also, need to below add entries in the settings.xml file located in M2_HOME directory.

Step: 2
   <servers>
<server>
<id>remoteRepo</id>
<username><username></username>
<password><password></password>
</server>

  </servers>

 

 

After doing these changes, build your app with following command:

mvn clean deploy

 

Regarding the later question, pushing third party artifacts whose pom.xml is not available, below is the code snippet.

 

Step: 3

mvn deploy:deploy-file -DgroupId=com.company.app -DartifactId=appName -Dversion=1.0 -Dfile=<path-to-file>/appName.jar -Dpackaging=jar -DrepositoryId=remoteRepo -Durl=http://<remote host>:<port no>/<remote repository path> -DgeneratePom=true

 

but before executing Step :3 command, please make sure to add entries in settings.xml file as mentioned in Step: 2

 

 

Wednesday, June 10, 2015

How to pass environment variables to tomact

Just change the below file in order to pass environment variables to tomcat.

TOMCAT_HOME/bin/catalina.sh  

 

And keep the below line:

JAVA_OPTS="$JAVA_OPTS -Dkey=$value"

Monday, April 13, 2015

How to append url parameters in Wso2 API Manager

Appending url parameters in Wso2 API Manager using custom sequences:

 

<sequence xmlns="http://ws.apache.org/ns/synapse" name="eCommerce--Aria-add-params--In">

    <property name="REST_URL_POSTFIX" expression="fn:concat(get-property('axis2','REST_URL_POSTFIX'), '&amp;auth_key=mps8qpVB6NwjPgPGMJCNnAGKvHxNDbaX')" scope="axis2" type="STRING"/>

    <property name="REST_URL_POSTFIX" expression="fn:concat(get-property('axis2','REST_URL_POSTFIX'), '&amp;client_no=4974461')" scope="axis2" type="STRING"/>

    <log level="full">

        <property name="TRACE" value="Adding url params by Rajakrishna Reddy"/>

    </log>

</sequence>

 

 

 

 

Sunday, March 8, 2015

my new tab opens with chrome://quick_start/content/index.html on the address bar. How to fix it!!

1.    Open Firefox

2.    Type about:config in URL tab and Enter

  1. Filter with browser.newtab.url and change the value as "about:newtab"

 

Thursday, March 5, 2015

Enabling Basic Authentication for a web application in Tomcat

There are 3 steps to perform as follows:

1.      Create a role in tomcat-users.xml file under tomcat/conf directory as given below:

 

<role rolename="monitor"/>

<user username="krishna" password="1234" roles="monitor"/>

 

2.      Use the role created above in your web application’s web.xml and enable Basic Authentication as given below:

 

<security-constraint>

            <web-resource-collection>

                        <web-resource-name>Wildcard means whole application requires authentication</web-resource-name>

                        <url-pattern>/*</url-pattern>

                        <http-method>GET</http-method>

                        <http-method>POST</http-method>

            </web-resource-collection>

            <auth-constraint>

                        <role-name>monitor</role-name>

            </auth-constraint>

           

            <user-data-constraint>

                        <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->

                        <transport-guarantee>NONE</transport-guarantee>

            </user-data-constraint>

</security-constraint>

 

<login-config>

            <auth-method>BASIC</auth-method>

</login-config>

 

3.      Restart the tomcat.

 

 



Thanks & Regards,

Rajakrishna Reddy

Thursday, February 19, 2015

Taking thread dump on CPU High usage in WSO2 products

Please follow the commands provided here to take the thread dump.

 

First you need to create test.sh script using following command.
     vi test.sh

Then paste following script content.

    #!/bin/bash
    # 1: ['command\ name' or PID number(,s)] 2: MAX_CPU_PERCENT
    [[ $# -ne 2 ]] && exit 1
    PID_NAMES=$1
    # get all PIDS as nn,nn,nn
    if [[ ! "$PID_NAMES" =~ ^[0-9,]+$ ]] ; then
        PIDS=$(pgrep -d ',' -x $PID_NAMES)
    else
        PIDS=$PID_NAMES
    fi
    # echo "$PIDS $MAX_CPU"
    MAX_CPU="$2"
    MAX_CPU="$(echo "($MAX_CPU+0.5)/1" | bc)"
    LOOP=1
    while [[ $LOOP -eq 1 ]] ; do
        sleep 0.3s
        # Depending on your 'top' version and OS you might have
        # to change head and tail line-numbers
        LINE="$(top -b -d 0 -n 1 -p $PIDS | head -n 8 \
            | tail -n 1 | sed -r 's/[ ]+/,/g' | \
            sed -r 's/^\,|\,$//')"
        # If multiple processes in $PIDS, $LINE will only match\
        # the most active process
        CURR_PID=$(echo "$LINE" | cut -d ',' -f 1)
        # calculate cpu limits
        CURR_CPU_FLOAT=$(echo "$LINE"| cut -d ',' -f 9)
        CURR_CPU=$(echo "($CURR_CPU_FLOAT+0.5)/1" | bc)
        echo "PID $CURR_PID: $CURR_CPU""%"
        if [[ $CURR_CPU -ge $MAX_CPU ]] ; then
            now="$(date)"
            echo "PID $CURR_PID ($PID_NAMES) went over $MAX_CPU""%" on $now
            jstack $CURR_PID > ./$now+jlog.txt
            echo "[[ $CURR_CPU""% -ge $MAX_CPU""% ]]"
            LOOP=0
            break
        fi
    done
    echo "Stopped"



Then we need to get process id of running WSO2 server by running following command.
    sanjeewa@sanjeewa-ThinkPad-T530:~/work$ jps
    30755 Bootstrap
    8543 Jps
    4892 Main


Now we know carbon server running with process ID 30755. Then we can start our script by providing init parameters(process ID and CPU limit). So it will keep printing CPU usage in terminal and once it reached limit it will take thread dump using jstack command. It will create new file with with embedding current date time and push Jstack output to it.

We can start scritp like this.
    sanjeewa@sanjeewa-ThinkPad-T530:~/work$ sh test.sh 30755 99

As you can see when CPU goes above 99% it will create log file and append thread dump.

 

Public sample wadl urls for testing

Public sample wadl urls for testing: https://developer.dnb.com/docs/v1/1.0/rest

 

Tuesday, February 17, 2015

Installing certificates into trust store

openssl s_client -showcerts -connect www.trimblemaps.com:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > /tmp/trimblemaps.pem

 

keytool -importcert -alias trimblemaps -keystore client-truststore.jks --file /tmp/trimblemaps.pem

Installing Mongo in Linux using yum

Installing Mongo in linux using yum.

The Mongo DB downloads repository contains two packages:

  • mongo-10gen-server

This package contains the mongod and mongos daemons from the latest stable release and associated configuration and init scripts. Additionally, you can use this package to install daemons from a previous release of MongoDB.

  • mongo-10gen

This package contains all MongoDB tools from the latest stable release. Additionally, you can use this package to install tools from a previous release of MongoDB. Install this package on all production MongoDB hosts and optionally on other systems from which you may need to administer MongoDB systems.

Install MongoDB

Configure Package Management System (YUM)

Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:

TIP

For production deployments, always run MongoDB on 64-bit systems.

If you are running a 64-bit system, use the following configuration:

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

gpgcheck=0

enabled=1

If you are running a 32-bit system, which is not recommended for production deployments, use the following configuration:

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/

gpgcheck=0

enabled=1

Install Packages

Issue the following command (as root or with sudo) to install the latest stable version of MongoDB and the associated tools:

yum install mongo-10gen mongo-10gen-server

When this command completes, you have successfully installed MongoDB!

Manage Installed Versions

You can use the mongo-10gen and mongo-10gen-server packages to install previous releases of MongoDB. To install a specific release, append the version number, as in the following example:

yum install mongo-10gen-2.2.3 mongo-10gen-server-2.2.3

This installs the mongo-10gen and mongo-10gen-server packages with the 2.2.3 release. You can specify any available version of MongoDB; however yum will upgrade the mongo-10gen and mongo-10gen-server packages when a newer version becomes available. Use the following pinningprocedure to prevent unintended upgrades.

To pin a package, add the following line to your /etc/yum.conf file:

exclude=mongo-10gen,mongo-10gen-server