| 17 |
* utility methods and classes, as well as a simple framework for |
* utility methods and classes, as well as a simple framework for |
| 18 |
* helping to make sure that assertions failing in generated threads |
* helping to make sure that assertions failing in generated threads |
| 19 |
* cause the associated test that generated them to itself fail (which |
* cause the associated test that generated them to itself fail (which |
| 20 |
* JUnit doe not otherwise arrange). The rules for creating such |
* JUnit does not otherwise arrange). The rules for creating such |
| 21 |
* tests are: |
* tests are: |
| 22 |
* |
* |
| 23 |
* <ol> |
* <ol> |
| 24 |
* |
* |
| 25 |
* <li> All assertions in code running in generated threads must use |
* <li> All assertions in code running in generated threads must use |
| 26 |
* the forms {@link #threadFail} , {@link #threadAssertTrue} {@link |
* the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link |
| 27 |
* #threadAssertEquals}, or {@link #threadAssertNull}, (not |
* #threadAssertEquals}, or {@link #threadAssertNull}, (not |
| 28 |
* <tt>fail</tt>, <tt>assertTrue</tt>, etc.) It is OK (but not |
* <tt>fail</tt>, <tt>assertTrue</tt>, etc.) It is OK (but not |
| 29 |
* particularly recommended) for other code to use these forms too. |
* particularly recommended) for other code to use these forms too. |
| 44 |
* is always discriminable as larger than SHORT and smaller than |
* is always discriminable as larger than SHORT and smaller than |
| 45 |
* MEDIUM. And so on. These constants are set to conservative values, |
* MEDIUM. And so on. These constants are set to conservative values, |
| 46 |
* but even so, if there is ever any doubt, they can all be increased |
* but even so, if there is ever any doubt, they can all be increased |
| 47 |
* in one spot to rerun tests on slower platforms</li> |
* in one spot to rerun tests on slower platforms.</li> |
| 48 |
* |
* |
| 49 |
* <li> All threads generated must be joined inside each test case |
* <li> All threads generated must be joined inside each test case |
| 50 |
* method (or <tt>fail</tt> to do so) before returning from the |
* method (or <tt>fail</tt> to do so) before returning from the |
| 173 |
|
|
| 174 |
|
|
| 175 |
/** |
/** |
| 176 |
* Return the shortest timed delay. This could |
* Returns the shortest timed delay. This could |
| 177 |
* be reimplemented to use for example a Property. |
* be reimplemented to use for example a Property. |
| 178 |
*/ |
*/ |
| 179 |
protected long getShortDelay() { |
protected long getShortDelay() { |
| 182 |
|
|
| 183 |
|
|
| 184 |
/** |
/** |
| 185 |
* Set delays as multiples of SHORT_DELAY. |
* Sets delays as multiples of SHORT_DELAY. |
| 186 |
*/ |
*/ |
| 187 |
protected void setDelays() { |
protected void setDelays() { |
| 188 |
SHORT_DELAY_MS = getShortDelay(); |
SHORT_DELAY_MS = getShortDelay(); |
| 197 |
volatile boolean threadFailed; |
volatile boolean threadFailed; |
| 198 |
|
|
| 199 |
/** |
/** |
| 200 |
* Initialize test to indicate that no thread assertions have failed |
* Initializes test to indicate that no thread assertions have failed |
| 201 |
*/ |
*/ |
| 202 |
public void setUp() { |
public void setUp() { |
| 203 |
setDelays(); |
setDelays(); |
| 205 |
} |
} |
| 206 |
|
|
| 207 |
/** |
/** |
| 208 |
* Trigger test case failure if any thread assertions have failed |
* Triggers test case failure if any thread assertions have failed |
| 209 |
*/ |
*/ |
| 210 |
public void tearDown() { |
public void tearDown() { |
| 211 |
assertFalse(threadFailed); |
assertFalse(threadFailed); |