[P-unit-devel] SF.net SVN: p-unit: [161] trunk/punit
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <zha...@us...> - 2007-05-27 08:16:41
|
Revision: 161
http://p-unit.svn.sourceforge.net/p-unit/?rev=161&view=rev
Author: zhanghuangzhu
Date: 2007-05-27 01:16:42 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Andrew Zhang: Disabled memory by default. Refactored some method name, and add ExecutionPoolSample.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
Added Paths:
-----------
trunk/punit.samples/src/samples/ExecutorPoolSample.java
trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java
trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
trunk/punit.samples/src/samples/LongTimeExecutionTest1.java
trunk/punit.samples/src/samples/LongTimeExecutionTest2.java
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -23,6 +23,8 @@
protected transient TestResult _result;
public Level _level = Level.FINE;
+
+ private TimeWatcher _timeWatcher;
public StreamLoggerListener() {
}
@@ -33,6 +35,7 @@
}
public void onRunnerStart(Class clazz, Runner runner) {
+ startTimeWatcher();
_result = new TestResult();
StringBuffer sb = new StringBuffer();
sb.append("["); //$NON-NLS-1$
@@ -45,11 +48,17 @@
log(sb.toString(), Level.INFO);
}
+ private void startTimeWatcher() {
+ _timeWatcher = new TimeWatcher();
+ _timeWatcher.start();
+ }
+
public void onRunnerEnd(Class clazz, Runner runner) {
logResult();
}
public void logResult() {
+ stopTimeWatcher();
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
sb.append(_result.methodCount());
@@ -64,7 +73,8 @@
} else {
sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
}
- sb.append(") "); //$NON-NLS-1$
+ sb.append(") - "); //$NON-NLS-1$
+ sb.append(_timeWatcher.stringValue());
sb.append(ReporterUtil.LINE_SEPERATOR);
logErr(sb.toString(), Level.INFO);
TraverserUtil.traverse(failures.iterator(), new Traverser() {
@@ -77,6 +87,10 @@
});
}
+ private void stopTimeWatcher() {
+ _timeWatcher.stop();
+ }
+
public void onSuiteStart(PUnitTestSuite suite) {
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.06")); //$NON-NLS-1$
@@ -105,7 +119,7 @@
final Iterator iter = watchers.iterator();
Watcher watcher = (Watcher) iter.next();
log(" - [" + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
- TraverserUtil.traverse(watchers.iterator(), new Traverser() {
+ TraverserUtil.traverse(iter, new Traverser() {
public void traverse(Object obj) {
Watcher watcher = (Watcher) obj;
log("," + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -290,15 +290,15 @@
return _testMethodBuilder.buildTestMethods(testClass);
}
- public TestMethodBuilder testMethodBuilder() {
+ public TestMethodBuilder methodBuilder() {
return _testMethodBuilder;
}
- public TestMethodRunner testMethodRunner() {
+ public TestMethodRunner methodRunner() {
return _testMethodRunner;
}
- public TestSuiteBuilder testSuiteBuiler() {
+ public TestSuiteBuilder suiteBuiler() {
return _testSuiteBuiler;
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -16,10 +16,10 @@
public RunnerProperties properties();
- public TestMethodBuilder testMethodBuilder();
+ public TestMethodBuilder methodBuilder();
- public TestMethodRunner testMethodRunner();
+ public TestMethodRunner methodRunner();
- public TestSuiteBuilder testSuiteBuiler();
+ public TestSuiteBuilder suiteBuiler();
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -15,8 +15,6 @@
public abstract class AbstractTestMethodRunner implements TestMethodRunner {
protected List _watchers = new ArrayList(); // <Watcher>
-
- private MemoryWatcher _memoryWatcher = new MemoryWatcher();
private TimeWatcher _timeWatcher = new TimeWatcher();
@@ -37,7 +35,6 @@
protected transient Method _setUpMethod;
public AbstractTestMethodRunner() {
- _watchers.add(_memoryWatcher);
_watchers.add(_timeWatcher);
}
@@ -60,11 +57,7 @@
public void removeTimeWatcher() {
_watchers.remove(_timeWatcher);
}
-
- public void removeMemoryWatcher() {
- _watchers.remove(_memoryWatcher);
- }
-
+
public void run(Object testInstance, Method method, Object[] params) {
onMethodStart(method, testInstance, params);
Throwable throwable = null;
Added: trunk/punit.samples/src/samples/ExecutorPoolSample.java
===================================================================
--- trunk/punit.samples/src/samples/ExecutorPoolSample.java (rev 0)
+++ trunk/punit.samples/src/samples/ExecutorPoolSample.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,11 @@
+package samples;
+
+import org.punit.runner.*;
+
+public class ExecutorPoolSample {
+ public static void main(String[] args) {
+ PUnitSoloRunner runner = new PUnitSoloRunner();
+ runner.setExecutorPool(new PUnitExecutorPool(2));
+ runner.run(LongTimeExecutionPUnitTestSuite.class);
+ }
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionJUnitTestSuite.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,22 @@
+package samples;
+
+import junit.framework.*;
+
+public class LongTimeExecutionJUnitTestSuite {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for long time execution"); //$NON-NLS-1$
+ // $JUnit-BEGIN$
+ Class[] testCases = testCases();
+ for (int i = 0; i < testCases.length; ++i) {
+ suite.addTestSuite(testCases[i]);
+ }
+ // $JUnit-END$
+ return suite;
+ }
+
+ public static Class[] testCases() {
+ return new Class[] { LongTimeExecutionTest1.class,
+ LongTimeExecutionTest2.class, };
+ }
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionPUnitTestSuite.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,11 @@
+package samples;
+
+import org.punit.type.*;
+
+public class LongTimeExecutionPUnitTestSuite implements PUnitTestSuite{
+
+ public Class[] suite() {
+ return LongTimeExecutionJUnitTestSuite.testCases();
+ }
+
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionTest1.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionTest1.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionTest1.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,22 @@
+package samples;
+
+import junit.framework.*;
+
+public class LongTimeExecutionTest1 extends TestCase {
+ public void test1() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void test2() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testA() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testB() throws Exception {
+ Thread.sleep(5000);
+ }
+
+}
Added: trunk/punit.samples/src/samples/LongTimeExecutionTest2.java
===================================================================
--- trunk/punit.samples/src/samples/LongTimeExecutionTest2.java (rev 0)
+++ trunk/punit.samples/src/samples/LongTimeExecutionTest2.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -0,0 +1,22 @@
+package samples;
+
+import junit.framework.*;
+
+public class LongTimeExecutionTest2 extends TestCase {
+ public void test1() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void test2() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testA() throws Exception {
+ Thread.sleep(5000);
+ }
+
+ public void testB() throws Exception {
+ Thread.sleep(5000);
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-25 13:36:58 UTC (rev 160)
+++ trunk/punit.test/src/tests/api/org/punit/runner/method/AbstractTestMethodRunnerTest.java 2007-05-27 08:16:42 UTC (rev 161)
@@ -12,16 +12,8 @@
public void testWatchers() {
List watchers = _mockRunner.watchers();
- assertEquals(2, watchers.size()); // time, and memory watchers
+ assertEquals(1, watchers.size()); // time, and memory watchers
- _mockRunner.removeMemoryWatcher();
- watchers = _mockRunner.watchers();
- assertEquals(1, watchers.size());
-
- _mockRunner.removeMemoryWatcher();
- watchers = _mockRunner.watchers();
- assertEquals(1, watchers.size());
-
_mockRunner.removeTimeWatcher();
watchers = _mockRunner.watchers();
assertEquals(0, watchers.size());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|