Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Testing database/data layer without using Singleton method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Testing database/data layer without using Singleton method" Watch "Testing database/data layer without using Singleton method" New topic
Author

Testing database/data layer without using Singleton method

Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Hi,
Just wondering if I don't use the Singleton pattern for the Data layer of my project, for testing purposes, would I have to use multiple instances of my Data class in testing? For example, say I was testing multiple-threading of 50 reads. Would I need to say, test 25 of these using 1 instance of my Data class and another 25 say using another instance? Basically what I am asking is if one does not use the Singleton pattern for the Data layer when accessing the database functionality, do they have to test application across multiple instances of the data class?
Thanks.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5543
    
  13

Hi Mark,

That all depends on how you implemented concurrency and making the data class thread-safe. Many possible alternatives to ensure thread-safety, so it has little added value to elaborate on it.

And if you implemented your singleton pattern correctly, you should not be able to create multiple instances of your Data class. Because if you can do it for testing purposes, you also can do it for developing (production) purposes and the singleton pattern is not applied correctly.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
Don't get me started about those stupid light bulbs.
 
subject: Testing database/data layer without using Singleton method