Browse files

added better java test, integrated test and sample result

  • Loading branch information...
1 parent 25d1d73 commit 6218fb26726a25bc7b40f889ff38eb247a229716 Vincent Landgraf committed Apr 2, 2011
View
BIN Graphs.numbers
Binary file not shown.
View
43 Makefile
@@ -1,19 +1,46 @@
-COUNT = 10000
-URL = "http://localhost/~vincentlandgraf/test.json"
+COUNT = 10
+URL = "http://localhost/~vincentlandgraf/test.json"
+DATE = `date +%Y-%m-%d.%H-%M`
+RESULT = "result-$(DATE).txt"
-all: install test-ruby test-java test-apache
+all: clean install test csv
-install:
+clean:
+ rm -f $(RESULT)
+
+#
+# Install the environment
+#
+
+install: install-ruby install-java
+
+install-ruby:
rvm 1.9.2,1.8.7 exec bundle install
+
+install-java:
cd java && mvn clean && mvn package
+#
+# Do the test
+#
+
+test: test-ruby test-java test-apache
+
test-ruby:
- rvm 1.9.2,1.8.7 exec ruby test.rb $(COUNT) $(URL)
+ rvm 1.9.2,1.8.7 exec ruby test.rb $(COUNT) $(URL) >> $(RESULT)
test-java:
java -version
- java -server -jar java/target/http-test-0.0.1-SNAPSHOT.jar $(COUNT) $(URL)
- java -jar java/target/http-test-0.0.1-SNAPSHOT.jar $(COUNT) $(URL)
+ java -server -jar java/target/http-test-0.0.1-SNAPSHOT.jar $(COUNT) $(URL) >> $(RESULT)
+ java -jar java/target/http-test-0.0.1-SNAPSHOT.jar $(COUNT) $(URL) >> $(RESULT)
test-apache:
- ab -n $(COUNT) $(URL)
+ ab -n $(COUNT) $(URL) >> $(RESULT)
+
+#
+# Extract the results
+#
+
+csv:
+ awk -F" " -f extract.awk $(RESULT) > $(RESULT).csv
+ open $(RESULT).csv -a numbers
View
1 create_test_data.rb
@@ -1,3 +1,4 @@
+require "rubygems"
require 'bundler'
Bundler.require :default
require 'yajl/json_gem'
View
23 extract.awk
@@ -0,0 +1,23 @@
+#!/usr/bin/awk
+
+# headlines
+/Java|ruby 1|ApacheBench/ {
+ print
+}
+
+# results
+/^testing/ {
+ # use same decimal delimiters everywhere
+ gsub(/\./, ",", $0);
+
+ # remove unnecessary chars
+ gsub(/^testing[ ]*/, "", $0)
+ gsub(/[()]/, "", $0);
+ gsub(/[ ]+/, ";", $0);
+
+ print
+}
+
+/Time taken for tests:/ {
+ print "ab;;;;" $5
+}
View
20 java/src/main/java/org/toevolve/httptest/ApacheHttpClient.java
@@ -12,24 +12,26 @@
private HttpClient client;
- public ApacheHttpClient() {
- client = new HttpClient();
- }
-
public static void main(String[] args) throws Exception {
- ApacheHttpClient app = new ApacheHttpClient();
+ ApacheHttpClient app = new ApacheHttpClient();
doTest("testing httpclient", args, app);
}
+
+ void prepare(URL url) throws Exception {
+ client = new HttpClient();
+ int port = url.getPort() == -1 ? url.getDefaultPort() : url.getPort();
+ client.startSession(url.getHost(), port);
+ }
void testRequest(URL url) throws Exception {
- client.startSession(url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort());
HttpMethod doGet = new GetMethod(url.getPath());
client.executeMethod(doGet);
- verifyResult((JSONArray)JSONValue.parse(doGet.getResponseBodyAsString()));
-
- client.endSession();
+ verifyResult((JSONArray)JSONValue.parse(doGet.getResponseBodyAsString()));
}
+ void tearDown() throws Exception {
+ client.endSession();
+ }
}
View
7 java/src/main/java/org/toevolve/httptest/TestApplication.java
@@ -6,7 +6,6 @@
import org.json.simple.JSONObject;
import java.lang.management.*;
-
public abstract class TestApplication {
/** code from http://nadeausoftware.com/articles/2008/03/java_tip_how_get_cpu_and_user_time_benchmarking **/
@@ -41,10 +40,12 @@ static void doTest(String name, String[] args, TestApplication app)
long startSystemTimeNano = getSystemTime();
long startUserTimeNano = getUserTime();
+ app.prepare(url);
// do the test
for (int i = 0; i < iterations; ++i) {
app.testRequest(url);
}
+ app.tearDown();
// end time
long taskUserTimeNano = getUserTime() - startUserTimeNano;
@@ -75,5 +76,9 @@ void verifyResult(JSONArray array) {
}
}
+ abstract void prepare(URL url) throws Exception;
+
abstract void testRequest(URL url) throws Exception;
+
+ abstract void tearDown() throws Exception;
}
View
3 test.rb
@@ -8,6 +8,7 @@
ITERATIONS = ARGV.shift.to_i
PATH = ARGV.shift
+FILES = ARGV.shift || "test_*.rb"
TESTS = []
def test_http(name, &block)
@@ -18,7 +19,7 @@ def test_http(name, &block)
dir = File.dirname(__FILE__)
-Dir[File.join(dir, "test_*.rb")].each do |file|
+Dir[File.join(dir, FILES)].each do |file|
require file
end

0 comments on commit 6218fb2

Please sign in to comment.