Senthilnathan
Senthilnathan

Reputation: 11

Testing for ehcache

I am using Java, Hibernate and Spring in my project. I am working on a huge set of data so I have implemented ehcache to cache the tables and result set on the first time.

But I dont know whether the data is getting loaded from cache the following times. How can I test this? Any help will be appreciated. This is how I have configured ehcache.

<prop key="hibernate.cache.use_second_level_cache">true</prop>  
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>  
<prop key="hibernate.cache.use_query_cache">true</prop>

Then I have kept ehcache.xml in the classpath. Is this enough? How can I test whether it's working or not?

Upvotes: 1

Views: 5033

Answers (2)

BITSSANDESH
BITSSANDESH

Reputation: 1135

You can add ehcache.xml in your test resources (Or in Test's Class Path) so that it would instantiate the ehcache. Then whenever you will test your method which is using this cached object it should search it from the cached object.

Or else you manually access the cache in your test code.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:cache.xml"})
public abstract class TestEcacheSpring {

  @Autowired
  EcacheSpringtest test;

  @Test
  public void test(){
    test.getName("test");
    test.getName("test"); 
  }

}

Upvotes: 0

skaffman
skaffman

Reputation: 403501

By checking the logs. Turn your server's logging up to DEBUG level, you'll see the cache activity being logged in there.

Upvotes: 5

Related Questions