This document describes how to setup Grinder for running system and performance testing against our web application.
Grinder Introduction
There are three main processes to are used to run tests across machine:
- Worker process: interpret Jython test scripts and performs tests using a number of work threads
- Agent process: Manages worker process
- Console: coordinate the other processes; collates and displays statistics
Grinder Project Setup
- You need to download the latest version of Grinder 3.1 from the following link:-
http://grinder.sourceforge.net/
- Set an environment variable called GRINDER_HOME.
Test if Grinder is configured correctly.
- Start ofbiz
- Start grinder by running the startAgent.bat file. This will use the etc/grinder.properties file to determine what scripts should run. The grinder.properties file is current set to run a script in the testdef/grinder/orders directory. This is the helloworld.py”.
You can execute an ofbiz service through grinder by using the following URI defined in the controller.xml file.
http://localhost:8080/<component-name>/control/runServiceTest?serviceName=<name_of_service>&userLogin=<admin>.. any other parameters needed for the service.
The results from the service are returned as a json data object. We will be creating a JSON object on the client side to process server requests.
Running Test From Console
The grinder console is a good way to run specific grinder tests because it allows you to pick different grinder.properties file and execute those tests. It also will transfer all the grinder scripts from the console workstation to the grinder agent workstation.
Here are the steps to set it up:
- From the Distribute menu select “set directory”
- Pick a directory that has a custom grinder.properties file (e.g. testdef/grinder/orders)
- Select the “Script” tab (4th one on the right)
- Expand the folder for the selected directory (e.g. testdef/grinder/orders) and the grinder.properties file in that directory should have a star by it.
- You can edit the grinder.properties file by double clicking it and bringing it in the edit window.
- Uncomment the scripts in that file that you want to run.
- Now start up a grinder agent. If the console is running the agent should have a message like “waiting for console signal”
- You can now run the test by pressing the run button on the far left “>”. If you modify the grinder.properties file you may have to press the “send the modified files to their agents” to make the change work.
Failing a Test
Grinder normal reports the success of a test immediately after running it. This means if you are doing a GET request you will only fail if the server gives you an HTTP error. If you want to verify the data that is returned from the service than you need to delay the reporting of the statistics before you execute the test. Then you can set the success or failure of the test.
Here is an example of how that is done:
Note: you have to set this before you run the tests
print "Setting grinder.statistics.delayReports to 1" grinder.statistics.delayReports = 1
Then run the test
orderId = reader.getFieldValue("orderId")
print "Getting order items for orderId: %s" % orderId
request = "http://localhost:8080/<component-name>/control/runServiceTest?serviceName=%s&orderId=%s&userLogin=admin" % (serviceName, orderId)
Then test something like the following:
if string.find(response.get("responseMessage"), "successXXX") == 0:
print "Successful test against %s" % (serviceName)
#writeToFile(result.getText())
else:
print serviceName + " failed to return success"
grinder.statistics.forLastTest.success = 0 ---> This is where we tell the server the test failed.
writeToFile(serviceName + " failed to return success")
Note:
- you can pick the grinder.properties file to run from the console
- you can also pick the directory to run
TODO: how to set the python directory for other libraries. For example, the string module isn’t there by default.
Adding Python Modules
- Jython includes a “registry” with a property called python.path. You can add paths to this directory and those libraries should be added to your environment.
- E.G. python.path=.;c:\\devtools\\jython2.2.1\\lib;c:\\devtools\\Python25\\Lib;c:\\devtools\\Python25\\Lib\\site-packages\\statlib
- You can test the path by running jython.bat
- import sys
- print sys.registry – should show what directories are loaded.
Bug: I can’t get the registry to work with grinder. It can find the python file if is it in the sample directory. I saw a post where they recommended the following work around to create your own path.
-import sys
-sys.path.insert(0, “D:\code\Grinder\client\SW2-file-store\incoming”)
Other Grinder Related Projects
Ground Report – Graphical reports for Grinder
http://sourceforge.net/projects/ground/
Grinder Analyzer – tool that parses log files and generates client-side performance graphs
http://sourceforge.net/project/showfiles.php?group_id=160220
webFlange – continuous test tool
GrinderStrone – Eclipse plugin for grinder

That’s way more clever than I was expecting. Thnaks!
Kudos! What a neat way of tihkning about it.