[P-unit-devel] SF.net SVN: p-unit: [318] trunk/punit/src/org/punit/method/runner
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <cu...@us...> - 2008-06-10 08:22:50
|
Revision: 318
http://p-unit.svn.sourceforge.net/p-unit/?rev=318&view=rev
Author: cuvavu
Date: 2008-06-10 01:22:58 -0700 (Tue, 10 Jun 2008)
Log Message:
-----------
Making the concurrentRunner run before and after stuff in the same thread as the actual test.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-06-10 08:22:52 UTC (rev 317)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-06-10 08:22:58 UTC (rev 318)
@@ -46,7 +46,7 @@
protected transient Class<? extends Throwable> _expectedException;
- protected abstract void runImpl() throws Throwable;
+ protected abstract void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable;
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
@@ -79,7 +79,7 @@
startWatchers(testInstance, method, params);
setUpAfterWatchers(params);
startToStopThread();
- runImpl();
+ runImpl( doNormalSetupAndTeardown(params) );
stopToStopThread();
runCheckMethod(testInstance, params);
} else {
@@ -171,10 +171,15 @@
} else if (_convention.isParameterizedTest(_class)) {
((Parameterized) _testInstance)
.setUpBeforeWatchers((Parameter) params[0]);
- } else {
- setUp();
}
}
+
+ private boolean doNormalSetupAndTeardown(Object[] params) throws Throwable {
+ if (_convention.isPUnitTest(_class) || _convention.isParameterizedTest(_class)) {
+ return false;
+ }
+ return true;
+ }
private void setUpAfterWatchers(Object[] params) throws Throwable {
if (_convention.isPUnitTest(_class)) {
@@ -200,12 +205,10 @@
} else if (_convention.isParameterizedTest(_class)) {
((Parameterized) _testInstance)
.tearDownAfterWatchers((Parameter) params[0]);
- } else {
- tearDown();
}
}
- private void setUp() throws Throwable {
+ protected void setUp() throws Throwable {
if (_setUpMethods != null) {
for (Method setUpMethod : _setUpMethods) {
try {
@@ -218,7 +221,7 @@
}
}
- private void tearDown() throws Throwable {
+ protected void tearDown() throws Throwable {
if (_tearDownMethods != null) {
for (Method tearDownMethod : _tearDownMethods) {
try {
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-06-10 08:22:52 UTC (rev 317)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-06-10 08:22:58 UTC (rev 318)
@@ -22,21 +22,21 @@
_concurrentCount = concurrentCount;
}
- protected void runImpl() throws Throwable {
- startThreads();
+ protected void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable {
+ startThreads( doNormalSetupAndTeardown );
joinThreads();
if (_concurrentException.size() > 0) {
throw _concurrentException;
}
}
- private void startThreads() {
+ private void startThreads( boolean doNormalSetupAndTeardown ) {
int count = _convention.getConcurrentCount(_testInstance, _method);
int threadCount = count > 0 ? count : _concurrentCount;
_threads = new TestMethodThread[threadCount];
_barrier = new CyclicBarrier(threadCount);
for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread("punit concurrent method runner"); //$NON-NLS-1$
+ _threads[i] = new TestMethodThread("punit concurrent method runner", doNormalSetupAndTeardown); //$NON-NLS-1$
}
for (int i = 0; i < _threads.length; ++i) {
_threads[i].start();
@@ -59,14 +59,26 @@
private class TestMethodThread extends Thread {
- public TestMethodThread(String threadName) {
+ boolean doNormalSetupAndTeardown;
+
+ public TestMethodThread(String threadName, boolean doNormalSetupAndTeardown) {
super(threadName);
+ this.doNormalSetupAndTeardown = doNormalSetupAndTeardown;
}
public void run() {
try {
_barrier.await();
- ConcurrentMethodRunner.this.runMethod();
+ try {
+ if (doNormalSetupAndTeardown) {
+ setUp();
+ }
+ ConcurrentMethodRunner.this.runMethod();
+ } finally {
+ if (doNormalSetupAndTeardown) {
+ tearDown();
+ }
+ }
} catch (Throwable t) {
_concurrentException.add(t);
}
Modified: trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java 2008-06-10 08:22:52 UTC (rev 317)
+++ trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java 2008-06-10 08:22:58 UTC (rev 318)
@@ -8,7 +8,16 @@
private static final long serialVersionUID = 3278612571978181393L;
- protected void runImpl() throws Throwable {
- runMethod();
+ protected void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable {
+ try {
+ if (doNormalSetupAndTeardown) {
+ setUp();
+ }
+ runMethod();
+ } finally {
+ if (doNormalSetupAndTeardown) {
+ tearDown();
+ }
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|