question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@SpyBean removes @Caching functionality

See original GitHub issue

Using @SpyBean to test the caching behavior of a repository implementation appears to be impossible or broken. The idea is that you inject a spy bean into your test, then call the @Cacheable method twice, and then verify with Mockito that this method was indeed called once.

Please have a look at the example project here, which illustrates the problem. Essentially, using the repository @SpyBean magically removes the caching, as the failing Mockito.verify illustrates. It appears that @SpyBean should be made aware of caching and respect the proxy which is setup for caching.

As I was also working on #11077 (not yet merged), I don’t know if such testing is actually supported. So I’m also open to new ideas how to achieve the desired test of caching annotations. I do not want to put the caching annotations on the interface (as for example proposed here), as I consider caching a responsibility of the implementation. This makes it impossible to use @MockBean.

My current workaround is to @MockBean the underlying storage of the repository (we have another abstraction layer in our project, which is not present in the example project above). Still I think using the proposed @SpyBean solution might lead to easier testing.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
codependentcommented, May 23, 2018

I also ran into this same problem (Spring Boot 1.5.12.RELEASE). Any solution for it?

0reactions
neisercommented, Jun 23, 2018

@wilkinsona Thanks a lot! Another reason to migrate our projects to Spring Boot 2.x

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing - Spring
This instructs Spring to remove the context from the cache and rebuild the application context before running the next test that requires the ......
Read more >
Mastering DynaCache in WebSphere Commerce
DynaCache removes stale cache items, both as individuals or dependent, related groups. The process of removing these items is called invalidation. DynaCache.
Read more >
Adaptive Performance-Aware Distributed Memory Caching
removes cache replicas based on overall cache perfor- mance. We have built a prototype system ... of each server using a hash function...
Read more >
Value-Based Web Caching - People @ EECS at UC Berkeley
It eliminates some of the privacy concerns associated with delta-encoding proxies; the client in our algorithm only re- ceives data that was originally...
Read more >
Spring Boot and Redis /1 - How to Cache Incoming Requests
Caching is a fundamental concept in designing the back-end of a web ... on how to leverage this functionality by incorporating Redis.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found