Create ehcache for reading and writing for test code and read-only for production code

I would like to annotate many of my Hibernate objects that contain reference data and / or configuration data using

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)

However, my JUnit tests set up and tear off some of this link / configuration data using Hibernate objects. Is there a recommended way for entities to be read and written during test installation and deletion, but read-only for production code?

Two of my immediate thoughts for imperfect workarounds:

  • Using NONSTRICT_READ_WRITE, but I'm not sure what the hidden cons are.
  • Subclassing in my test code to override read-only cache annotations.

Any recommendations on the cleanest ways to handle this?

(Note: Project uses maven.)

+3
source share
1 answer

Answering my own question:

Using NON_STRICT_READ_WRITE is a smart solution that has most of the benefits of READ_ONLY, but allows your test code to insert and update objects.

Remember to evict any cached items during test setup to make sure you are not reading outdated test data. (e.g. evictQueries ()).

0
source

Source: https://habr.com/ru/post/1745158/


All Articles