Skip to content

Instantly share code, notes, and snippets.

@kvalle
Created January 16, 2012 19:09
Show Gist options
  • Save kvalle/1622421 to your computer and use it in GitHub Desktop.
Save kvalle/1622421 to your computer and use it in GitHub Desktop.
Mininimal example of setup for writing Grinder test scripts in Java
java_test_runner = my.java.package.MyTestRunner
grinder.script = grinder.py
grinder.runs = 10
grinder.threads = 2
# etc
from net.grinder.plugin.http import HTTPRequest
from net.grinder.script.Grinder import grinder
def load_class(class_name):
m = __import__(class_name)
for comp in class_name.split('.')[1:]:
m = getattr(m, comp)
return m
test_runner = load_class(grinder.getProperties().getProperty('java_test_runner'))
class TestRunner:
def __init__(self):
self.runner = test_runner(HTTPRequest())
def __call__(self):
self.runner.call()
package my.java.package;
import net.grinder.plugin.http.HTTPRequest;
import net.grinder.script.NotWrappableTypeException;
import net.grinder.script.Test;
public class MyTestRunner {
private HTTPRequest test;
public JavaTestRunner(HTTPRequest req) throws NotWrappableTypeException {
this.test = (HTTPRequest) new Test(100, "http test").wrap(req);
}
public void call() throws Exception {
this.test.GET("http://google.com");
this.test.GET("http://nytimes.com");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment