Skip to content

Commit

Permalink
added better java test, integrated test and sample result
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Landgraf committed Apr 2, 2011
1 parent 25d1d73 commit 6218fb2
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 19 deletions.
Binary file added Graphs.numbers
Binary file not shown.
43 changes: 35 additions & 8 deletions Makefile
@@ -1,19 +1,46 @@
COUNT = 10000 COUNT = 10
URL = "http://localhost/~vincentlandgraf/test.json" 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 rvm 1.9.2,1.8.7 exec bundle install

install-java:
cd java && mvn clean && mvn package cd java && mvn clean && mvn package


#
# Do the test
#

test: test-ruby test-java test-apache

test-ruby: 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: test-java:
java -version java -version
java -server -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) java -jar java/target/http-test-0.0.1-SNAPSHOT.jar $(COUNT) $(URL) >> $(RESULT)


test-apache: 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
1 change: 1 addition & 0 deletions create_test_data.rb
@@ -1,3 +1,4 @@
require "rubygems"
require 'bundler' require 'bundler'
Bundler.require :default Bundler.require :default
require 'yajl/json_gem' require 'yajl/json_gem'
Expand Down
23 changes: 23 additions & 0 deletions 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
}
20 changes: 11 additions & 9 deletions java/src/main/java/org/toevolve/httptest/ApacheHttpClient.java
Expand Up @@ -12,24 +12,26 @@ public class ApacheHttpClient extends TestApplication {


private HttpClient client; private HttpClient client;


public ApacheHttpClient() {
client = new HttpClient();
}

public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ApacheHttpClient app = new ApacheHttpClient(); ApacheHttpClient app = new ApacheHttpClient();
doTest("testing httpclient", args, app); 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 { void testRequest(URL url) throws Exception {
client.startSession(url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort());
HttpMethod doGet = new GetMethod(url.getPath()); HttpMethod doGet = new GetMethod(url.getPath());
client.executeMethod(doGet); client.executeMethod(doGet);
verifyResult((JSONArray)JSONValue.parse(doGet.getResponseBodyAsString())); verifyResult((JSONArray)JSONValue.parse(doGet.getResponseBodyAsString()));

client.endSession();
} }


void tearDown() throws Exception {
client.endSession();
}
} }




Expand Up @@ -6,7 +6,6 @@
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.lang.management.*; import java.lang.management.*;



public abstract class TestApplication { public abstract class TestApplication {
/** code from http://nadeausoftware.com/articles/2008/03/java_tip_how_get_cpu_and_user_time_benchmarking **/ /** code from http://nadeausoftware.com/articles/2008/03/java_tip_how_get_cpu_and_user_time_benchmarking **/


Expand Down Expand Up @@ -41,10 +40,12 @@ static void doTest(String name, String[] args, TestApplication app)
long startSystemTimeNano = getSystemTime(); long startSystemTimeNano = getSystemTime();
long startUserTimeNano = getUserTime(); long startUserTimeNano = getUserTime();


app.prepare(url);
// do the test // do the test
for (int i = 0; i < iterations; ++i) { for (int i = 0; i < iterations; ++i) {
app.testRequest(url); app.testRequest(url);
} }
app.tearDown();


// end time // end time
long taskUserTimeNano = getUserTime() - startUserTimeNano; long taskUserTimeNano = getUserTime() - startUserTimeNano;
Expand Down Expand Up @@ -75,5 +76,9 @@ void verifyResult(JSONArray array) {
} }
} }


abstract void prepare(URL url) throws Exception;

abstract void testRequest(URL url) throws Exception; abstract void testRequest(URL url) throws Exception;

abstract void tearDown() throws Exception;
} }
3 changes: 2 additions & 1 deletion test.rb
Expand Up @@ -8,6 +8,7 @@


ITERATIONS = ARGV.shift.to_i ITERATIONS = ARGV.shift.to_i
PATH = ARGV.shift PATH = ARGV.shift
FILES = ARGV.shift || "test_*.rb"
TESTS = [] TESTS = []


def test_http(name, &block) def test_http(name, &block)
Expand All @@ -18,7 +19,7 @@ def test_http(name, &block)


dir = File.dirname(__FILE__) dir = File.dirname(__FILE__)


Dir[File.join(dir, "test_*.rb")].each do |file| Dir[File.join(dir, FILES)].each do |file|
require file require file
end end


Expand Down

0 comments on commit 6218fb2

Please sign in to comment.