File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes How to test ReentrantReadWriteLock? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How to test ReentrantReadWriteLock?" Watch "How to test ReentrantReadWriteLock?" New topic
Author

How to test ReentrantReadWriteLock?

Swerrgy Smith
Ranch Hand

Joined: Mar 26, 2010
Posts: 91
Hi all,

I am implementing my own ReentrantReadWriteLock. However, I don't know how to test it. For example, how to test that a resource can be accessed by multiple readers or a single writer at a time, but not both.

Can you please help me?

Thank you very much.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18836
    
  40

Swerrgy Smith wrote:Hi all,

I am implementing my own ReentrantReadWriteLock. However, I don't know how to test it. For example, how to test that a resource can be accessed by multiple readers or a single writer at a time, but not both.

Can you please help me?
.


You think that writing the test harness for this class would be easier that writing the class itself... What's wrong with creating two basic classes? One that creates a thread, that grabs the read lock, prints that it owns it, and keeps it forever. One that does the same for the write lock. With these you can then create a ton of mini test cases, one that creates lots of reads; one that does the reads, waits a bit, then does the writes; one that does the writes, then does the reads, etc.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Swerrgy Smith
Ranch Hand

Joined: Mar 26, 2010
Posts: 91
Henry Wong wrote:
Swerrgy Smith wrote:Hi all,

I am implementing my own ReentrantReadWriteLock. However, I don't know how to test it. For example, how to test that a resource can be accessed by multiple readers or a single writer at a time, but not both.

Can you please help me?
.


You think that writing the test harness for this class would be easier that writing the class itself... What's wrong with creating two basic classes? One that creates a thread, that grabs the read lock, prints that it owns it, and keeps it forever. One that does the same for the write lock. With these you can then create a ton of mini test cases, one that creates lots of reads; one that does the reads, waits a bit, then does the writes; one that does the writes, then does the reads, etc.

Henry



Thank you very much. This is a good idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to test ReentrantReadWriteLock?