• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to test ReentrantReadWriteLock?

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21423
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic