Sunday, July 14, 2013

JMeter -- Process Setup 07 -- Explaining Build File 02

This is part seven of our setup.  Part six can be found here:

My apologies for the large time gap between part 6 and part 7.  Let's get to it!

We will be covering what the following targets are doing: transformation, transform, perfStart, perfStop, mailSuccessCompile, mailSend, fullrun, and fullrunOneTransform.

This is exactly the same as transformationOld, except with two transformations: a less detailed one and a more detailed one.  The reason why I did this is simple.  After the test is completed, people get a mail notifying them with links to the report files.  Some people like to check their work mail on the phone.  The detailed report is very large and takes forever and a day to load.  The less detailed report loads very quickly and gives a good summary of what has happened in the test.

Sometimes a test will stop or be stopped prematurely, but you still want to see a report.  What you need to do:
  1. Go to the results folder and see if there is a .JTL file associated with the test -- you can tell by the filename's timestamp.  If the .JTL is not there, you'll have to re-run.
  2. If the .JTL is there the XML will probably be malformed.  Open it up in Notepad++ and check the end of the file.  It should have a closing </httpSample> tag and it should end with </testResults>.  If a tag is missing, add it in the correct spot, save the file, and close it.
  3. Now you can use the transform target to just run the XSL transformation on the .JTL file.  You have three options:
    1. ant -Dfile="[JTLFilename_without.jtl_atTheEnd]" -Dproject="[projectName]" transform
      1. This does absolutely nothing.  You need to add the -Dxsl flag at the end and set it to either "full" or "less".
    2. ant -Dfile="[JTLFilename_without.jtl_atTheEnd]" -Dproject="[projectName]" transform -Dxsl="full"
      1. This runs two transformations on the .JTL file, the Detailed and the Less Detailed ones.  Two reports are generated.
    3. ant -Dfile="[JTLFilename_without.jtl_atTheEnd]" -Dproject="[projectName]" transform -Dxsl="less"
      1. This runs one transformation on the .JTL file - the Less Detailed one.  One report is generated.
This target is called by other targets in order to set a counter name and start Perfmon.  It uses a built in utility in Windows called logman, which I'll get into once we reach Process Setup 10.  To satisfy your curiosity, open a command prompt and enter: "logman query".  You should see something like this:

  • We are using the Ant "exec" command to build up a command which will be executed.  Think about this as if we are telling Ant to open a command prompt and enter a string of commands.
  • After the first echo, we are building up the following command: logman update=[${counterName}] -o "C:\PerfLogs\Admin\${project}\ReportLog_${time}\WebServer.blg -u ${compU} ${compP}
    • counterName is the name of the Data Collection Set that we will be using.  As an overview, we will create a Data Collection Set and choose all of the different performance counters that we are interested in tracking.  This command updates this counter to OUTPUT the data to a folder specific to this Project & this Test, so that it's easy to find later on.  counterName is set in
    • compU and compP are the user name and password that are needed to edit the Data Collection Set.  If I recall correctly, it should be the same as your windows login and password, IF NEEDED.  These are also set in
  • After the second echo, we again use exec to build up the command to start logman, which is simply: logman start ${counterName}.

Similar to the last part of the perfStart target, this utilizes the Ant exec command to stop Perfmon: logman stop ${counterName}.

It's was not easy, at least when I created this, to concatenate and manipulate strings, which is why the var folder was necessary.
  • We start by copying the contents of the ${project} variable into the project.txt file.  We then replace spaces in the file with the HTML encoded value "%20".  We repeat this for ${file} > file.txt and ${folder}> folder.txt.
  • All of the var files are loaded into variables.
  • A lot of the rest of this target is just doing math & string operations in order to output a nicely formatted calculation of the time in the email.
  • The last part of this target puts text into two var files, subject.txt and mailbody.txt.
    • The subject will be, for our example: "BC Rich Load Test <timestamp> - Success"
    • The body will be an HTML document with a funny picture, a table with test time info and links to the reports.
      • The table contains: Test name, Start Time, End Time, and Total time.
      • The reports are the Detailed JMeter Report, the Less Detailed JMeter Report, and the Perfmon .BLG's & HTML report.

This target sends a mail depending on the status.  It checks if the value of the var/failed.txt file is "No" and if so, it gets all the pieces together and sends the Succes mail out, otherwise it sends the Failure mail.  Some properties (enableStartTLS, user, password, and ssl) are required if using a gmail address & can probably be removed if you're using an internal address.

This target pretty much just calls all the other targets in sequential order.  The calls to the other targets are located within a trycatch statement, which checks to see if there are any errors.  If there are any errors, the sequence stops, the var/failed.txt is set to Yes, and a Failure mail is sent.  To use this target, use the command: ant -Dfile="[filename]" -Dfolder="[folderName]" -Dproject="[projectName]" fullrun
  • It starts by resetting the var/failed.txt file to No and then calls:
    • perfStop (to stop the counter if it is running)
    • perfStart (to properly set the counter/log and start the monitoring)
    • jmeterStart (to run the test)
    • transformation (to perform two transformations)
    • perfStop (to stop the counter)
    • mailSuccessCompile (to compile the Success Mail)
  • If any of the previous calls fails, the failMessage is stored and var/failed.txt is set to Yes
  • mailSend (to send the Success Mail)

This is exactly the same as fullrun, except it performs a single transformation (by using transformationOld instead of transformation).  To use this target, use the command: ant -Dfile="[filename]" -Dfolder="[folderName]" -Dproject="[projectName]" fullrunOneTransform

The build file has many targets, some of which are meant to be called from the command line, and others which are meant to be called sequentially.  You are welcome to tweak each one as you see fit.  Pretty much anything you can do manually on the computer can be automated using Ant -- you just need to find the proper command and modify the build file.

Recap & Next Steps:
We have covered how to set up JMeter and Ant and get your tests' reports up and running.  We have tweaked our properties and have modified our build files.  Next we will go over what the XSL files are doing, setup a way to programmatically run our tests (locally or on remote machines) with batch files, and then monitor everything being used with Perfmon.

In Process Setup 08, we will look into the XSL files and how to tweak them.
Part eight has not yet been completed.
Related Posts Plugin for WordPress, Blogger...