我开发了一个MemberRepository扩展的Spring Data存储库接口org.springframework.data.jpa.repository.JpaRepository.MemberRepository有一个方法:
@Cacheable(CacheConfiguration.DATABASE_CACHE_NAME)
Member findByEmail(String email);
Run Code Online (Sandbox Code Playgroud)
结果由Spring缓存抽象缓存(由a支持ConcurrentMapCache).
我的问题是,我想要写一个集成测试(针对HSQLDB)断言结果被从数据库第一次检索,并从缓存中的第二次.
我最初想过嘲笑jpa基础设施(实体经理等),并以某种方式断言实体经理第二次没有被调用但看起来太难/笨重(参见/sf/answers/1640972021/).
那么有人可以提供有关如何测试带有注释的Spring Data Repository方法的缓存行为的建议@Cacheable吗?