p-unit-devel Mailing List for p-unit
Status: Beta
Brought to you by:
zhanghuangzhu
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(182) |
Jun
(46) |
Jul
(3) |
Aug
(2) |
Sep
(1) |
Oct
(7) |
Nov
(18) |
Dec
(8) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(9) |
Feb
(5) |
Mar
(10) |
Apr
(17) |
May
(16) |
Jun
(16) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <zha...@us...> - 2008-07-18 05:22:39
|
Revision: 326
http://p-unit.svn.sourceforge.net/p-unit/?rev=326&view=rev
Author: zhanghuangzhu
Date: 2008-07-18 05:22:46 +0000 (Fri, 18 Jul 2008)
Log Message:
-----------
az: run check method after all threads joined.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-06-17 06:35:50 UTC (rev 325)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-07-18 05:22:46 UTC (rev 326)
@@ -27,6 +27,7 @@
Object[] params ) throws Throwable {
startThreads( testInstance, method, params );
joinThreads();
+ runCheckMethod(testInstance, params);
if (_concurrentException.size() > 0) {
throw _concurrentException;
}
@@ -84,7 +85,6 @@
startToStopThread();
ConcurrentMethodRunner.this.runMethod();
stopToStopThread();
- runCheckMethod(testInstance, params);
} finally {
try{
tearDownBeforeWatchers(params);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-06-17 06:35:41
|
Revision: 325
http://p-unit.svn.sourceforge.net/p-unit/?rev=325&view=rev
Author: zhanghuangzhu
Date: 2008-06-16 23:35:50 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Andrew Zhag: removed multiple virtual machine support.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
trunk/punit.test/src/tests/util/TestUtil.java
Removed Paths:
-------------
trunk/punit.test/src/tests/samples/VMsSample.java
Modified: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-06-17 06:35:30 UTC (rev 324)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-06-17 06:35:50 UTC (rev 325)
@@ -27,7 +27,6 @@
_mockEvenListener = new MockEvenListener();
soloRunner.addEventListener(_mockEvenListener);
_methodRunner.setRunner(soloRunner);
- _methodRunner.setRunnerProperties(new RunnerProperties());
_methodRunner.setConvention(new ByNameConvention());
}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2008-06-17 06:35:30 UTC (rev 324)
+++ trunk/punit.test/src/tests/api/org/punit/runner/SoloRunnerTest.java 2008-06-17 06:35:50 UTC (rev 325)
@@ -20,10 +20,6 @@
_runner.addEventListener(_eventListener);
}
- public void testMain() {
- SoloRunner.main(new String[] { TestSuiteClass.class.getName() });
- }
-
public void testRun() {
_runner.run(TestSuiteClass.class);
}
Deleted: trunk/punit.test/src/tests/samples/VMsSample.java
===================================================================
--- trunk/punit.test/src/tests/samples/VMsSample.java 2008-06-17 06:35:30 UTC (rev 324)
+++ trunk/punit.test/src/tests/samples/VMsSample.java 2008-06-17 06:35:50 UTC (rev 325)
@@ -1,72 +0,0 @@
-package tests.samples;
-
-import java.io.File;
-
-import org.punit.runner.SoloRunner;
-import org.punit.type.VM;
-import org.punit.util.IOUtil;
-
-import tests.util.TestUtil;
-
-public class VMsSample {
-
- private static String CLASSPATH;
-
-
- static {
- CLASSPATH = generateClassPath();
- }
-
- private static String HARMONY = "D:\\harmony_trunk\\harmony-jre-r530500\\bin\\java" + CLASSPATH; //$NON-NLS-1$
-
- private static String SUN = "D:\\tools\\jdk1.5.0_07\\bin\\java" + CLASSPATH; //$NON-NLS-1$
-
- public static void main(String[] args) {
- TestUtil.runUnitTest = false;
- VM harmonyVM = new VM(HARMONY, "Harmony"); //$NON-NLS-1$
- VM sunVM = new VM(SUN, "SUN"); //$NON-NLS-1$
- new SoloRunner().runVMs(VMsSample.class, new VM[] { harmonyVM,
- sunVM });
- }
-
- /*
- * D:\harmony_trunk\harmony-jre-r530500\bin\java -cp
- * D:\workspace_3.2\punit.test\bin;D:\workspace_3.2\punit\bin
- * org.punit.runner.PUnitSoloRunner extension.tests.samples.VMsSample
- * D:\workspace_3.2\punit.test true Harmony
- * org.punit.reporter.stream.console.ConsoleLoggerListener
- * org.punit.reporter.stream.file.FileLoggerListener
- * org.punit.reporter.chart.image.OverviewImageReporter
- */
- private static String generateClassPath() {
- StringBuffer sb = new StringBuffer();
- sb.append(" -cp "); //$NON-NLS-1$
- String currentPath = IOUtil.getCurrentPath();
-
- // test project
- sb.append(currentPath);
- sb.append(File.separator);
- sb.append("bin;"); //$NON-NLS-1$
-
- // core project
- sb.append(currentPath.replaceAll("punit.test", "punit")); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append(File.separator);
- sb.append("bin;"); //$NON-NLS-1$
-
- // junit
- sb.append("D:\\tools\\eclipse3.2\\plugins\\org.junit_3.8.1\\junit.jar"); //$NON-NLS-1$
- return sb.toString();
- }
-
- public void test1() {
- TestUtil.doSomething();
- }
-
- public void test2() {
- TestUtil.doSomething();
- }
-
- public void test3() {
- TestUtil.doSomething();
- }
-}
Modified: trunk/punit.test/src/tests/util/TestUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/TestUtil.java 2008-06-17 06:35:30 UTC (rev 324)
+++ trunk/punit.test/src/tests/util/TestUtil.java 2008-06-17 06:35:50 UTC (rev 325)
@@ -1,12 +1,9 @@
package tests.util;
import java.io.*;
-import java.lang.reflect.Method;
-import java.util.Random;
+import java.lang.reflect.*;
+import java.util.*;
-import org.punit.events.EventListener;
-import org.punit.runner.SoloRunner;
-import org.punit.type.VM;
import org.punit.util.*;
public class TestUtil {
@@ -99,17 +96,4 @@
return sb.toString();
}
- public static void runVMs(Class clazz, EventListener[] listeners) {
- runUnitTest = false;
- final String THIS_VM = getVmLaunchString();
- final String NO_VERIFY = " -Xverify:none"; //$NON-NLS-1$
-
- VM vm = new VM(THIS_VM, "VM"); //$NON-NLS-1$
- VM vm_noverify = new VM(THIS_VM + NO_VERIFY, "VM_NOVERIFY"); //$NON-NLS-1$
- SoloRunner runner = new SoloRunner();
- for(int i = 0; i < listeners.length; ++i) {
- runner.addEventListener(listeners[i]);
- }
- runner.runVMs(clazz, new VM[] { vm, vm_noverify });
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-06-17 06:35:23
|
Revision: 324
http://p-unit.svn.sourceforge.net/p-unit/?rev=324&view=rev
Author: zhanghuangzhu
Date: 2008-06-16 23:35:30 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Andrew Zhag: removed multiple virtual machine support.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/method/runner/MethodRunner.java
trunk/punit/src/org/punit/runner/AbstractRunner.java
trunk/punit/src/org/punit/runner/ConcurrentRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/SoloRunner.java
trunk/punit/src/org/punit/runner/VanillaRunner.java
trunk/punit/src/org/punit/util/ReporterUtil.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/RunnerProperties.java
trunk/punit/src/org/punit/util/RunnerUtil.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -22,8 +22,6 @@
private AbstractRunner _runner;
- private RunnerProperties _runnerProperties;
-
protected Convention _convention;
private transient ToStopThread _toStopThread;
@@ -57,10 +55,6 @@
_runner = runner;
}
- public void setRunnerProperties(RunnerProperties props) {
- _runnerProperties = props;
- }
-
public void addWatcher(Watcher watcher) {
_watchers.add(watcher);
}
@@ -71,28 +65,14 @@
public void run(Object testInstance, Method method, Object[] params) {
onMethodStart(method, testInstance, params);
- Throwable throwable = null;
- try {
- if (needsRunMethod()) {
- init(testInstance, method, params);
- runImpl( testInstance, method, params );
- } else {
- startWatchers(testInstance, method, params);
- }
- } catch (Throwable t) {
- throwable = t;
- } finally {
- try {
- if (!needsRunMethod()) {
- stopWatchers(testInstance, method, params);
- }
- } catch (Throwable t) {
- if(throwable == null) {
- throwable = t;
- }
- }
- }
- onMethodEnd(method, testInstance, params, throwable);
+ Throwable throwable = null;
+ try {
+ init(testInstance, method, params);
+ runImpl(testInstance, method, params);
+ } catch (Throwable t) {
+ throwable = t;
+ }
+ onMethodEnd(method, testInstance, params, throwable);
}
protected void startToStopThread() {
@@ -239,10 +219,6 @@
return _watchers;
}
- public boolean needsRunMethod() {
- return !_runnerProperties.isParent;
- }
-
@SuppressWarnings("unchecked")
public Object clone() {
try {
Modified: trunk/punit/src/org/punit/method/runner/MethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/MethodRunner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/method/runner/MethodRunner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -19,8 +19,6 @@
public void run(Object testInstance, Method method, Object[] params);
public void setRunner(AbstractRunner runner);
-
- public void setRunnerProperties(RunnerProperties props);
/**
* @return watchers associated with this method runner
Modified: trunk/punit/src/org/punit/runner/AbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractRunner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/runner/AbstractRunner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -2,7 +2,6 @@
package org.punit.runner;
-import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.atomic.*;
@@ -10,7 +9,6 @@
import org.punit.convention.*;
import org.punit.events.EventListener;
import org.punit.exception.*;
-import org.punit.exception.IOException;
import org.punit.message.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
@@ -34,8 +32,6 @@
private ConsoleLogger _consoleLogger = new ConsoleLogger();
- private RunnerProperties _properties = new RunnerProperties();
-
private ExecutorPool _executorPool;
private Convention _convention;
@@ -48,7 +44,6 @@
_testMethodBuilder = testMethodBuilder;
_methodRunner = testMethodRunner;
_methodRunner.setRunner(this);
- _methodRunner.setRunnerProperties(_properties);
registerDefaultListeners();
setConvention(new ByNameConvention());
}
@@ -109,11 +104,6 @@
});
}
- public int run(Class<?> clazz, RunnerProperties properties) {
- setRunnerProperties(properties);
- return run(clazz);
- }
-
public void setExecutorPool(ExecutorPool pool) {
_executorPool = pool;
}
@@ -130,105 +120,10 @@
}
}
- private void setRunnerProperties(RunnerProperties properties) {
- _properties = properties;
- _methodRunner.setRunnerProperties(_properties);
- }
-
- public void runVMs(Class<?> clazz, VM[] vms) {
- _properties.isParent = true;
- _properties.vms = vms;
- for (int i = 0; i < vms.length; ++i) {
- VM vm = vms[i];
- storeRunnerConfig(vm);
- storeRunnerProperties(vm);
- String command = generateVMCommand(clazz, vm);
- Process p = IOUtil.exec(command);
- readErrorStream(p);
- readOutputStream(p);
- try {
- p.waitFor();
- } catch (InterruptedException e) {
- throw new IOException(e);
- }
- deleteRunnerConfig(vm);
- deleteRunnerProperties(vm);
- }
- filterNonParentEventListeners();
- run(clazz);
- }
public void addWatcher(Watcher watcher) {
_methodRunner.addWatcher(watcher);
}
-
- private void readOutputStream(Process p) {
- new StreamReaderThread(p.getInputStream(), false).start();
- }
-
- private void readErrorStream(Process p) {
- new StreamReaderThread(p.getErrorStream(), true).start();
- }
-
- private void filterNonParentEventListeners() {
- final List<EventListener> newEventListener = new ArrayList<EventListener>();
- Iterator<EventListener> iter = _eventListeners.iterator();
- while (iter.hasNext()) {
- EventListener listener = iter.next();
- if (listener.supportParentRunner()) {
- newEventListener.add(listener);
- }
- }
- _eventListeners.clear();
- _eventListeners.addAll(newEventListener);
- }
-
- private void deleteRunnerProperties(VM vm) {
- IOUtil.deleteFile(runnerPropertiesFileName(vm));
- }
-
- private void deleteRunnerConfig(VM vm) {
- IOUtil.deleteFile(runnerConfigFileName(vm));
- }
-
- private void storeRunnerProperties(VM vm) {
- RunnerProperties properties = new RunnerProperties();
- properties.vmName = vm.punitName();
- properties.isIntermediate = true;
- IOUtil.serialize(properties, runnerPropertiesFileName(vm));
- }
-
- private void storeRunnerConfig(VM vm) {
- IOUtil.serialize(this, runnerConfigFileName(vm));
- }
-
- private String runnerConfigFileName(VM vm) {
- return resultFolder() + File.separator + vm.punitName()
- + ".cfg"; //$NON-NLS-1$
- }
-
- private String runnerPropertiesFileName(VM vm) {
- return resultFolder() + File.separator + vm.punitName()
- + ".props"; //$NON-NLS-1$
- }
-
- public RunnerProperties properties() {
- return _properties;
- }
-
- private String generateVMCommand(Class<?> clazz, VM vm) {
- final StringBuffer sb = new StringBuffer();
- sb.append(vm.path());
- sb.append(" "); //$NON-NLS-1$
- sb.append(this.getClass().getName());
- sb.append(" "); //$NON-NLS-1$
- sb.append(clazz.getName());
- sb.append(" "); //$NON-NLS-1$
- sb.append(runnerConfigFileName(vm));
- sb.append(" "); //$NON-NLS-1$
- sb.append(runnerPropertiesFileName(vm));
- return sb.toString();
- }
private void runTestClass(final Class<?> clazz) {
if (_executorPool == null) {
Modified: trunk/punit/src/org/punit/runner/ConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentRunner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/runner/ConcurrentRunner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -4,17 +4,12 @@
import org.punit.message.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
-import org.punit.util.*;
public class ConcurrentRunner extends AbstractRunner {
private static final long serialVersionUID = -7193902024861434576L;
private static final int DEFAULT_CONCURRENT_COUNT = 10;
-
- public static void main(String[] args) {
- RunnerUtil.run(new ConcurrentRunner(), args);
- }
public ConcurrentRunner() {
this(ConcurrentRunner.DEFAULT_CONCURRENT_COUNT);
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/runner/Runner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -15,10 +15,6 @@
public int run(Class<?> clazz);
- public int run(Class<?> clazz, RunnerProperties properties);
-
- public RunnerProperties properties();
-
public TestMethodBuilder methodBuilder();
public MethodRunner methodRunner();
Deleted: trunk/punit/src/org/punit/runner/RunnerProperties.java
===================================================================
--- trunk/punit/src/org/punit/runner/RunnerProperties.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/runner/RunnerProperties.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -1,21 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.runner;
-
-import java.io.Serializable;
-
-import org.punit.type.VM;
-
-public class RunnerProperties implements Serializable {
-
- private static final long serialVersionUID = -4832579362013257784L;
-
- public String vmName;
-
- public boolean isIntermediate;
-
- public boolean isParent;
-
- public VM[] vms;
-
-}
Modified: trunk/punit/src/org/punit/runner/SoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloRunner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/runner/SoloRunner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -5,16 +5,11 @@
import org.punit.message.*;
import org.punit.method.builder.*;
import org.punit.method.runner.*;
-import org.punit.util.*;
public class SoloRunner extends AbstractRunner {
private static final long serialVersionUID = 5938649527831492676L;
- public static void main(String[] args) {
- RunnerUtil.run(new SoloRunner(), args);
- }
-
public SoloRunner() {
super(new MethodBuilderImpl(), new SoloMethodRunner());
}
Modified: trunk/punit/src/org/punit/runner/VanillaRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/VanillaRunner.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/runner/VanillaRunner.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -27,10 +27,6 @@
return _runner.methodRunner();
}
- public RunnerProperties properties() {
- return _runner.properties();
- }
-
public void resultFolder(String folder) {
_runner.resultFolder(folder);
}
@@ -43,10 +39,6 @@
return _runner.run(clazz);
}
- public int run(Class<?> clazz, RunnerProperties properties) {
- return _runner.run(clazz, properties);
- }
-
public TestResult testResult() {
return _runner.testResult();
}
Modified: trunk/punit/src/org/punit/util/ReporterUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReporterUtil.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/util/ReporterUtil.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -2,11 +2,10 @@
package org.punit.util;
-import java.io.File;
-import java.lang.reflect.Method;
+import java.io.*;
+import java.lang.reflect.*;
-import org.punit.runner.Runner;
-import org.punit.runner.RunnerProperties;
+import org.punit.runner.*;
public class ReporterUtil {
@@ -53,11 +52,6 @@
sb.append(clazz.getName());
sb.append("."); //$NON-NLS-1$
sb.append(runner.punitName());
- RunnerProperties properties = runner.properties();
- if(properties.vmName != null) {
- sb.append("."); //$NON-NLS-1$
- sb.append(properties.vmName);
- }
return sb.toString();
}
Deleted: trunk/punit/src/org/punit/util/RunnerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/RunnerUtil.java 2008-06-17 06:35:04 UTC (rev 323)
+++ trunk/punit/src/org/punit/util/RunnerUtil.java 2008-06-17 06:35:30 UTC (rev 324)
@@ -1,32 +0,0 @@
-/* (C) Copyright 2007, by Andrew Zhang */
-
-package org.punit.util;
-
-import org.punit.message.Messages;
-import org.punit.runner.Runner;
-import org.punit.runner.RunnerProperties;
-
-public class RunnerUtil {
-
- private static final int MAX_ARGS = 3;
-
- public static void run(Runner runner, String[] args) {
- int length = args.length;
- if (length == 0 || length > MAX_ARGS) {
- throw new IllegalArgumentException(length
- + Messages.getString("runner.arguments")); //$NON-NLS-1$
- }
- Runner testRunner = runner;
- RunnerProperties properties = runner.properties();
- Class<?> testClass = ReflectionUtil.newClass(args[0]);
- if (length >= 2) {
- testRunner = (Runner) IOUtil.getSerialiableObject(args[1]);
- }
- if (length >= 3) {
- properties = (RunnerProperties) IOUtil
- .getSerialiableObject(args[2]);
- }
- testRunner.run(testClass, properties);
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-06-17 06:34:59
|
Revision: 323
http://p-unit.svn.sourceforge.net/p-unit/?rev=323&view=rev
Author: zhanghuangzhu
Date: 2008-06-16 23:35:04 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Andrew Zhag: removed multiple virtual machine support.
Modified Paths:
--------------
trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
Modified: trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2008-06-17 06:34:55 UTC (rev 322)
+++ trunk/punit.extension/src/org/punit/reporter/chart/AbstractChartReporter.java 2008-06-17 06:35:04 UTC (rev 323)
@@ -9,9 +9,7 @@
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.punit.events.*;
-import org.punit.exception.IOException;
import org.punit.message.*;
-import org.punit.reporter.chart.image.*;
import org.punit.runner.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -25,8 +23,6 @@
protected ChartRender _render;
- protected transient RunnerProperties _runnerProperties;
-
protected transient Object _testInstance;
public AbstractChartReporter(ChartRender render) {
@@ -38,10 +34,7 @@
@SuppressWarnings("unchecked")
public void onRunnerStart(final Class clazz, Runner runner) {
ReporterUtil.initResultFolder(runner);
- _runnerProperties = runner.properties();
- if (!isIntermediate()) {
- _render.onRunnerStart(clazz, runner);
- }
+ _render.onRunnerStart(clazz, runner);
}
@SuppressWarnings("unchecked")
@@ -51,79 +44,24 @@
String fileName = generateResultFileNamePrefix(runner, key);
storeDataset(dataset, fileName, key);
}
- if (!isIntermediate()) {
- _render.onRunnerEnd(clazz, runner);
- }
+ _render.onRunnerEnd(clazz, runner);
}
private DefaultCategoryDataset getDataset(final Runner runner,
DatasetKey key) {
- DefaultCategoryDataset dataset;
- if (isParentRunner()) {
- dataset = generateDatasetFromChildrenVMs(runner, key);
- } else {
- dataset = (DefaultCategoryDataset) getDatasetOrNew(key);
- }
- return dataset;
+ return getDatasetOrNew(key);
}
- private DefaultCategoryDataset generateDatasetFromChildrenVMs(
- final Runner runner, DatasetKey key) {
- String childFileNamePrefix = generateResultFileNamePrefix(runner, key);
- final VM[] vms = _runnerProperties.vms;
- DefaultCategoryDataset dataset = getDatasetOrNew(key);
- for (int i = 0; i < vms.length; ++i) {
- String vmname = vms[i].punitName();
- String childFileName = generateIntermediateFileName(
- childFileNamePrefix, vmname);
- DefaultCategoryDataset childDataset = consumeChildData(runner,
- childFileName);
- dataset = ChartUtil.appendDataset(dataset, childDataset, vmname);
- }
- return dataset;
- }
- private DefaultCategoryDataset consumeChildData(final Runner runner,
- String childFileName) {
- ObjectInputStream ois = null;
- try {
- FileInputStream fis = new FileInputStream(childFileName);
- ois = new ObjectInputStream(fis);
- return (DefaultCategoryDataset) ois.readObject();
- } catch (Exception e) {
- throw new IOException(e);
- } finally {
- if (ois != null) {
- try {
- ois.close();
- } catch (java.io.IOException e) {
- throw new IOException(e);
- }
- }
- IOUtil.deleteFile(childFileName);
- }
- }
-
private void storeDataset(DefaultCategoryDataset dataset,
- String prefixFileName, DatasetKey key) {
- if (isIntermediate()) {
- String fileName = generateIntermediateFileName(prefixFileName,
- _runnerProperties.vmName);
- ChartUtil.storeDatasetAsObject(dataset, new File(fileName));
- } else {
- String title = key.punitName();
- String yLegendText = watcherLegend(key.watcher());
- JFreeChart chart = ChartUtil.generateChartFromDataset(title,
- yLegendText, dataset);
- _render.renderChart(chart, prefixFileName);
- }
- }
+ String prefixFileName, DatasetKey key) {
+ String title = key.punitName();
+ String yLegendText = watcherLegend(key.watcher());
+ JFreeChart chart = ChartUtil.generateChartFromDataset(title,
+ yLegendText, dataset);
+ _render.renderChart(chart, prefixFileName);
+ }
- private static String generateIntermediateFileName(String prefix,
- String vmName) {
- return prefix + vmName + ImageConstants.SER;
- }
-
private final String generateResultFileNamePrefix(Runner runner,
DatasetKey key) {
StringBuffer sb = new StringBuffer();
@@ -142,14 +80,6 @@
return watcher.punitName() + " [" + watcher.unit() + "]"; //$NON-NLS-1$//$NON-NLS-2$
}
- protected final boolean isIntermediate() {
- return _runnerProperties.isIntermediate;
- }
-
- protected final boolean isParentRunner() {
- return _runnerProperties.isParent;
- }
-
private final DefaultCategoryDataset getDatasetOrNew(DatasetKey key) {
DefaultCategoryDataset dataset = _datasets.get(key);
if (dataset == null) {
@@ -200,9 +130,6 @@
Watcher watcher = iter.next();
DatasetKey key = getKey(watcher);
DefaultCategoryDataset dataset = getDatasetOrNew(key);
- if (isParentRunner()) {
- return;
- }
double value = watcher.value();
String yname = testInstance.getClass().getSimpleName();
String xname = ReporterUtil.simpleMethodName(method, params);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-06-17 06:34:46
|
Revision: 322
http://p-unit.svn.sourceforge.net/p-unit/?rev=322&view=rev
Author: zhanghuangzhu
Date: 2008-06-16 23:34:55 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Andrew Zhag: removed multiple virtual machine support.
Removed Paths:
-------------
trunk/punit.extension.test/src/extension/tests/samples/OverviewVMsSample.java
trunk/punit.extension.test/src/extension/tests/samples/TestClassVMsSample.java
trunk/punit.extension.test/src/extension/tests/samples/TestSuiteVMsSample.java
Deleted: trunk/punit.extension.test/src/extension/tests/samples/OverviewVMsSample.java
===================================================================
--- trunk/punit.extension.test/src/extension/tests/samples/OverviewVMsSample.java 2008-06-17 06:34:35 UTC (rev 321)
+++ trunk/punit.extension.test/src/extension/tests/samples/OverviewVMsSample.java 2008-06-17 06:34:55 UTC (rev 322)
@@ -1,16 +0,0 @@
-package extension.tests.samples;
-
-import org.punit.events.EventListener;
-import org.punit.reporter.chart.OverviewReporter;
-import org.punit.reporter.chart.image.ImageRender;
-
-import tests.api.org.punit.testclasses.TestSuiteClass;
-import tests.util.TestUtil;
-
-public class OverviewVMsSample {
- public static void main(String[] args) {
- TestUtil.runVMs(TestSuiteClass.class,
- new EventListener[] { new OverviewReporter(
- new ImageRender()) });
- }
-}
Deleted: trunk/punit.extension.test/src/extension/tests/samples/TestClassVMsSample.java
===================================================================
--- trunk/punit.extension.test/src/extension/tests/samples/TestClassVMsSample.java 2008-06-17 06:34:35 UTC (rev 321)
+++ trunk/punit.extension.test/src/extension/tests/samples/TestClassVMsSample.java 2008-06-17 06:34:55 UTC (rev 322)
@@ -1,31 +0,0 @@
-package extension.tests.samples;
-
-import org.punit.events.EventListener;
-import org.punit.reporter.chart.TestClassReporter;
-import org.punit.reporter.chart.image.ImageRender;
-
-import tests.util.TestUtil;
-
-public class TestClassVMsSample {
- public static void main(String[] args) {
- TestUtil.runVMs(TestClassVMsSample.class,
- new EventListener[] { new TestClassReporter(
- new ImageRender()) });
- }
-
- public void test1() {
- TestUtil.consumeMemory(200000);
- TestUtil.consumeTime(1000);
- }
-
- public void test2() {
- TestUtil.consumeMemory(100000);
- TestUtil.consumeTime(1000);
- }
-
- public void test3() {
- TestUtil.consumeMemory(200000);
- TestUtil.consumeTime(2000);
- }
-
-}
Deleted: trunk/punit.extension.test/src/extension/tests/samples/TestSuiteVMsSample.java
===================================================================
--- trunk/punit.extension.test/src/extension/tests/samples/TestSuiteVMsSample.java 2008-06-17 06:34:35 UTC (rev 321)
+++ trunk/punit.extension.test/src/extension/tests/samples/TestSuiteVMsSample.java 2008-06-17 06:34:55 UTC (rev 322)
@@ -1,17 +0,0 @@
-package extension.tests.samples;
-
-import org.punit.events.EventListener;
-import org.punit.reporter.chart.TestSuiteReporter;
-import org.punit.reporter.chart.pdf.PDFRender;
-
-import tests.api.org.punit.testclasses.TestSuite2;
-import tests.util.TestUtil;
-
-public class TestSuiteVMsSample {
-
- public static void main(String[] args) {
- TestUtil.runVMs(TestSuite2.class,
- new EventListener[] { new TestSuiteReporter(new PDFRender()) });
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-06-17 06:34:25
|
Revision: 321
http://p-unit.svn.sourceforge.net/p-unit/?rev=321&view=rev
Author: zhanghuangzhu
Date: 2008-06-16 23:34:35 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Andrew Zhag: removed multiple virtual machine support.
Removed Paths:
-------------
trunk/punit.samples/src/samples/vms/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Andrew Z. <zha...@gm...> - 2008-06-17 00:06:39
|
On Tue, Jun 17, 2008 at 12:25 AM, Chris Wilson <ch...@cj...> wrote:
> Hi,
>
> I have had a tinker around and have refactored the code from the
> AbstractMethodRunner.run method into the runImpl methods. This has
> restored the original run order while keeping everything in the
> threads it needs to be in.
>
> So now, we have the original running order (the setup stuff gets done
> before the watchers) while the setup gets run in the thread it is
> setting up. This setup is run once in each thread which is, I think,
> the correct behaviour.
>
> Let me know what you think of this.
Hi Chris,
Looks fine for me except one point: IMO, check method should be run only
once.
setup -> testMethod -> tearDown
... ... checkMethod
setup -> testMethod -> tearDown
CheckMethod is invoked to verify whether all the result is OK after all
threads end. If each thread wants to assert data, user can write the
assertion code in test method just as normal unit test. How do you think
about it? Thanks!
>
> Chris
>
>
>
> 2008/6/13 Andrew Zhang <zha...@gm...>:
> > Hi Chris,
> >
> > Did you receive my last reply? Thanks!
> >
> > On Wed, Jun 11, 2008 at 11:35 PM, Andrew Zhang <zha...@gm...>
> > wrote:
> >>
> >>
> >> On Wed, Jun 11, 2008 at 11:02 PM, Chris Wilson <ch...@cj...>
> >> wrote:
> >>>
> >>> Hi,
> >>>
> >>> I am writing tests that need to run both a unit tests and performance
> >>> tests, so we are writing them so that the operation includes various
> >>> bits of setup in the setUp method. I can see that the instance below
> >>> makes sense to just run the setup once, but likewise your example
> >>> won't work if run as a unit test with junit.
> >>>
> >>> I think just measuring the time to execute the test method would be
> >>> ideal, but depending on the scenario, as long as you know that every
> >>> run is doing the same thing you can extrapolate how long it takes.
> >>> You could, for instance, have an empty test and then the time for that
> >>> would give you a baseline to compaire other tests against (as it will
> >>> be doing all the setUp etc and method and thread initialisation
> >>> stuff).
> >>>
> >>> I would say that if there needs to be a setup method only run once for
> >>> all performace tests either the beforeClass method or a special method
> >>> should be used. I would just expect a setUp or @Before method to run
> >>> before all tests.
> >>>
> >>> If I were to have a class with two tests in it testA and testB, what
> >>> would the run order:
> >>>
> >>> setUp
> >>> testA
> >>> testA
> >>> testA
> >>> tearDown
> >>>
> >>> setUp
> >>> testB
> >>> testB
> >>> testB
> >>> tearDown
> >>
> >> Hi Chris,
> >>
> >> exactly.
> >>>
> >>>
> >>> or something else?
> >>>
> >>> I guess I could live with this, actually, though it doesn't feel quite
> >>> right, as long as the setUp method is run in the same thread as the
> >>> test method.
> >>
> >> For concurrent test case, we usually want to assert concurrent behavior
> of
> >> the same instance. That's why setUp only runs once.
> >> Otherwise, it doesn't make too much sense to run the test case like
> below,
> >> because every thread is totally independent of each other.
> >> setUp () { foo = new Foo(); }
> >> test() { operate on foo and assert foo; }
> >>
> >> Chris, for your scenario, does concurrent runner verify anything more
> than
> >> solo runner? Thanks a lot!
> >>>
> >>>
> >>> Chris
> >>>
> >>> 2008/6/11 Andrew Zhang <zha...@gm...>:
> >>> >
> >>> >
> >>> > On Wed, Jun 11, 2008 at 10:25 PM, Chris Wilson <ch...@cj...>
> >>> > wrote:
> >>> >>
> >>> >> Hi,
> >>> >>
> >>> >> I agree that the setUp/tearDown should not be timed - I hadn't
> though
> >>> >> of that in my code. I wasn't massively clear as to what a lot of
> the
> >>> >> watcher etc code was doing. It does, however, make a lot of sense
> to
> >>> >> have the setUp/tearDown run once per test run - ie if you run testA
> >>> >> method five times you should run the setUp and TearDown five times
> >>> >> too. That would be the expected behaviour, I would think, as that
> is
> >>> >> what happens when the tests are run in general.
> >>> >>
> >>> >>
> >>> >> Perhaps what needs to happen is that all the watcher code needs to
> be
> >>> >> run in the same thread as the test?
> >>> >
> >>> > Hi Chris,
> >>> >
> >>> > My intuition is that multiple setUp/tearDown makes sense for some
> >>> > cases, but
> >>> > single run also is reasonable sometimes. :)
> >>> >
> >>> > Take testing ArrayList#add method as an example:
> >>> > setUp: new an ArrayList instance
> >>> > testAdd: list.add(someObject); // run 10 times
> >>> > checkAdd: assert the list size is 10
> >>> >
> >>> > The test makes sure that concurrent invocation on list.add doesn't
> >>> > throw any
> >>> > exception, and the result list size is 10.
> >>> > For this example, if ArrayList is replaced with Vector, it may very
> >>> > possible
> >>> > fail because Vector#add is not synchronized and may throw some
> >>> > exception
> >>> > during add (I can't remember the exact exception).
> >>> >
> >>> > Would you please explain your scenario a little bit? Thanks!
> >>> >
> >>> > Another point is that which kind of time do we want to measure?
> >>> >
> >>> > setUp -> testAdd 10 times-> checkAdd -> tearDown
> >>> >
> >>> > The original code measures the time/memory to execute testAdd 10
> times.
> >>> >
> >>> > What's your idea? Thanks a lot!
> >>> >
> >>> > p.s. sorry, I forget to add p-unit-dev in the receiver list of my
> last
> >>> > mail.
> >>> > Anyway, you have quoted it. :)
> >>> >>
> >>> >>
> >>> >> Chris
> >>> >>
> >>> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
> >>> >> >
> >>> >> >
> >>> >> > On Wed, Jun 11, 2008 at 4:07 PM, Chris Wilson <
> ch...@cj...>
> >>> >> > wrote:
> >>> >> >>
> >>> >> >> Hi,
> >>> >> >>
> >>> >> >> No, I removed the reverence to setup in the setUpBeforeWatchers
> >>> >> >> method
> >>> >> >> (and tearDown in the setUpAfterWatchers too). The logic part of
> it
> >>> >> >> is
> >>> >> >> done by the doNormalSetupAndTeardown method and then based on
> that
> >>> >> >> it'll run them or not.
> >>> >> >
> >>> >> > Hi Chris,
> >>> >> >
> >>> >> > SetUp/tearDown method is usually considered as preparation/cleanup
> >>> >> > of a
> >>> >> > test
> >>> >> > case so that p-unit only measures the execution time and memory of
> >>> >> > test
> >>> >> > method instead of test method + setUp/tearDown.
> >>> >> >
> >>> >> > setUpBeforeWatchers(params);
> >>> >> > startWatchers(testInstance, method, params); // begin to measure
> >>> >> > setUpAfterWatchers(params);
> >>> >> > startToStopThread();
> >>> >> > runImpl();
> >>> >> > stopToStopThread();
> >>> >> >
> >>> >> > Another point you addressed is that should concurrent test method
> >>> >> > run
> >>> >> > setUp/tearDown multiple times or single time?
> >>> >> > I'm not 100% sure when I designed ConcurrentRunner. For your case,
> >>> >> > it
> >>> >> > looks
> >>> >> > like that you prefer multiple option. Do I understand correctly?
> >>> >> > Thanks!
> >>> >> >
> >>> >> >
> >>> >> >
> >>> >> >>
> >>> >> >>
> >>> >> >> Chris
> >>> >> >>
> >>> >> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
> >>> >> >> > Hi Chris,
> >>> >> >> >
> >>> >> >> > In original code of AbstractMethodRunner#run, it invokes setup
> as
> >>> >> >> > well:
> >>> >> >> >
> >>> >> >> > init(testInstance, method, params);
> >>> >> >> > setUpBeforeWatchers(params); // setup will be
> run
> >>> >> >> > here.
> >>> >> >> > startWatchers(testInstance, method, params);
> >>> >> >> > setUpAfterWatchers(params);
> >>> >> >> > startToStopThread();
> >>> >> >> > runImpl();
> >>> >> >> > stopToStopThread();
> >>> >> >> > runCheckMethod(testInstance, params);
> >>> >> >> >
> >>> >> >> > Will your modification cause multiple run of setUp & tearDown?
> >>> >> >> > Thanks!
> >>> >> >> >
> >>> >> >> > On Tue, Jun 10, 2008 at 4:22 PM, <cu...@us...
> >
> >>> >> >> > wrote:
> >>> >> >> >>
> >>> >> >> >> 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.
> >>> >> >> >>
> >>> >> >> >>
> >>> >> >> >>
> >>> >> >> >>
> >>> >> >> >>
> -------------------------------------------------------------------------
> >>> >> >> >> Check out the new SourceForge.net Marketplace.
> >>> >> >> >> It's the best place to buy or sell services for
> >>> >> >> >> just about anything Open Source.
> >>> >> >> >> http://sourceforge.net/services/buy/index.php
> >>> >> >> >> _______________________________________________
> >>> >> >> >> P-unit-devel mailing list
> >>> >> >> >> P-u...@li...
> >>> >> >> >> https://lists.sourceforge.net/lists/listinfo/p-unit-devel
> >>> >> >> >
> >>> >> >> >
> >>> >> >> >
> >>> >> >> > --
> >>> >> >> > Best regards,
> >>> >> >> > Andrew Zhang
> >>> >> >> >
> >>> >> >> > db4o - database for Android: www.db4o.com
> >>> >> >> > http://zhanghuangzhu.blogspot.com/
> >>> >> >
> >>> >> >
> >>> >> >
> >>> >> > --
> >>> >> > Best regards,
> >>> >> > Andrew Zhang
> >>> >> >
> >>> >> > db4o - database for Android: www.db4o.com
> >>> >> > http://zhanghuangzhu.blogspot.com/
> >>> >
> >>> >
> >>> >
> >>> > --
> >>> > Best regards,
> >>> > Andrew Zhang
> >>> >
> >>> > db4o - database for Android: www.db4o.com
> >>> > http://zhanghuangzhu.blogspot.com/
> >>
> >>
> >>
> >> --
> >> Best regards,
> >> Andrew Zhang
> >>
> >> db4o - database for Android: www.db4o.com
> >> http://zhanghuangzhu.blogspot.com/
> >
> >
> > --
> > Best regards,
> > Andrew Zhang
> >
> > db4o - database for Android: www.db4o.com
> > http://zhanghuangzhu.blogspot.com/
>
--
Best regards,
Andrew Zhang
db4o - database for Android: www.db4o.com
http://zhanghuangzhu.blogspot.com/
|
|
From: Chris W. <ch...@cj...> - 2008-06-16 16:25:52
|
Hi,
I have had a tinker around and have refactored the code from the
AbstractMethodRunner.run method into the runImpl methods. This has
restored the original run order while keeping everything in the
threads it needs to be in.
So now, we have the original running order (the setup stuff gets done
before the watchers) while the setup gets run in the thread it is
setting up. This setup is run once in each thread which is, I think,
the correct behaviour.
Let me know what you think of this.
Chris
2008/6/13 Andrew Zhang <zha...@gm...>:
> Hi Chris,
>
> Did you receive my last reply? Thanks!
>
> On Wed, Jun 11, 2008 at 11:35 PM, Andrew Zhang <zha...@gm...>
> wrote:
>>
>>
>> On Wed, Jun 11, 2008 at 11:02 PM, Chris Wilson <ch...@cj...>
>> wrote:
>>>
>>> Hi,
>>>
>>> I am writing tests that need to run both a unit tests and performance
>>> tests, so we are writing them so that the operation includes various
>>> bits of setup in the setUp method. I can see that the instance below
>>> makes sense to just run the setup once, but likewise your example
>>> won't work if run as a unit test with junit.
>>>
>>> I think just measuring the time to execute the test method would be
>>> ideal, but depending on the scenario, as long as you know that every
>>> run is doing the same thing you can extrapolate how long it takes.
>>> You could, for instance, have an empty test and then the time for that
>>> would give you a baseline to compaire other tests against (as it will
>>> be doing all the setUp etc and method and thread initialisation
>>> stuff).
>>>
>>> I would say that if there needs to be a setup method only run once for
>>> all performace tests either the beforeClass method or a special method
>>> should be used. I would just expect a setUp or @Before method to run
>>> before all tests.
>>>
>>> If I were to have a class with two tests in it testA and testB, what
>>> would the run order:
>>>
>>> setUp
>>> testA
>>> testA
>>> testA
>>> tearDown
>>>
>>> setUp
>>> testB
>>> testB
>>> testB
>>> tearDown
>>
>> Hi Chris,
>>
>> exactly.
>>>
>>>
>>> or something else?
>>>
>>> I guess I could live with this, actually, though it doesn't feel quite
>>> right, as long as the setUp method is run in the same thread as the
>>> test method.
>>
>> For concurrent test case, we usually want to assert concurrent behavior of
>> the same instance. That's why setUp only runs once.
>> Otherwise, it doesn't make too much sense to run the test case like below,
>> because every thread is totally independent of each other.
>> setUp () { foo = new Foo(); }
>> test() { operate on foo and assert foo; }
>>
>> Chris, for your scenario, does concurrent runner verify anything more than
>> solo runner? Thanks a lot!
>>>
>>>
>>> Chris
>>>
>>> 2008/6/11 Andrew Zhang <zha...@gm...>:
>>> >
>>> >
>>> > On Wed, Jun 11, 2008 at 10:25 PM, Chris Wilson <ch...@cj...>
>>> > wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> I agree that the setUp/tearDown should not be timed - I hadn't though
>>> >> of that in my code. I wasn't massively clear as to what a lot of the
>>> >> watcher etc code was doing. It does, however, make a lot of sense to
>>> >> have the setUp/tearDown run once per test run - ie if you run testA
>>> >> method five times you should run the setUp and TearDown five times
>>> >> too. That would be the expected behaviour, I would think, as that is
>>> >> what happens when the tests are run in general.
>>> >>
>>> >>
>>> >> Perhaps what needs to happen is that all the watcher code needs to be
>>> >> run in the same thread as the test?
>>> >
>>> > Hi Chris,
>>> >
>>> > My intuition is that multiple setUp/tearDown makes sense for some
>>> > cases, but
>>> > single run also is reasonable sometimes. :)
>>> >
>>> > Take testing ArrayList#add method as an example:
>>> > setUp: new an ArrayList instance
>>> > testAdd: list.add(someObject); // run 10 times
>>> > checkAdd: assert the list size is 10
>>> >
>>> > The test makes sure that concurrent invocation on list.add doesn't
>>> > throw any
>>> > exception, and the result list size is 10.
>>> > For this example, if ArrayList is replaced with Vector, it may very
>>> > possible
>>> > fail because Vector#add is not synchronized and may throw some
>>> > exception
>>> > during add (I can't remember the exact exception).
>>> >
>>> > Would you please explain your scenario a little bit? Thanks!
>>> >
>>> > Another point is that which kind of time do we want to measure?
>>> >
>>> > setUp -> testAdd 10 times-> checkAdd -> tearDown
>>> >
>>> > The original code measures the time/memory to execute testAdd 10 times.
>>> >
>>> > What's your idea? Thanks a lot!
>>> >
>>> > p.s. sorry, I forget to add p-unit-dev in the receiver list of my last
>>> > mail.
>>> > Anyway, you have quoted it. :)
>>> >>
>>> >>
>>> >> Chris
>>> >>
>>> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
>>> >> >
>>> >> >
>>> >> > On Wed, Jun 11, 2008 at 4:07 PM, Chris Wilson <ch...@cj...>
>>> >> > wrote:
>>> >> >>
>>> >> >> Hi,
>>> >> >>
>>> >> >> No, I removed the reverence to setup in the setUpBeforeWatchers
>>> >> >> method
>>> >> >> (and tearDown in the setUpAfterWatchers too). The logic part of it
>>> >> >> is
>>> >> >> done by the doNormalSetupAndTeardown method and then based on that
>>> >> >> it'll run them or not.
>>> >> >
>>> >> > Hi Chris,
>>> >> >
>>> >> > SetUp/tearDown method is usually considered as preparation/cleanup
>>> >> > of a
>>> >> > test
>>> >> > case so that p-unit only measures the execution time and memory of
>>> >> > test
>>> >> > method instead of test method + setUp/tearDown.
>>> >> >
>>> >> > setUpBeforeWatchers(params);
>>> >> > startWatchers(testInstance, method, params); // begin to measure
>>> >> > setUpAfterWatchers(params);
>>> >> > startToStopThread();
>>> >> > runImpl();
>>> >> > stopToStopThread();
>>> >> >
>>> >> > Another point you addressed is that should concurrent test method
>>> >> > run
>>> >> > setUp/tearDown multiple times or single time?
>>> >> > I'm not 100% sure when I designed ConcurrentRunner. For your case,
>>> >> > it
>>> >> > looks
>>> >> > like that you prefer multiple option. Do I understand correctly?
>>> >> > Thanks!
>>> >> >
>>> >> >
>>> >> >
>>> >> >>
>>> >> >>
>>> >> >> Chris
>>> >> >>
>>> >> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
>>> >> >> > Hi Chris,
>>> >> >> >
>>> >> >> > In original code of AbstractMethodRunner#run, it invokes setup as
>>> >> >> > well:
>>> >> >> >
>>> >> >> > init(testInstance, method, params);
>>> >> >> > setUpBeforeWatchers(params); // setup will be run
>>> >> >> > here.
>>> >> >> > startWatchers(testInstance, method, params);
>>> >> >> > setUpAfterWatchers(params);
>>> >> >> > startToStopThread();
>>> >> >> > runImpl();
>>> >> >> > stopToStopThread();
>>> >> >> > runCheckMethod(testInstance, params);
>>> >> >> >
>>> >> >> > Will your modification cause multiple run of setUp & tearDown?
>>> >> >> > Thanks!
>>> >> >> >
>>> >> >> > On Tue, Jun 10, 2008 at 4:22 PM, <cu...@us...>
>>> >> >> > wrote:
>>> >> >> >>
>>> >> >> >> 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.
>>> >> >> >>
>>> >> >> >>
>>> >> >> >>
>>> >> >> >>
>>> >> >> >> -------------------------------------------------------------------------
>>> >> >> >> Check out the new SourceForge.net Marketplace.
>>> >> >> >> It's the best place to buy or sell services for
>>> >> >> >> just about anything Open Source.
>>> >> >> >> http://sourceforge.net/services/buy/index.php
>>> >> >> >> _______________________________________________
>>> >> >> >> P-unit-devel mailing list
>>> >> >> >> P-u...@li...
>>> >> >> >> https://lists.sourceforge.net/lists/listinfo/p-unit-devel
>>> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >> > --
>>> >> >> > Best regards,
>>> >> >> > Andrew Zhang
>>> >> >> >
>>> >> >> > db4o - database for Android: www.db4o.com
>>> >> >> > http://zhanghuangzhu.blogspot.com/
>>> >> >
>>> >> >
>>> >> >
>>> >> > --
>>> >> > Best regards,
>>> >> > Andrew Zhang
>>> >> >
>>> >> > db4o - database for Android: www.db4o.com
>>> >> > http://zhanghuangzhu.blogspot.com/
>>> >
>>> >
>>> >
>>> > --
>>> > Best regards,
>>> > Andrew Zhang
>>> >
>>> > db4o - database for Android: www.db4o.com
>>> > http://zhanghuangzhu.blogspot.com/
>>
>>
>>
>> --
>> Best regards,
>> Andrew Zhang
>>
>> db4o - database for Android: www.db4o.com
>> http://zhanghuangzhu.blogspot.com/
>
>
> --
> Best regards,
> Andrew Zhang
>
> db4o - database for Android: www.db4o.com
> http://zhanghuangzhu.blogspot.com/
|
|
From: <cu...@us...> - 2008-06-16 16:18:13
|
Revision: 320
http://p-unit.svn.sourceforge.net/p-unit/?rev=320&view=rev
Author: cuvavu
Date: 2008-06-16 09:18:03 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Restoring the original ordering for running a method. This is almost a revert of previous change, probably worth looking at last two revisions to get a grip of where the code has gone.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
Modified: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-06-16 16:17:56 UTC (rev 319)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-06-16 16:18:03 UTC (rev 320)
@@ -109,17 +109,23 @@
private static class MockMethodRunner extends AbstractMethodRunner {
public boolean isInvoked;
- protected void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable {
+ protected void runImpl( Object testInstance, Method method, Object[] params ) throws Throwable {
isInvoked = true;
try {
- if (doNormalSetupAndTeardown) {
- setUp();
- }
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
+ startToStopThread();
super.runMethod();
+ stopToStopThread();
+ runCheckMethod(testInstance, params);
} finally {
- if (doNormalSetupAndTeardown) {
- tearDown();
- }
+ try{
+ tearDownBeforeWatchers(params);
+ } finally {
+ stopWatchers(testInstance, method, params);
+ tearDownAfterWatchers(params);
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cu...@us...> - 2008-06-16 16:17:58
|
Revision: 319
http://p-unit.svn.sourceforge.net/p-unit/?rev=319&view=rev
Author: cuvavu
Date: 2008-06-16 09:17:56 -0700 (Mon, 16 Jun 2008)
Log Message:
-----------
Restoring the original ordering for running a method. This is almost a revert of previous change, probably worth looking at last two revisions to get a grip of where the code has gone.
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:58 UTC (rev 318)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2008-06-16 16:17:56 UTC (rev 319)
@@ -46,7 +46,7 @@
protected transient Class<? extends Throwable> _expectedException;
- protected abstract void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable;
+ protected abstract void runImpl( Object testInstance, Method method, Object[] params ) throws Throwable;
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
@@ -75,13 +75,7 @@
try {
if (needsRunMethod()) {
init(testInstance, method, params);
- setUpBeforeWatchers(params);
- startWatchers(testInstance, method, params);
- setUpAfterWatchers(params);
- startToStopThread();
- runImpl( doNormalSetupAndTeardown(params) );
- stopToStopThread();
- runCheckMethod(testInstance, params);
+ runImpl( testInstance, method, params );
} else {
startWatchers(testInstance, method, params);
}
@@ -89,43 +83,32 @@
throwable = t;
} finally {
try {
- if (needsRunMethod()) {
- tearDownBeforeWatchers(params);
+ if (!needsRunMethod()) {
+ stopWatchers(testInstance, method, params);
}
} catch (Throwable t) {
if(throwable == null) {
throwable = t;
}
- } finally {
- try {
- stopWatchers(testInstance, method, params);
- if (needsRunMethod()) {
- tearDownAfterWatchers(params);
- }
- } catch (Throwable t) {
- if(throwable == null) {
- throwable = t;
- }
- }
}
}
onMethodEnd(method, testInstance, params, throwable);
}
- private void startToStopThread() {
+ protected void startToStopThread() {
if (_toStopThread != null) {
_toStopThread.start();
}
}
- private void stopToStopThread() {
+ protected void stopToStopThread() {
if (_toStopThread != null) {
_toStopThread.close();
_toStopThread = null;
}
}
- private void runCheckMethod(Object testInstance, Object[] params) {
+ protected void runCheckMethod(Object testInstance, Object[] params) {
if (_checkMethod != null) {
ReflectionUtil.invokeMethod(_checkMethod, testInstance, params);
}
@@ -171,17 +154,12 @@
} 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 {
+ protected void setUpAfterWatchers(Object[] params) throws Throwable {
if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).setUpAfterWatchers();
} else if (_convention.isParameterizedTest(_class)) {
@@ -190,7 +168,7 @@
}
}
- private void tearDownBeforeWatchers(Object[] params) throws Throwable {
+ protected void tearDownBeforeWatchers(Object[] params) throws Throwable {
if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).tearDownBeforeWatchers();
} else if (_convention.isParameterizedTest(_class)) {
@@ -199,12 +177,14 @@
}
}
- private void tearDownAfterWatchers(Object[] params) throws Throwable {
+ protected void tearDownAfterWatchers(Object[] params) throws Throwable {
if (_convention.isPUnitTest(_class)) {
((Test) _testInstance).tearDownAfterWatchers();
} else if (_convention.isParameterizedTest(_class)) {
((Parameterized) _testInstance)
.tearDownAfterWatchers((Parameter) params[0]);
+ } else {
+ tearDown();
}
}
Modified: trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-06-10 08:22:58 UTC (rev 318)
+++ trunk/punit/src/org/punit/method/runner/ConcurrentMethodRunner.java 2008-06-16 16:17:56 UTC (rev 319)
@@ -2,6 +2,7 @@
package org.punit.method.runner;
+import java.lang.reflect.Method;
import java.util.concurrent.*;
import org.punit.exception.*;
@@ -22,21 +23,23 @@
_concurrentCount = concurrentCount;
}
- protected void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable {
- startThreads( doNormalSetupAndTeardown );
+ protected void runImpl( Object testInstance, Method method,
+ Object[] params ) throws Throwable {
+ startThreads( testInstance, method, params );
joinThreads();
if (_concurrentException.size() > 0) {
throw _concurrentException;
}
}
- private void startThreads( boolean doNormalSetupAndTeardown ) {
+ private void startThreads( Object testInstance, Method method,
+ Object[] params ) {
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", doNormalSetupAndTeardown); //$NON-NLS-1$
+ _threads[i] = new TestMethodThread("punit concurrent method runner", testInstance, method, params); //$NON-NLS-1$
}
for (int i = 0; i < _threads.length; ++i) {
_threads[i].start();
@@ -59,29 +62,40 @@
private class TestMethodThread extends Thread {
- boolean doNormalSetupAndTeardown;
+ private Object testInstance;
+ private Method method;
+ private Object[] params;
- public TestMethodThread(String threadName, boolean doNormalSetupAndTeardown) {
+ public TestMethodThread(String threadName, Object testInstance, Method method,
+ Object[] params ) {
super(threadName);
- this.doNormalSetupAndTeardown = doNormalSetupAndTeardown;
+ this.testInstance = testInstance;
+ this.method = method;
+ this.params = params;
}
public void run() {
try {
_barrier.await();
try {
- if (doNormalSetupAndTeardown) {
- setUp();
- }
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
+ startToStopThread();
ConcurrentMethodRunner.this.runMethod();
+ stopToStopThread();
+ runCheckMethod(testInstance, params);
} finally {
- if (doNormalSetupAndTeardown) {
- tearDown();
- }
+ try{
+ tearDownBeforeWatchers(params);
+ } finally {
+ stopWatchers(testInstance, method, params);
+ tearDownAfterWatchers(params);
+ }
}
} catch (Throwable t) {
_concurrentException.add(t);
}
}
}
-}
+}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java 2008-06-10 08:22:58 UTC (rev 318)
+++ trunk/punit/src/org/punit/method/runner/SoloMethodRunner.java 2008-06-16 16:17:56 UTC (rev 319)
@@ -2,22 +2,30 @@
package org.punit.method.runner;
+import java.lang.reflect.Method;
+
public class SoloMethodRunner extends AbstractMethodRunner {
private static final long serialVersionUID = 3278612571978181393L;
- protected void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable {
+ protected void runImpl( Object testInstance, Method method, Object[] params ) throws Throwable {
try {
- if (doNormalSetupAndTeardown) {
- setUp();
- }
+ setUpBeforeWatchers(params);
+ startWatchers(testInstance, method, params);
+ setUpAfterWatchers(params);
+ startToStopThread();
runMethod();
+ stopToStopThread();
+ runCheckMethod(testInstance, params);
} finally {
- if (doNormalSetupAndTeardown) {
- tearDown();
- }
+ try{
+ tearDownBeforeWatchers(params);
+ } finally {
+ stopWatchers(testInstance, method, params);
+ tearDownAfterWatchers(params);
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Andrew Z. <zha...@gm...> - 2008-06-13 12:00:37
|
Hi Chris,
Did you receive my last reply? Thanks!
On Wed, Jun 11, 2008 at 11:35 PM, Andrew Zhang <zha...@gm...>
wrote:
>
>
> On Wed, Jun 11, 2008 at 11:02 PM, Chris Wilson <ch...@cj...>
> wrote:
>
>> Hi,
>>
>> I am writing tests that need to run both a unit tests and performance
>> tests, so we are writing them so that the operation includes various
>> bits of setup in the setUp method. I can see that the instance below
>> makes sense to just run the setup once, but likewise your example
>> won't work if run as a unit test with junit.
>>
>> I think just measuring the time to execute the test method would be
>> ideal, but depending on the scenario, as long as you know that every
>> run is doing the same thing you can extrapolate how long it takes.
>> You could, for instance, have an empty test and then the time for that
>> would give you a baseline to compaire other tests against (as it will
>> be doing all the setUp etc and method and thread initialisation
>> stuff).
>>
>> I would say that if there needs to be a setup method only run once for
>> all performace tests either the beforeClass method or a special method
>> should be used. I would just expect a setUp or @Before method to run
>> before all tests.
>>
>> If I were to have a class with two tests in it testA and testB, what
>> would the run order:
>>
>> setUp
>> testA
>> testA
>> testA
>> tearDown
>>
>> setUp
>> testB
>> testB
>> testB
>> tearDown
>>
>
> Hi Chris,
>
> exactly.
>
>>
>>
>> or something else?
>>
>> I guess I could live with this, actually, though it doesn't feel quite
>> right, as long as the setUp method is run in the same thread as the
>> test method.
>
>
> For concurrent test case, we usually want to assert concurrent behavior of
> the same instance. That's why setUp only runs once.
> Otherwise, it doesn't make too much sense to run the test case like below,
> because every thread is totally independent of each other.
> setUp () { foo = new Foo(); }
> test() { operate on foo and assert foo; }
>
> Chris, for your scenario, does concurrent runner verify anything more than
> solo runner? Thanks a lot!
>
>>
>>
>> Chris
>>
>> 2008/6/11 Andrew Zhang <zha...@gm...>:
>> >
>> >
>> > On Wed, Jun 11, 2008 at 10:25 PM, Chris Wilson <ch...@cj...>
>> wrote:
>> >>
>> >> Hi,
>> >>
>> >> I agree that the setUp/tearDown should not be timed - I hadn't though
>> >> of that in my code. I wasn't massively clear as to what a lot of the
>> >> watcher etc code was doing. It does, however, make a lot of sense to
>> >> have the setUp/tearDown run once per test run - ie if you run testA
>> >> method five times you should run the setUp and TearDown five times
>> >> too. That would be the expected behaviour, I would think, as that is
>> >> what happens when the tests are run in general.
>> >>
>> >>
>> >> Perhaps what needs to happen is that all the watcher code needs to be
>> >> run in the same thread as the test?
>> >
>> > Hi Chris,
>> >
>> > My intuition is that multiple setUp/tearDown makes sense for some cases,
>> but
>> > single run also is reasonable sometimes. :)
>> >
>> > Take testing ArrayList#add method as an example:
>> > setUp: new an ArrayList instance
>> > testAdd: list.add(someObject); // run 10 times
>> > checkAdd: assert the list size is 10
>> >
>> > The test makes sure that concurrent invocation on list.add doesn't throw
>> any
>> > exception, and the result list size is 10.
>> > For this example, if ArrayList is replaced with Vector, it may very
>> possible
>> > fail because Vector#add is not synchronized and may throw some exception
>> > during add (I can't remember the exact exception).
>> >
>> > Would you please explain your scenario a little bit? Thanks!
>> >
>> > Another point is that which kind of time do we want to measure?
>> >
>> > setUp -> testAdd 10 times-> checkAdd -> tearDown
>> >
>> > The original code measures the time/memory to execute testAdd 10 times.
>> >
>> > What's your idea? Thanks a lot!
>> >
>> > p.s. sorry, I forget to add p-unit-dev in the receiver list of my last
>> mail.
>> > Anyway, you have quoted it. :)
>> >>
>> >>
>> >> Chris
>> >>
>> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
>> >> >
>> >> >
>> >> > On Wed, Jun 11, 2008 at 4:07 PM, Chris Wilson <ch...@cj...>
>> >> > wrote:
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> No, I removed the reverence to setup in the setUpBeforeWatchers
>> method
>> >> >> (and tearDown in the setUpAfterWatchers too). The logic part of it
>> is
>> >> >> done by the doNormalSetupAndTeardown method and then based on that
>> >> >> it'll run them or not.
>> >> >
>> >> > Hi Chris,
>> >> >
>> >> > SetUp/tearDown method is usually considered as preparation/cleanup of
>> a
>> >> > test
>> >> > case so that p-unit only measures the execution time and memory of
>> test
>> >> > method instead of test method + setUp/tearDown.
>> >> >
>> >> > setUpBeforeWatchers(params);
>> >> > startWatchers(testInstance, method, params); // begin to measure
>> >> > setUpAfterWatchers(params);
>> >> > startToStopThread();
>> >> > runImpl();
>> >> > stopToStopThread();
>> >> >
>> >> > Another point you addressed is that should concurrent test method run
>> >> > setUp/tearDown multiple times or single time?
>> >> > I'm not 100% sure when I designed ConcurrentRunner. For your case, it
>> >> > looks
>> >> > like that you prefer multiple option. Do I understand correctly?
>> Thanks!
>> >> >
>> >> >
>> >> >
>> >> >>
>> >> >>
>> >> >> Chris
>> >> >>
>> >> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
>> >> >> > Hi Chris,
>> >> >> >
>> >> >> > In original code of AbstractMethodRunner#run, it invokes setup as
>> >> >> > well:
>> >> >> >
>> >> >> > init(testInstance, method, params);
>> >> >> > setUpBeforeWatchers(params); // setup will be run
>> >> >> > here.
>> >> >> > startWatchers(testInstance, method, params);
>> >> >> > setUpAfterWatchers(params);
>> >> >> > startToStopThread();
>> >> >> > runImpl();
>> >> >> > stopToStopThread();
>> >> >> > runCheckMethod(testInstance, params);
>> >> >> >
>> >> >> > Will your modification cause multiple run of setUp & tearDown?
>> >> >> > Thanks!
>> >> >> >
>> >> >> > On Tue, Jun 10, 2008 at 4:22 PM, <cu...@us...>
>> >> >> > wrote:
>> >> >> >>
>> >> >> >> 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.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> -------------------------------------------------------------------------
>> >> >> >> Check out the new SourceForge.net Marketplace.
>> >> >> >> It's the best place to buy or sell services for
>> >> >> >> just about anything Open Source.
>> >> >> >> http://sourceforge.net/services/buy/index.php
>> >> >> >> _______________________________________________
>> >> >> >> P-unit-devel mailing list
>> >> >> >> P-u...@li...
>> >> >> >> https://lists.sourceforge.net/lists/listinfo/p-unit-devel
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > Best regards,
>> >> >> > Andrew Zhang
>> >> >> >
>> >> >> > db4o - database for Android: www.db4o.com
>> >> >> > http://zhanghuangzhu.blogspot.com/
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Best regards,
>> >> > Andrew Zhang
>> >> >
>> >> > db4o - database for Android: www.db4o.com
>> >> > http://zhanghuangzhu.blogspot.com/
>> >
>> >
>> >
>> > --
>> > Best regards,
>> > Andrew Zhang
>> >
>> > db4o - database for Android: www.db4o.com
>> > http://zhanghuangzhu.blogspot.com/
>>
>
>
>
> --
> Best regards,
> Andrew Zhang
>
> db4o - database for Android: www.db4o.com
> http://zhanghuangzhu.blogspot.com/
>
--
Best regards,
Andrew Zhang
db4o - database for Android: www.db4o.com
http://zhanghuangzhu.blogspot.com/
|
|
From: Andrew Z. <zha...@gm...> - 2008-06-11 15:35:10
|
On Wed, Jun 11, 2008 at 11:02 PM, Chris Wilson <ch...@cj...> wrote:
> Hi,
>
> I am writing tests that need to run both a unit tests and performance
> tests, so we are writing them so that the operation includes various
> bits of setup in the setUp method. I can see that the instance below
> makes sense to just run the setup once, but likewise your example
> won't work if run as a unit test with junit.
>
> I think just measuring the time to execute the test method would be
> ideal, but depending on the scenario, as long as you know that every
> run is doing the same thing you can extrapolate how long it takes.
> You could, for instance, have an empty test and then the time for that
> would give you a baseline to compaire other tests against (as it will
> be doing all the setUp etc and method and thread initialisation
> stuff).
>
> I would say that if there needs to be a setup method only run once for
> all performace tests either the beforeClass method or a special method
> should be used. I would just expect a setUp or @Before method to run
> before all tests.
>
> If I were to have a class with two tests in it testA and testB, what
> would the run order:
>
> setUp
> testA
> testA
> testA
> tearDown
>
> setUp
> testB
> testB
> testB
> tearDown
Hi Chris,
exactly.
>
>
> or something else?
>
> I guess I could live with this, actually, though it doesn't feel quite
> right, as long as the setUp method is run in the same thread as the
> test method.
For concurrent test case, we usually want to assert concurrent behavior of
the same instance. That's why setUp only runs once.
Otherwise, it doesn't make too much sense to run the test case like below,
because every thread is totally independent of each other.
setUp () { foo = new Foo(); }
test() { operate on foo and assert foo; }
Chris, for your scenario, does concurrent runner verify anything more than
solo runner? Thanks a lot!
>
>
> Chris
>
> 2008/6/11 Andrew Zhang <zha...@gm...>:
> >
> >
> > On Wed, Jun 11, 2008 at 10:25 PM, Chris Wilson <ch...@cj...>
> wrote:
> >>
> >> Hi,
> >>
> >> I agree that the setUp/tearDown should not be timed - I hadn't though
> >> of that in my code. I wasn't massively clear as to what a lot of the
> >> watcher etc code was doing. It does, however, make a lot of sense to
> >> have the setUp/tearDown run once per test run - ie if you run testA
> >> method five times you should run the setUp and TearDown five times
> >> too. That would be the expected behaviour, I would think, as that is
> >> what happens when the tests are run in general.
> >>
> >>
> >> Perhaps what needs to happen is that all the watcher code needs to be
> >> run in the same thread as the test?
> >
> > Hi Chris,
> >
> > My intuition is that multiple setUp/tearDown makes sense for some cases,
> but
> > single run also is reasonable sometimes. :)
> >
> > Take testing ArrayList#add method as an example:
> > setUp: new an ArrayList instance
> > testAdd: list.add(someObject); // run 10 times
> > checkAdd: assert the list size is 10
> >
> > The test makes sure that concurrent invocation on list.add doesn't throw
> any
> > exception, and the result list size is 10.
> > For this example, if ArrayList is replaced with Vector, it may very
> possible
> > fail because Vector#add is not synchronized and may throw some exception
> > during add (I can't remember the exact exception).
> >
> > Would you please explain your scenario a little bit? Thanks!
> >
> > Another point is that which kind of time do we want to measure?
> >
> > setUp -> testAdd 10 times-> checkAdd -> tearDown
> >
> > The original code measures the time/memory to execute testAdd 10 times.
> >
> > What's your idea? Thanks a lot!
> >
> > p.s. sorry, I forget to add p-unit-dev in the receiver list of my last
> mail.
> > Anyway, you have quoted it. :)
> >>
> >>
> >> Chris
> >>
> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
> >> >
> >> >
> >> > On Wed, Jun 11, 2008 at 4:07 PM, Chris Wilson <ch...@cj...>
> >> > wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> No, I removed the reverence to setup in the setUpBeforeWatchers
> method
> >> >> (and tearDown in the setUpAfterWatchers too). The logic part of it
> is
> >> >> done by the doNormalSetupAndTeardown method and then based on that
> >> >> it'll run them or not.
> >> >
> >> > Hi Chris,
> >> >
> >> > SetUp/tearDown method is usually considered as preparation/cleanup of
> a
> >> > test
> >> > case so that p-unit only measures the execution time and memory of
> test
> >> > method instead of test method + setUp/tearDown.
> >> >
> >> > setUpBeforeWatchers(params);
> >> > startWatchers(testInstance, method, params); // begin to measure
> >> > setUpAfterWatchers(params);
> >> > startToStopThread();
> >> > runImpl();
> >> > stopToStopThread();
> >> >
> >> > Another point you addressed is that should concurrent test method run
> >> > setUp/tearDown multiple times or single time?
> >> > I'm not 100% sure when I designed ConcurrentRunner. For your case, it
> >> > looks
> >> > like that you prefer multiple option. Do I understand correctly?
> Thanks!
> >> >
> >> >
> >> >
> >> >>
> >> >>
> >> >> Chris
> >> >>
> >> >> 2008/6/11 Andrew Zhang <zha...@gm...>:
> >> >> > Hi Chris,
> >> >> >
> >> >> > In original code of AbstractMethodRunner#run, it invokes setup as
> >> >> > well:
> >> >> >
> >> >> > init(testInstance, method, params);
> >> >> > setUpBeforeWatchers(params); // setup will be run
> >> >> > here.
> >> >> > startWatchers(testInstance, method, params);
> >> >> > setUpAfterWatchers(params);
> >> >> > startToStopThread();
> >> >> > runImpl();
> >> >> > stopToStopThread();
> >> >> > runCheckMethod(testInstance, params);
> >> >> >
> >> >> > Will your modification cause multiple run of setUp & tearDown?
> >> >> > Thanks!
> >> >> >
> >> >> > On Tue, Jun 10, 2008 at 4:22 PM, <cu...@us...>
> >> >> > wrote:
> >> >> >>
> >> >> >> 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.
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >>
> -------------------------------------------------------------------------
> >> >> >> Check out the new SourceForge.net Marketplace.
> >> >> >> It's the best place to buy or sell services for
> >> >> >> just about anything Open Source.
> >> >> >> http://sourceforge.net/services/buy/index.php
> >> >> >> _______________________________________________
> >> >> >> P-unit-devel mailing list
> >> >> >> P-u...@li...
> >> >> >> https://lists.sourceforge.net/lists/listinfo/p-unit-devel
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > Best regards,
> >> >> > Andrew Zhang
> >> >> >
> >> >> > db4o - database for Android: www.db4o.com
> >> >> > http://zhanghuangzhu.blogspot.com/
> >> >
> >> >
> >> >
> >> > --
> >> > Best regards,
> >> > Andrew Zhang
> >> >
> >> > db4o - database for Android: www.db4o.com
> >> > http://zhanghuangzhu.blogspot.com/
> >
> >
> >
> > --
> > Best regards,
> > Andrew Zhang
> >
> > db4o - database for Android: www.db4o.com
> > http://zhanghuangzhu.blogspot.com/
>
--
Best regards,
Andrew Zhang
db4o - database for Android: www.db4o.com
http://zhanghuangzhu.blogspot.com/
|
|
From: Chris W. <ch...@cj...> - 2008-06-11 15:02:33
|
Hi, I am writing tests that need to run both a unit tests and performance tests, so we are writing them so that the operation includes various bits of setup in the setUp method. I can see that the instance below makes sense to just run the setup once, but likewise your example won't work if run as a unit test with junit. I think just measuring the time to execute the test method would be ideal, but depending on the scenario, as long as you know that every run is doing the same thing you can extrapolate how long it takes. You could, for instance, have an empty test and then the time for that would give you a baseline to compaire other tests against (as it will be doing all the setUp etc and method and thread initialisation stuff). I would say that if there needs to be a setup method only run once for all performace tests either the beforeClass method or a special method should be used. I would just expect a setUp or @Before method to run before all tests. If I were to have a class with two tests in it testA and testB, what would the run order: setUp testA testA testA tearDown setUp testB testB testB tearDown or something else? I guess I could live with this, actually, though it doesn't feel quite right, as long as the setUp method is run in the same thread as the test method. Chris 2008/6/11 Andrew Zhang <zha...@gm...>: > > > On Wed, Jun 11, 2008 at 10:25 PM, Chris Wilson <ch...@cj...> wrote: >> >> Hi, >> >> I agree that the setUp/tearDown should not be timed - I hadn't though >> of that in my code. I wasn't massively clear as to what a lot of the >> watcher etc code was doing. It does, however, make a lot of sense to >> have the setUp/tearDown run once per test run - ie if you run testA >> method five times you should run the setUp and TearDown five times >> too. That would be the expected behaviour, I would think, as that is >> what happens when the tests are run in general. >> >> >> Perhaps what needs to happen is that all the watcher code needs to be >> run in the same thread as the test? > > Hi Chris, > > My intuition is that multiple setUp/tearDown makes sense for some cases, but > single run also is reasonable sometimes. :) > > Take testing ArrayList#add method as an example: > setUp: new an ArrayList instance > testAdd: list.add(someObject); // run 10 times > checkAdd: assert the list size is 10 > > The test makes sure that concurrent invocation on list.add doesn't throw any > exception, and the result list size is 10. > For this example, if ArrayList is replaced with Vector, it may very possible > fail because Vector#add is not synchronized and may throw some exception > during add (I can't remember the exact exception). > > Would you please explain your scenario a little bit? Thanks! > > Another point is that which kind of time do we want to measure? > > setUp -> testAdd 10 times-> checkAdd -> tearDown > > The original code measures the time/memory to execute testAdd 10 times. > > What's your idea? Thanks a lot! > > p.s. sorry, I forget to add p-unit-dev in the receiver list of my last mail. > Anyway, you have quoted it. :) >> >> >> Chris >> >> 2008/6/11 Andrew Zhang <zha...@gm...>: >> > >> > >> > On Wed, Jun 11, 2008 at 4:07 PM, Chris Wilson <ch...@cj...> >> > wrote: >> >> >> >> Hi, >> >> >> >> No, I removed the reverence to setup in the setUpBeforeWatchers method >> >> (and tearDown in the setUpAfterWatchers too). The logic part of it is >> >> done by the doNormalSetupAndTeardown method and then based on that >> >> it'll run them or not. >> > >> > Hi Chris, >> > >> > SetUp/tearDown method is usually considered as preparation/cleanup of a >> > test >> > case so that p-unit only measures the execution time and memory of test >> > method instead of test method + setUp/tearDown. >> > >> > setUpBeforeWatchers(params); >> > startWatchers(testInstance, method, params); // begin to measure >> > setUpAfterWatchers(params); >> > startToStopThread(); >> > runImpl(); >> > stopToStopThread(); >> > >> > Another point you addressed is that should concurrent test method run >> > setUp/tearDown multiple times or single time? >> > I'm not 100% sure when I designed ConcurrentRunner. For your case, it >> > looks >> > like that you prefer multiple option. Do I understand correctly? Thanks! >> > >> > >> > >> >> >> >> >> >> Chris >> >> >> >> 2008/6/11 Andrew Zhang <zha...@gm...>: >> >> > Hi Chris, >> >> > >> >> > In original code of AbstractMethodRunner#run, it invokes setup as >> >> > well: >> >> > >> >> > init(testInstance, method, params); >> >> > setUpBeforeWatchers(params); // setup will be run >> >> > here. >> >> > startWatchers(testInstance, method, params); >> >> > setUpAfterWatchers(params); >> >> > startToStopThread(); >> >> > runImpl(); >> >> > stopToStopThread(); >> >> > runCheckMethod(testInstance, params); >> >> > >> >> > Will your modification cause multiple run of setUp & tearDown? >> >> > Thanks! >> >> > >> >> > On Tue, Jun 10, 2008 at 4:22 PM, <cu...@us...> >> >> > wrote: >> >> >> >> >> >> 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. >> >> >> >> >> >> >> >> >> >> >> >> ------------------------------------------------------------------------- >> >> >> Check out the new SourceForge.net Marketplace. >> >> >> It's the best place to buy or sell services for >> >> >> just about anything Open Source. >> >> >> http://sourceforge.net/services/buy/index.php >> >> >> _______________________________________________ >> >> >> P-unit-devel mailing list >> >> >> P-u...@li... >> >> >> https://lists.sourceforge.net/lists/listinfo/p-unit-devel >> >> > >> >> > >> >> > >> >> > -- >> >> > Best regards, >> >> > Andrew Zhang >> >> > >> >> > db4o - database for Android: www.db4o.com >> >> > http://zhanghuangzhu.blogspot.com/ >> > >> > >> > >> > -- >> > Best regards, >> > Andrew Zhang >> > >> > db4o - database for Android: www.db4o.com >> > http://zhanghuangzhu.blogspot.com/ > > > > -- > Best regards, > Andrew Zhang > > db4o - database for Android: www.db4o.com > http://zhanghuangzhu.blogspot.com/ |
|
From: Andrew Z. <zha...@gm...> - 2008-06-11 14:49:04
|
On Wed, Jun 11, 2008 at 10:25 PM, Chris Wilson <ch...@cj...> wrote: > Hi, > > I agree that the setUp/tearDown should not be timed - I hadn't though > of that in my code. I wasn't massively clear as to what a lot of the > watcher etc code was doing. It does, however, make a lot of sense to > have the setUp/tearDown run once per test run - ie if you run testA > method five times you should run the setUp and TearDown five times > too. That would be the expected behaviour, I would think, as that is > what happens when the tests are run in general. > > > Perhaps what needs to happen is that all the watcher code needs to be > run in the same thread as the test? Hi Chris, My intuition is that multiple setUp/tearDown makes sense for some cases, but single run also is reasonable sometimes. :) Take testing ArrayList#add method as an example: setUp: new an ArrayList instance testAdd: list.add(someObject); // run 10 times checkAdd: assert the list size is 10 The test makes sure that concurrent invocation on list.add doesn't throw any exception, and the result list size is 10. For this example, if ArrayList is replaced with Vector, it may very possible fail because Vector#add is not synchronized and may throw some exception during add (I can't remember the exact exception). Would you please explain your scenario a little bit? Thanks! Another point is that which kind of time do we want to measure? setUp -> testAdd 10 times-> checkAdd -> tearDown The original code measures the time/memory to execute testAdd 10 times. What's your idea? Thanks a lot! p.s. sorry, I forget to add p-unit-dev in the receiver list of my last mail. Anyway, you have quoted it. :) > > > Chris > > 2008/6/11 Andrew Zhang <zha...@gm...>: > > > > > > On Wed, Jun 11, 2008 at 4:07 PM, Chris Wilson <ch...@cj...> > wrote: > >> > >> Hi, > >> > >> No, I removed the reverence to setup in the setUpBeforeWatchers method > >> (and tearDown in the setUpAfterWatchers too). The logic part of it is > >> done by the doNormalSetupAndTeardown method and then based on that > >> it'll run them or not. > > > > Hi Chris, > > > > SetUp/tearDown method is usually considered as preparation/cleanup of a > test > > case so that p-unit only measures the execution time and memory of test > > method instead of test method + setUp/tearDown. > > > > setUpBeforeWatchers(params); > > startWatchers(testInstance, method, params); // begin to measure > > setUpAfterWatchers(params); > > startToStopThread(); > > runImpl(); > > stopToStopThread(); > > > > Another point you addressed is that should concurrent test method run > > setUp/tearDown multiple times or single time? > > I'm not 100% sure when I designed ConcurrentRunner. For your case, it > looks > > like that you prefer multiple option. Do I understand correctly? Thanks! > > > > > > > >> > >> > >> Chris > >> > >> 2008/6/11 Andrew Zhang <zha...@gm...>: > >> > Hi Chris, > >> > > >> > In original code of AbstractMethodRunner#run, it invokes setup as > well: > >> > > >> > init(testInstance, method, params); > >> > setUpBeforeWatchers(params); // setup will be run > here. > >> > startWatchers(testInstance, method, params); > >> > setUpAfterWatchers(params); > >> > startToStopThread(); > >> > runImpl(); > >> > stopToStopThread(); > >> > runCheckMethod(testInstance, params); > >> > > >> > Will your modification cause multiple run of setUp & tearDown? Thanks! > >> > > >> > On Tue, Jun 10, 2008 at 4:22 PM, <cu...@us...> > wrote: > >> >> > >> >> 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. > >> >> > >> >> > >> >> > ------------------------------------------------------------------------- > >> >> Check out the new SourceForge.net Marketplace. > >> >> It's the best place to buy or sell services for > >> >> just about anything Open Source. > >> >> http://sourceforge.net/services/buy/index.php > >> >> _______________________________________________ > >> >> P-unit-devel mailing list > >> >> P-u...@li... > >> >> https://lists.sourceforge.net/lists/listinfo/p-unit-devel > >> > > >> > > >> > > >> > -- > >> > Best regards, > >> > Andrew Zhang > >> > > >> > db4o - database for Android: www.db4o.com > >> > http://zhanghuangzhu.blogspot.com/ > > > > > > > > -- > > Best regards, > > Andrew Zhang > > > > db4o - database for Android: www.db4o.com > > http://zhanghuangzhu.blogspot.com/ > -- Best regards, Andrew Zhang db4o - database for Android: www.db4o.com http://zhanghuangzhu.blogspot.com/ |
|
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.
|
|
From: <cu...@us...> - 2008-06-10 08:22:49
|
Revision: 317
http://p-unit.svn.sourceforge.net/p-unit/?rev=317&view=rev
Author: cuvavu
Date: 2008-06-10 01:22:52 -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.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
Added Paths:
-----------
trunk/punit.test/src/tests/api/org/punit/testclasses/BeforeAndAfterConcurrentTestClass.java
Modified: trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-05-28 12:46:18 UTC (rev 316)
+++ trunk/punit.test/src/tests/api/org/punit/method/runner/AbstractMethodRunnerTest.java 2008-06-10 08:22:52 UTC (rev 317)
@@ -67,7 +67,7 @@
public void testRun_MultipleExceptions() {
resetRunFlag();
_methodRunner.run(new TestMultiException(), getMethod(TestMultiException.class, "test"), new Object[] {});
- Assert.assertEquals(NullPointerException.class, _mockEvenListener.throwable);
+ Assert.assertEquals(IllegalStateException.class, _mockEvenListener.throwable);
}
private void resetRunFlag() {
@@ -109,9 +109,18 @@
private static class MockMethodRunner extends AbstractMethodRunner {
public boolean isInvoked;
- protected void runImpl() throws Throwable {
+ protected void runImpl( boolean doNormalSetupAndTeardown ) throws Throwable {
isInvoked = true;
- super.runMethod();
+ try {
+ if (doNormalSetupAndTeardown) {
+ setUp();
+ }
+ super.runMethod();
+ } finally {
+ if (doNormalSetupAndTeardown) {
+ tearDown();
+ }
+ }
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2008-05-28 12:46:18 UTC (rev 316)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentRunnerTest.java 2008-06-10 08:22:52 UTC (rev 317)
@@ -9,9 +9,11 @@
import org.punit.convention.AnnotationConvention;
import org.punit.events.*;
import org.punit.runner.ConcurrentRunner;
+import org.punit.runner.ExecutorPoolImpl;
import org.punit.runner.SoloRunner;
import tests.api.org.punit.testclasses.AnnotationTestClass;
+import tests.api.org.punit.testclasses.BeforeAndAfterConcurrentTestClass;
import tests.api.org.punit.testclasses.ConcurrentParameterizedTestClass;
import tests.api.org.punit.testclasses.ConcurrentTestClass;
import tests.api.org.punit.testclasses.LoopTestClass;
@@ -31,70 +33,81 @@
public void setUp() {
_runner = new ConcurrentRunner();
}
- public void testMain() {
- ConcurrentRunner.main(new String[] { TestSuiteClass.class.getName() });
- }
-
- public void testRun() {
- _runner.run(TestSuiteClass.class);
- }
-
- public void testRunLoopTest() {
- LoopTestClass.reset();
- _runner.run(LoopTestClass.class);
- LoopTestClass.assertTestClassRun();
- }
-
- public void testRunConcurrent() {
- ConcurrentTestClass.reset();
- _runner.run(ConcurrentTestClass.class);
- assertConcurrentTestClassRun();
- }
-
- public void testRunTest() {
- TestClass0.reset();
- _runner.run(TestClass0.class);
- TestClass0.assertTestClassRun();
- }
-
- public void testRunAnnotationTest() {
- AnnotationTestClass.reset();
+// public void testMain() {
+// ConcurrentRunner.main(new String[] { TestSuiteClass.class.getName() });
+// }
+//
+// public void testRun() {
+// _runner.run(TestSuiteClass.class);
+// }
+//
+// public void testRunLoopTest() {
+// LoopTestClass.reset();
+// _runner.run(LoopTestClass.class);
+// LoopTestClass.assertTestClassRun();
+// }
+//
+// public void testRunConcurrent() {
+// ConcurrentTestClass.reset();
+// _runner.run(ConcurrentTestClass.class);
+// assertConcurrentTestClassRun();
+// }
+//
+// public void testRunTest() {
+// TestClass0.reset();
+// _runner.run(TestClass0.class);
+// TestClass0.assertTestClassRun();
+// }
+//
+// public void testRunAnnotationTest() {
+// AnnotationTestClass.reset();
+// _runner.setConvention(new AnnotationConvention());
+// _runner.run(AnnotationTestClass.class);
+// AnnotationTestClass.assertTestClassRun();
+// }
+//
+// public void testRunPUnitTest() {
+// TestClass3.reset();
+// _runner.run(TestClass3.class);
+// TestClass3.assertTestClassRun();
+// }
+//
+// public void testRunParameterized() throws Exception {
+// ConcurrentParameterizedTestClass.reset();
+// _runner.run(ConcurrentParameterizedTestClass.class);
+// ConcurrentParameterizedTestClass.assertTestClassRun();
+// }
+//
+// public void testRunTestSuite() {
+// ConcurrentTestClass.reset();
+// TestClass0.reset();
+// TestClass3.reset();
+// _runner.run(TestSuiteClass.class);
+// assertConcurrentTestClassRun();
+// TestClass0.assertTestClassRun();
+// TestClass3.assertTestClassRun();
+// }
+//
+// public void testSerializable() throws Exception {
+// _runner.addEventListener(new MockEventListener());
+// List<EventListener> expectedListeners = _runner.eventListeners();
+// ConcurrentRunner runner = (ConcurrentRunner) TestUtil
+// .getSerialiableObject(_runner);
+// List<EventListener> eventListeners = runner.eventListeners();
+// assertEquals(expectedListeners.size(), eventListeners.size());
+// }
+
+ /**
+ * Test to check that the before and after methods run in the same thread as the methods
+ */
+ public void testBeforeAndAfterThreads() throws Exception {
+ _runner = new ConcurrentRunner(1);
+// _runner.setExecutorPool(new ExecutorPoolImpl(2));
_runner.setConvention(new AnnotationConvention());
- _runner.run(AnnotationTestClass.class);
- AnnotationTestClass.assertTestClassRun();
+ _runner.run(BeforeAndAfterConcurrentTestClass.class);
+ assertEquals(_runner.testResult().failures().size(), 0);
}
- public void testRunPUnitTest() {
- TestClass3.reset();
- _runner.run(TestClass3.class);
- TestClass3.assertTestClassRun();
- }
-
- public void testRunParameterized() throws Exception {
- ConcurrentParameterizedTestClass.reset();
- _runner.run(ConcurrentParameterizedTestClass.class);
- ConcurrentParameterizedTestClass.assertTestClassRun();
- }
-
- public void testRunTestSuite() {
- ConcurrentTestClass.reset();
- TestClass0.reset();
- TestClass3.reset();
- _runner.run(TestSuiteClass.class);
- assertConcurrentTestClassRun();
- TestClass0.assertTestClassRun();
- TestClass3.assertTestClassRun();
- }
-
- public void testSerializable() throws Exception {
- _runner.addEventListener(new MockEventListener());
- List<EventListener> expectedListeners = _runner.eventListeners();
- ConcurrentRunner runner = (ConcurrentRunner) TestUtil
- .getSerialiableObject(_runner);
- List<EventListener> eventListeners = runner.eventListeners();
- assertEquals(expectedListeners.size(), eventListeners.size());
- }
-
private void assertConcurrentTestClassRun() {
ConcurrentTestClass test = new ConcurrentTestClass();
assertEquals(test.concurrentCount(), ConcurrentTestClass.value);
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/BeforeAndAfterConcurrentTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/BeforeAndAfterConcurrentTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/BeforeAndAfterConcurrentTestClass.java 2008-06-10 08:22:52 UTC (rev 317)
@@ -0,0 +1,32 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.annotation.After;
+import org.punit.annotation.Before;
+import org.punit.annotation.Test;
+
+import static junit.framework.Assert.*;
+
+import tests.util.*;
+
+public class BeforeAndAfterConcurrentTestClass {
+
+ private int value1 = 0;
+
+ @Before
+ public void before() {
+ value1 = 5;
+ }
+
+ @Test
+ public synchronized void one() {
+ TestUtil.doSomething();
+ value1 += 5;
+ assertEquals(10, value1);
+ }
+
+ @After
+ public void after() {
+ value1 += 5;
+ assertEquals(15, value1);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Chris W. <ch...@cj...> - 2008-06-09 16:21:58
|
Hi, The setup and teardown methods are currently executed, when using the concurrent runner, in the main control thread rather than in the test's individual threads. This strikes me as incorrect, and has caused me some problems. So I have fixed it. The code is ready to commit, I just wanted clarification that this was OK. All the tests pass, though I had to make one small change to the testRun_MultipleExceptions method of AbstractMethodRunner as the code should enforce the teardown methods to be run even if the test fails. If this sounds reasonable then I'll commit this tomorrow. Chris |
|
From: Andrew Z. <zha...@gm...> - 2008-05-29 11:41:26
|
On Thu, May 29, 2008 at 4:08 PM, Chris Wilson <ch...@cj...> wrote: > Hi, > > In JUnit 4 you can have several methods @before and @after (though not > @beforeclass or @afterclass). This is the advantage of annotations. > See: > > http://www.devx.com/Java/Article/31983/0/page/3 > I see, thanks! > <http://www.devx.com/Java/Article/31983/0/page/3> > > Cheers, > > Chris > > 2008/5/29 Andrew Zhang <zha...@gm...>: > > Hi Chris, > > > > I have a question about "allowMultiple" parameter. Why does > setUp/tearDown > > allow multiple? One class can only have one setUp/tearDown method? Or > it's > > JUnit4 convention? Thanks! > > > > Best regards, > > Andrew Zhang > > > -- Best regards, Andrew Zhang db4o - database for Android: www.db4o.com http://zhanghuangzhu.blogspot.com/ |
|
From: Chris W. <ch...@cj...> - 2008-05-29 08:08:47
|
Hi, In JUnit 4 you can have several methods @before and @after (though not @beforeclass or @afterclass). This is the advantage of annotations. See: http://www.devx.com/Java/Article/31983/0/page/3 Cheers, Chris 2008/5/29 Andrew Zhang <zha...@gm...>: > Hi Chris, > > I have a question about "allowMultiple" parameter. Why does setUp/tearDown > allow multiple? One class can only have one setUp/tearDown method? Or it's > JUnit4 convention? Thanks! > > Best regards, > Andrew Zhang > |
|
From: Andrew Z. <zha...@gm...> - 2008-05-29 01:33:25
|
Hi Chris, I have a question about "allowMultiple" parameter. Why does setUp/tearDown allow multiple? One class can only have one setUp/tearDown method? Or it's JUnit4 convention? Thanks! Best regards, Andrew Zhang |
|
From: <cu...@us...> - 2008-05-28 12:46:11
|
Revision: 316
http://p-unit.svn.sourceforge.net/p-unit/?rev=316&view=rev
Author: cuvavu
Date: 2008-05-28 05:46:18 -0700 (Wed, 28 May 2008)
Log Message:
-----------
Cleaning up source tree
Property Changed:
----------------
trunk/punit.extension/
Property changes on: trunk/punit.extension
___________________________________________________________________
Name: svn:ignore
+ *.jar
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cu...@us...> - 2008-05-28 12:46:02
|
Revision: 315
http://p-unit.svn.sourceforge.net/p-unit/?rev=315&view=rev
Author: cuvavu
Date: 2008-05-28 05:46:10 -0700 (Wed, 28 May 2008)
Log Message:
-----------
Cleaning up source tree
Property Changed:
----------------
trunk/punit/
Property changes on: trunk/punit
___________________________________________________________________
Name: svn:ignore
+ *.jar
bin
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cu...@us...> - 2008-05-28 12:38:44
|
Revision: 314
http://p-unit.svn.sourceforge.net/p-unit/?rev=314&view=rev
Author: cuvavu
Date: 2008-05-28 05:38:52 -0700 (Wed, 28 May 2008)
Log Message:
-----------
Clarifying comments
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/AnnotationConvention.java
Modified: trunk/punit/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-05-28 11:17:54 UTC (rev 313)
+++ trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-05-28 12:38:52 UTC (rev 314)
@@ -152,7 +152,7 @@
* @param annotationOnly Check for old-style name based methods?
* @param annotation Annotation to look for
* @param delegateMethod Method to use when looking for alternatives name-based methods
- * @param before Is this method an "after" method (or a before)?
+ * @param after Is this method an "after" method (or a before)?
* @param allowMultiple Allow multiple tests?
* @return
*/
@@ -184,7 +184,7 @@
}
}
- // Do we want the superclass code to be before or after the current code?
+ // Is this method an "after" method (or before)? If its after we want this class's code to be before the superclass's (or vice-versa).
List<Method> methodsList = new ArrayList<Method>();
if (after) {
if (annotatedMethods != null && annotatedMethods.length > 0) methodsList.add(annotatedMethods[0]);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2008-05-28 11:17:47
|
Revision: 313
http://p-unit.svn.sourceforge.net/p-unit/?rev=313&view=rev
Author: zhanghuangzhu
Date: 2008-05-28 04:17:54 -0700 (Wed, 28 May 2008)
Log Message:
-----------
andrew zhang: should be annotation == false.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/AnnotationConvention.java
Modified: trunk/punit/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-05-28 09:34:47 UTC (rev 312)
+++ trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-05-28 11:17:54 UTC (rev 313)
@@ -172,7 +172,7 @@
Method[] superMethods = getClassAnnotationMethod(test.getSuperclass(), true, annotation, delegateMethod, after, allowMultiple);
// Look for un-anotated method in this class if there has been no annotated methods in superclass
- if (annotationOnly = false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
+ if (annotationOnly == false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
try {
return (Method[])delegateMethod.invoke(_delegate, test);
} catch (IllegalArgumentException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cu...@us...> - 2008-05-28 09:34:40
|
Revision: 312
http://p-unit.svn.sourceforge.net/p-unit/?rev=312&view=rev
Author: cuvavu
Date: 2008-05-28 02:34:47 -0700 (Wed, 28 May 2008)
Log Message:
-----------
Adding in a general method for dealing with before and after annotations. This is a bit bulky.
Modified Paths:
--------------
trunk/punit/src/org/punit/convention/AnnotationConvention.java
trunk/punit/src/org/punit/exception/AnnotationException.java
Modified: trunk/punit/src/org/punit/convention/AnnotationConvention.java
===================================================================
--- trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-05-28 00:44:46 UTC (rev 311)
+++ trunk/punit/src/org/punit/convention/AnnotationConvention.java 2008-05-28 09:34:47 UTC (rev 312)
@@ -3,6 +3,7 @@
package org.punit.convention;
import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -101,109 +102,98 @@
@SuppressWarnings("unchecked")
public Method[] getAfterClassMethod(Class test) {
- return getAfterClassMethod(test, false);
+ try {
+ return getClassAnnotationMethod(test, false, _afterClass, _delegate.getClass().getMethod("getAfterClassMethod", Class.class), true, false);
+ } catch (SecurityException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ } catch (NoSuchMethodException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ }
}
- @SuppressWarnings("unchecked")
- private Method[] getAfterClassMethod(Class test, boolean annotationOnly) {
- if (test == null) return new Method[0];
-
- Method[] annotatedMethods = AnnotationUtil.getMethodsByAnnotation(test, _afterClass);
- if (annotatedMethods != null && annotatedMethods.length > 1) throw new AnnotationException( "Too many @AfterClass annotations - only one allowed per class" );
-
- // Get the AfterClass methods from the superclasses (if any) - only look at annotations, though
- Method[] superMethods = getAfterClassMethod(test.getSuperclass(), true);
-
- // Look for un-anotated method in this class if there has been no annotated methods in superclass
- if (annotationOnly = false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
- return _delegate.getAfterClassMethod(test);
- }
-
- // This classes method needs to be on the list before its superclasses
- List<Method> methodsList = new ArrayList<Method>();
- if (annotatedMethods != null && annotatedMethods.length > 0) methodsList.add(annotatedMethods[0]);
- if (superMethods != null) methodsList.addAll(Arrays.asList(superMethods));
-
- return methodsList.size() == 0 ? null : methodsList.toArray(new Method[0]);
- }
@SuppressWarnings("unchecked")
public Method[] getBeforeClassMethod(Class test) {
- return getBeforeClassMethod(test, false);
+ try {
+ return getClassAnnotationMethod(test, false, _beforeClass, _delegate.getClass().getMethod("getBeforeClassMethod", Class.class), false, false);
+ } catch (SecurityException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ } catch (NoSuchMethodException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ }
}
- @SuppressWarnings("unchecked")
- private Method[] getBeforeClassMethod(Class test, boolean annotationOnly) {
- if (test == null) return new Method[0];
-
- Method[] annotatedMethods = AnnotationUtil
- .getMethodsByAnnotation(test, _beforeClass);
- if (annotatedMethods != null && annotatedMethods.length > 1) throw new AnnotationException( "Too many @BeforeClass annotations - only one allowed per class" );
- // Get the BeforeClass methods from the superclasses (if any) - only look at annotations, though
- Method[] superMethods = getBeforeClassMethod(test.getSuperclass(), true);
-
- // Look for un-anotated method in this class if there has been no annotated methods in superclass
- if (annotationOnly = false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
- return _delegate.getBeforeClassMethod(test);
- }
-
- // This classes method needs to be on the list after its superclasses
- List<Method> methodsList = new ArrayList<Method>();
- if (superMethods != null) methodsList.addAll(Arrays.asList(superMethods));
- if (annotatedMethods != null && annotatedMethods.length > 0) methodsList.add(annotatedMethods[0]);
-
- return methodsList.size() == 0 ? null : methodsList.toArray(new Method[0]);
- }
-
@SuppressWarnings("unchecked")
public Method[] getSetUpMethod(Class test) {
- return getSetUpMethod(test, false);
+ try {
+ return getClassAnnotationMethod(test, false, _before, _delegate.getClass().getMethod("getSetUpMethod", Class.class), false, true);
+ } catch (SecurityException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ } catch (NoSuchMethodException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ }
}
- @SuppressWarnings("unchecked")
- private Method[] getSetUpMethod(Class test, boolean annotationOnly) {
- if (test == null) return new Method[0];
-
- Method[] annotatedMethods = AnnotationUtil.getMethodsByAnnotation(test, _before);
-
- // Get the Before methods from the superclasses (if any)
- Method[] superMethods = getSetUpMethod(test.getSuperclass(), true);
-
- // Look for un-anotated method in this class if there has been no annotated methods in superclass
- if (annotationOnly = false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
- return _delegate.getSetUpMethod(test);
- }
-
- // This classes method needs to be on the list after its superclasses
- List<Method> methodsList = new ArrayList<Method>();
- if (superMethods != null) methodsList.addAll(Arrays.asList(superMethods));
- if (annotatedMethods != null) methodsList.addAll(Arrays.asList(annotatedMethods));
-
- return methodsList.size() == 0 ? null : methodsList.toArray(new Method[0]);
- }
@SuppressWarnings("unchecked")
public Method[] getTearDownMethod(Class test) {
- return getTearDownMethod(test, false);
+ try {
+ return getClassAnnotationMethod(test, false, _after, _delegate.getClass().getMethod("getTearDownMethod", Class.class), true, true);
+ } catch (SecurityException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ } catch (NoSuchMethodException e) {
+ throw new AnnotationException( "Problem finding method", e );
+ }
}
+
+ /**
+ * Method to get, recursively, annotated methods from superclasses. This is a bit of a beast because
+ * it needs to account for for slightly different ways of doing things.
+ *
+ * @param test Class to test
+ * @param annotationOnly Check for old-style name based methods?
+ * @param annotation Annotation to look for
+ * @param delegateMethod Method to use when looking for alternatives name-based methods
+ * @param before Is this method an "after" method (or a before)?
+ * @param allowMultiple Allow multiple tests?
+ * @return
+ */
@SuppressWarnings("unchecked")
- private Method[] getTearDownMethod(Class test, boolean annotationOnly) {
+ private Method[] getClassAnnotationMethod(Class test,
+ boolean annotationOnly,
+ Class<? extends Annotation> annotation,
+ Method delegateMethod,
+ boolean after,
+ boolean allowMultiple) {
if (test == null) return new Method[0];
- Method[] annotatedMethods = AnnotationUtil.getMethodsByAnnotation(test, _after);
+ Method[] annotatedMethods = AnnotationUtil.getMethodsByAnnotation(test, annotation);
+ if (!allowMultiple && annotatedMethods != null && annotatedMethods.length > 1) throw new AnnotationException( "Too many " + annotation.getCanonicalName() + "annotations - only one allowed per class" );
- // Get the After methods from the superclasses (if any)
- Method[] superMethods = getTearDownMethod(test.getSuperclass(), true);
+ // Get the annotated methods from the superclasses (if any) - only look at annotations, though
+ Method[] superMethods = getClassAnnotationMethod(test.getSuperclass(), true, annotation, delegateMethod, after, allowMultiple);
// Look for un-anotated method in this class if there has been no annotated methods in superclass
- if (annotationOnly = false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
- return _delegate.getTearDownMethod(test);
+ if (annotationOnly = false && (annotatedMethods == null || annotatedMethods.length == 0) && (superMethods == null || superMethods.length==0)) {
+ try {
+ return (Method[])delegateMethod.invoke(_delegate, test);
+ } catch (IllegalArgumentException e) {
+ throw new AnnotationException( "Problem running method", e );
+ } catch (IllegalAccessException e) {
+ throw new AnnotationException( "Problem running method", e );
+ } catch (InvocationTargetException e) {
+ throw new AnnotationException( "Problem running method", e );
+ }
}
- // This classes method needs to be on the list before its superclasses
+ // Do we want the superclass code to be before or after the current code?
List<Method> methodsList = new ArrayList<Method>();
- if (annotatedMethods != null) methodsList.addAll(Arrays.asList(annotatedMethods));
- if (superMethods != null) methodsList.addAll(Arrays.asList(superMethods));
+ if (after) {
+ if (annotatedMethods != null && annotatedMethods.length > 0) methodsList.add(annotatedMethods[0]);
+ if (superMethods != null) methodsList.addAll(Arrays.asList(superMethods));
+ } else {
+ if (superMethods != null) methodsList.addAll(Arrays.asList(superMethods));
+ if (annotatedMethods != null && annotatedMethods.length > 0) methodsList.add(annotatedMethods[0]);
+ }
return methodsList.size() == 0 ? null : methodsList.toArray(new Method[0]);
}
-
-}
+}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/exception/AnnotationException.java
===================================================================
--- trunk/punit/src/org/punit/exception/AnnotationException.java 2008-05-28 00:44:46 UTC (rev 311)
+++ trunk/punit/src/org/punit/exception/AnnotationException.java 2008-05-28 09:34:47 UTC (rev 312)
@@ -7,4 +7,8 @@
public AnnotationException(String message) {
super(message);
}
+
+ public AnnotationException(String message, Throwable t) {
+ super(message, t);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|