| edu.rice.cs.drjava.DrJavaTestCase edu.rice.cs.util.ReaderWriterLockTest
ReaderWriterLockTest | public class ReaderWriterLockTest extends DrJavaTestCase (Code) | | Attempts to test the correctness of the ReaderWriterLock class, which allows multiple reader and writer threads to
safely access a shared resource. (Multiple readers can be active at a time, but only one writer can be active,
during which time no readers can be active.) This can be difficult to test because there is little control over
how the threads are actually scheduled.
version: $Id: ReaderWriterLockTest.java 4255 2007-08-28 19:17:37Z mgricken $ |
Inner Class :abstract public class ReaderThread extends Thread | |
Inner Class :abstract public class WriterThread extends Thread | |
Inner Class :public class PrinterReaderThread extends ReaderThread | |
Inner Class :public class PrinterWriterThread extends WriterThread | |
Inner Class :public class PrintCommand | |
Method Summary | |
public void | setUp() Creates a new lock for the tests. | public void | testCannotReadInAWrite() Ensure that a writing thread cannot perform a read. | public void | testCannotWriteInARead() Ensure that a reading thread cannot perform a write. | public void | testCannotWriteInAWrite() Ensure that a writing thread cannot perform an additional write. | public void | testMultipleReaders() Tests that multiple readers can run without causing deadlock. | public void | testMultipleReadersAndWriters() We would like to test the following schedule.
W1 |***********|
W2 |..........*****|
R1 |..............********|
R2 |............****|
W3 |...................***|
R3 |.....................****|
R4 |................*******|
R5 |***|
Key: "." means waiting, "*" means running
This is next to impossible to set up in Java. | public void | testMultipleWriters() Tests that multiple writers run in mutually exclusive intervals without causing deadlock. | public void | testReaderMultipleReads() Ensure that a single thread can perform multiple reads. |
setUp | public void setUp() throws Exception(Code) | | Creates a new lock for the tests.
|
testCannotReadInAWrite | public void testCannotReadInAWrite()(Code) | | Ensure that a writing thread cannot perform a read.
|
testCannotWriteInARead | public void testCannotWriteInARead()(Code) | | Ensure that a reading thread cannot perform a write.
|
testCannotWriteInAWrite | public void testCannotWriteInAWrite()(Code) | | Ensure that a writing thread cannot perform an additional write.
|
testMultipleReaders | public void testMultipleReaders() throws InterruptedException(Code) | | Tests that multiple readers can run without causing deadlock. We can't really impose any ordering on their output.
|
testMultipleReadersAndWriters | public void testMultipleReadersAndWriters() throws InterruptedException(Code) | | We would like to test the following schedule.
W1 |***********|
W2 |..........*****|
R1 |..............********|
R2 |............****|
W3 |...................***|
R3 |.....................****|
R4 |................*******|
R5 |***|
Key: "." means waiting, "*" means running
This is next to impossible to set up in Java. What we'd really
like is a unit-testing framework that allows us to easily specify
such a schedule in a test. (Conveniently, Corky Cartwright has
applied for a Texas ATP grant to develop just such a framework.)
So, instead, we'll just set up these threads, let them run, and
enforce that no one interferes with output from a writer.
|
testMultipleWriters | public void testMultipleWriters() throws InterruptedException(Code) | | Tests that multiple writers run in mutually exclusive intervals without causing deadlock.
|
testReaderMultipleReads | public void testReaderMultipleReads() throws InterruptedException(Code) | | Ensure that a single thread can perform multiple reads.
|
Fields inherited from edu.rice.cs.drjava.DrJavaTestCase | final public static String TEST_DRJAVA_CONFIG_PROPERTY(Code)(Java Doc)
|
|
|