[P-unit-devel] SF.net SVN: p-unit: [233] trunk/punit
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <le...@us...> - 2007-09-28 17:30:01
|
Revision: 233
http://p-unit.svn.sourceforge.net/p-unit/?rev=233&view=rev
Author: leshik
Date: 2007-09-28 10:29:13 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Simplified memory cleanup utilities, fixed minor formatting issues.
Modified Paths:
--------------
trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
trunk/punit/src/org/punit/util/MemoryUtil.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/watcher/CustomWatcher.java
trunk/punit/src/punit.properties
trunk/punit.samples/src/samples/DoSomethingTestClass.java
trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java
Modified: trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/method/runner/AbstractMethodRunner.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -55,6 +55,7 @@
public AbstractMethodRunner() {
_watchers.add(_timeWatcher);
+ _shouldStop = true;
}
public void setEventListeners(List eventListeners) {
@@ -174,9 +175,6 @@
}
}, toWork);
_shouldStop = false;
- } else {
- _shouldStop = true;
- _toStopThread = null;
}
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLogger.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLogger.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -106,7 +106,7 @@
}
public void onClassStart(Object testInstance) {
- logln(testInstance.getClass().getName(), Level.INFO);
+ // logln(testInstance.getClass().getName(), Level.INFO);
}
public void onClassEnd(Object testInstance, Throwable t) {
Modified: trunk/punit/src/org/punit/util/MemoryUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/MemoryUtil.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/util/MemoryUtil.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -6,63 +6,20 @@
public class MemoryUtil {
private static Runtime _runtime = Runtime.getRuntime();
-
- private static long freeMemory() {
- return _runtime.freeMemory();
- }
-
+
public static long totalMemory() {
return _runtime.totalMemory();
}
public static long usedMemory() {
- clear();
- return totalMemory() - freeMemory();
+ return totalMemory() - _runtime.freeMemory();
}
public static void clear() {
- final int CLEAR_RETRIES = 3;
-
- long free;
-
- // continue while amount of free memory grows
- do {
- free = freeMemory();
- for (int i = 0; i < CLEAR_RETRIES; i++) {
- System.gc();
- System.runFinalization();
- // give a finalization thread a chance to do it's job
- Thread.yield();
- }
- } while (free < freeMemory());
-
+ System.gc();
+ System.runFinalization();
}
-
- /**
- * Allocates objects till OutOfMemoryError is not thrown.
- *
- * @return total memory when virtual pages can be no longer committed
- */
- public static long maxTotalMemory() {
- int size = Integer.MAX_VALUE;
-
- Object[] list = new Object[1];
-
- // decrease the chunk size
- while (size > 0) {
- try {
- while (true) {
- Object[] newElement = new Object[size];
- newElement[0] = list;
- list = newElement;
- }
- } catch (OutOfMemoryError oome) {
- }
- size = size / 2;
- }
- return totalMemory();
- }
-
+
private static final int WILDERNESS_SIZE = 4096;
private static byte[] _wilderness;
@@ -76,8 +33,6 @@
try {
_wilderness = new byte[WILDERNESS_SIZE];
} catch (OutOfMemoryError oome) {
- System.out.println("failed to allocate wilderness");
- Thread.dumpStack();
throw new OutOfMemoryException(oome);
}
}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -51,9 +51,6 @@
* the string value to assign
*/
public static void setField(Object testInstance, Field field, String value) {
- // System.out.println("Field = " + field + ", value = " + value);
- // System.out.println("value = " + Integer.getInteger(value));
-
try {
field.setAccessible(true);
Class fieldClass = field.getType();
Modified: trunk/punit/src/org/punit/watcher/CustomWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/CustomWatcher.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/org/punit/watcher/CustomWatcher.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -18,7 +18,7 @@
private String _name;
- private String _unit;
+ private String _unit;
private transient static MethodRunner _methodRunner;
@@ -77,7 +77,7 @@
}
}
}
-
+
public static boolean shouldStop() {
return _methodRunner.shouldStop();
}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit/src/punit.properties 2007-09-28 17:29:13 UTC (rev 233)
@@ -1,5 +1,5 @@
builder.01=\ should implement
-logger.01=Started running
+logger.01=Starting
logger.total=total:
logger.failures=failures:
logger.green=GREEN
Modified: trunk/punit.samples/src/samples/DoSomethingTestClass.java
===================================================================
--- trunk/punit.samples/src/samples/DoSomethingTestClass.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit.samples/src/samples/DoSomethingTestClass.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -5,19 +5,19 @@
public class DoSomethingTestClass implements Test {
public void setUpBeforeWatchers() throws Exception {
- System.out.println("This setup will not be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This setup is not included into the execution time"); //$NON-NLS-1$
}
public void setUpAfterWatchers() throws Exception {
- System.out.println("This setup will be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This setup is included into the execution time"); //$NON-NLS-1$
}
public void tearDownBeforeWatchers() throws Exception {
- System.out.println("This setup will be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This tear down is included into the execution time"); //$NON-NLS-1$
}
public void tearDownAfterWatchers() throws Exception {
- System.out.println("This setup will not be caculated into the execution time"); //$NON-NLS-1$
+ System.out.println("This setup is not included into the execution time"); //$NON-NLS-1$
}
public void testA() {
Modified: trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java 2007-08-19 22:45:41 UTC (rev 232)
+++ trunk/punit.test/src/tests/api/org/punit/util/MemoryUtilTest.java 2007-09-28 17:29:13 UTC (rev 233)
@@ -12,16 +12,10 @@
public void testUsedMemory() {
long used = MemoryUtil.usedMemory();
Assert.assertTrue(used <= MemoryUtil.totalMemory());
- Assert.assertTrue(used <= MemoryUtil.maxTotalMemory());
int size = Math.round((1 - TOLERANCE)
* (MemoryUtil.totalMemory() - used));
Object a = new byte[size];
Assert.assertEquals(1, ((float) MemoryUtil.usedMemory() - used) / size, TOLERANCE);
}
-
- public void testTotalMemory() {
- Assert.assertTrue(MemoryUtil.totalMemory() <= MemoryUtil
- .maxTotalMemory());
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|