Java ehcache的测试
我在项目中使用Java、Hibernate和Spring。我正在处理大量的数据,所以我第一次实现了ehcache来缓存表和结果集 但是我不知道接下来的几次是否从缓存中加载了数据。我如何测试这个?任何帮助都将不胜感激。这就是我配置ehcache的方式Java ehcache的测试,java,spring,hibernate,ehcache,Java,Spring,Hibernate,Ehcache,我在项目中使用Java、Hibernate和Spring。我正在处理大量的数据,所以我第一次实现了ehcache来缓存表和结果集 但是我不知道接下来的几次是否从缓存中加载了数据。我如何测试这个?任何帮助都将不胜感激。这就是我配置ehcache的方式 <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class">
<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>
true
net.sf.ehcache.hibernate.SingletonEhCacheProvider
真的
然后我在类路径中保留了
ehcache.xml
。这够了吗?如何通过检查日志来测试它是否工作?。将服务器的日志记录设置为调试级别,您将看到缓存活动正在那里被记录。通过检查日志。将服务器的日志记录升级到调试级别,您将看到缓存活动正在那里被记录。您可以在测试资源(或测试的类路径)中添加ehcache.xml,以便它将实例化ehcache。然后,无论何时测试使用此缓存对象的方法,它都应该从缓存对象中搜索它
或者手动访问测试代码中的缓存
@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");
}
}
您可以在测试资源(或测试的类路径)中添加ehcache.xml,以便它实例化ehcache。然后,无论何时测试使用此缓存对象的方法,它都应该从缓存对象中搜索它 或者手动访问测试代码中的缓存
@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");
}
}
自动化测试呢?自动化测试呢?