File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes testing locks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "testing locks" Watch "testing locks" New topic
Author

testing locks

Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
How did you guys test the lock implementation with multiple clients requesting for tickets? I have not reached the GUI part. Any ideas?
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Prakash,
I wrote a standalone test program spawning threads in a loop to make remote calls. Keep in mind that you will not be reusing the remote object you got from the firt call. Every thread will get ask for a new instance of remote object from the RMI server.
Think about probably 7 various test cases and test them.
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
Thanks a lot, Sai!
Pete Lyons
Ranch Hand

Joined: Aug 18, 2002
Posts: 109
It is also easy to test by putting either a call to Thread.sleep() or System.in.readLine() (a handy way to pause a program) between your calls to lock() and unlock(). Then if you run 2 different instances of the client against one server and try to book seats on the same flight, being sure to have the second client start booking while the first client has the flight locked, you should see afterward that the second client shows the correct total number of seats, while the first client is not yet aware of the seats the second one booked. Does that make sense? I hope that helps.
Thomas Fly
Ranch Hand

Joined: Sep 09, 2002
Posts: 164
Personally I included a "Traffic Cop" test mode (menu selectable) that locks, then throws up a dialog box before continuing on.
My lock mechanism notes the time that the lock was acquired, as well as a clientID (the remote stub reference), and a "progress" counter. If a client has gone comotose (i.e., not made any progress in 60 seconds, beyond acquiring the lock), the server can give its lock to a second client that comes along requesting that lock.
Server shutdown also checks for comotose clients, and gives you the option of "pulling the plug" on them- hence allowing any blocked clients to finish.
That locking mechanism is fancier than what's really required, but still the Traffic Cop is a neat way to test the locking mechanism, since it gives you direct control over it.


Fly by Night Consultants<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr><i>I climbed on the back of a giant albatross<br />which flew through a crack in the cloud<br />to a place where happiness reigned...<br />all year 'round<br />the music played ever so loudly!</i><p><a href="http://thomasfly.com/songs/Traffic/Hole_in_my_Shoe_qt.htm" target="_blank" rel="nofollow">Hole in My Shoe</a><hr></blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: testing locks
 
Similar Threads
Testing lock/unlock
Testing and JUnit
Locking - synchronized
Transfer handling help
Modify Issues