ConcurrentTest并发测试框架介绍
ConcurrentTest
Sourceforge Link: ConcurrentTest, 0.9.1
1. Description
- A java concurrent test library.
* It provides some base class which can simplify perfermance test for concurrent and multi-core program.
* Write code easily, and detailed CSV report is generated automatically.
* Most accurate result of multi-core program.
2. Design
This framework provides several classes to use.
Framework Class Description
1 AbstractRunner -
A abstract super class. You can write test class extends it.
2 RunnerFactory -
A abstract factory. You can extend it and override newRunner() method to create multi threads test runner.
3 ConcurrentTestMeter
A test meter. You cant use ConcurrentTestMeter.createMeter( poolSize, runnerFactory) to create a meter.
You can use concurrentTestMeter.runTest( n,count) to run the test.
4 ConcurrentTestReport -
The concurrent test report. It is created by ConcurrentTestMeter.
It can output CSV format report. You can edit it with Microsoft Excel easily.
3. Demo:
Java Relection Performance Test
(see org.bamboo.concurrenttest.demo.MethodInvokeTest for detailed)
Here is a sample to test java reflection under multi-core,multi thread senario.
1) Write code you want to test.
2) Use ConcurrentTestMeter class to run your test.
3) Write main() method.
4) Performance Test Report.
1) Write code you want to test.
Write a JavaReflectRunner class which extends from AbstractRunner class.
Override doWork(int) method to write logic you want to test,e.g. method.invoke(...)
package org.bamboo.concurrenttest.demo;import java.lang.reflect.Method;public class JavaReflectRunner extends AbstractRunner { private static Method method ; static { try { method = Foo.class.getMethod("sayHello", new Class<?>[]{ String.class }); } catch (Exception e) { } } public void doWork(int i) { try { Foo foo = new Foo(); method.invoke(foo, new Object[]{"ABCD" + i}); } catch (Exception e) { e.printStackTrace(); } }}
public class MethodInvokeTest { public static final int _threadPoolSize = 4; public static void testJavaReflect(int poolSize,int threads ,int runTimes) { ConcurrentTestMeter concurrentTestMeter = ConcurrentTestMeter.createMeter( poolSize, new RunnerFactory() { public Runner newRunner() { return new JavaReflectRunner(); } public String getTestName() { return "JavaReflectRunner"; } }); ConcurrentTestReport report = concurrentTestMeter.runTest( threads,runTimes); System.out.printf("%s \r\n" ,report.toCsvFormat()); }
public static void main(String[] args) { int poolSize = 4; int concurrents = 200; int countPerThread = 10000; System.out.printf(ConcurrentTestReport.getHeader() +"\r\n"); testJavaReflect(poolSize,concurrents, countPerThread); testCglibReflect(poolSize,concurrents,countPerThread); System.out.println("\r\nMain exit..."); }