This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JUnit Test Cases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JUnit Test Cases" Watch "JUnit Test Cases" New topic
Author

JUnit Test Cases

Chris Be
Ranch Hand

Joined: Sep 11, 2006
Posts: 36
Two test cases that may come in handy . Note: They may need to be adjusted to match your particular database interface, or implementation. Any suggestions welcome.

1. Database interface functionality, non-threaded:


2. A fully fledged concurrency test.



ChrisBe<br />-------<br />SCJP, SCJD, SCEA in the making
Daniel Vogt
Greenhorn

Joined: Feb 19, 2007
Posts: 5
thanks for this test! it is very useful and inspired.


SCJP (83%) SCJD (in progress)
Tomasz Wilk
Greenhorn

Joined: Jul 13, 2007
Posts: 11
I find them usefull too.
But I don't agree with one thing. ConcurrencyTest fails if a read method throws exception. It is possible and legal to get this if a record was previously deleted. Therefore it can be considered as invalid (deleted) record and i.e. RecordNotFoundException has to be thrown.

Regards,
Tomek
Chris Be
Ranch Hand

Joined: Sep 11, 2006
Posts: 36
Originally posted by Tomasz Wilk:
[qb]ConcurrencyTest fails if a read method throws exception. It is possible and legal to get this if a record was previously deleted. Therefore it can be considered as invalid (deleted) record and i.e. RecordNotFoundException has to be thrown.
/qb]


Tomek,

I think you may have overlooked some critical test code sections. ConcurrencyTest does not
fail at all upon encountering a RecordNotFoundException. To the contrary, it acknowledges that the attempt to access the record was due to an invalid record accessed, and decrements the failure count required to pass the test.


[ October 01, 2007: Message edited by: Chris Be ]
Naveen Narayanan
Ranch Hand

Joined: Sep 11, 2007
Posts: 114

Chris ,
I am not sure right/wrong , but have a doubt �

Probably lockRecord can throw RecordNotFoundException , if a thread attempt to modify a deleted record ..(previously deleted one)
Can I suggest lockRecord also in try catch block and return it in a controlled manner so that it doesn�t be considered a failure �


Expecting your comments


SCJP 5.0, SCJD, SCWCD
Chris Be
Ranch Hand

Joined: Sep 11, 2006
Posts: 36
Originally posted by Naveen Narayanan:
Chris ,
I am not sure right/wrong , but have a doubt �
Expecting your comments


Yes SIR!

Well, you are suggesting the typical log-and-rethrow exception handling anti-pattern. Exception handling is worth taking much time to study (e.g. here), since done badly, it is a black hole swallowing up valuable resources during software maintenance.
[ November 15, 2007: Message edited by: Chris Be ]
Sean Beecroft
Greenhorn

Joined: Dec 28, 2007
Posts: 26
I've had to modify this test for the BS. It is more comprehensive then my own concurrency testing. As a result I may have found a dead lock in my code.


SCJA | SCJP | SCJD | SCMAD | SCEA(Underway...)
Chris Bicnal
Ranch Hand

Joined: Aug 17, 2005
Posts: 78
    
    1
Hi Sean,

How did you modify these classes to work with B&S, could you share your code?

Thanks,

Chris
 
wood burning stoves
 
subject: JUnit Test Cases
 
Similar Threads
About:My URLyBird1.3.2 Locking
Deadlock question
Lock on reading records
Locking & Exceptions (B&S)
testing concurrency and sleeping threads