Junit testing stategy for clustered ehcache
I am planning to use ehcahe to cache some of my frequently used objects. I have a ehcache in a clustered configuration.
Now i want to do the following in my JUnit-
- Check if hibernate ehcache code is working correctly in cluster mode.
- Chec开发者_如何学Pythonk if my objects are correctly being fetched from cache and not recreated from WS.
Any thoughts?
Q> Check if hibernate ehcache code is working correctly in cluster mode.
A> You will have to mock a lot of stuff - double layer of (at least two separate instances) database, Hibernate and Ehcache to say the least. This might be doable but to me this doesn't make sense on many levels. First, the definition of a unit is the smallest testable part of an application - and this case goes nowhere near it. Secondly, I am sure Ehcache has unit/integration tests itself, do you really have so little trust in your libraries that you want to write unit tests for them? (proof of concept is quite different from unit test)
Q> Check if my objects are correctly being fetched from cache and not recreated from WS.
A> Scenarios are quite different depending on the cache strategy (cache-aside VS cache-as-sor VS read-through). This however should be quite easy as you have the control over your WS. During the test you should be able to determine how many times the WS was called - say, if the first read-through call to cache results a call to WS, then the second call shouldn't (because of the record being cached).
精彩评论