HHH-18098 improve test for @Cacheable(false)

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-10 15:40:23 +02:00
parent 77f6af42e7
commit 47da22183b
1 changed files with 20 additions and 0 deletions

View File

@ -75,12 +75,32 @@ public class InheritedCacheableTest extends BaseNonConfigCoreFunctionalTestCase
final Customer customer = s.get( Customer.class, "2" ); final Customer customer = s.get( Customer.class, "2" );
assertTrue( Hibernate.isInitialized( customer ) ); assertTrue( Hibernate.isInitialized( customer ) );
assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(0L) ); assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(0L) );
assertThat( statistics.getSecondLevelCachePutCount(), CoreMatchers.is(0L) );
statistics.clear(); statistics.clear();
final Employee emp = s.get( Employee.class, "1" ); final Employee emp = s.get( Employee.class, "1" );
assertTrue( Hibernate.isInitialized( emp ) ); assertTrue( Hibernate.isInitialized( emp ) );
assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L) ); assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L) );
assertThat( statistics.getSecondLevelCachePutCount(), CoreMatchers.is(0L) );
}
);
inTransaction(
s -> {
statistics.clear();
final Person customer = s.get( Person.class, "2" );
assertTrue( Hibernate.isInitialized( customer ) );
assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(0L) );
assertThat( statistics.getSecondLevelCachePutCount(), CoreMatchers.is(0L) );
statistics.clear();
final Person emp = s.get( Person.class, "1" );
assertTrue( Hibernate.isInitialized( emp ) );
assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L) );
assertThat( statistics.getSecondLevelCachePutCount(), CoreMatchers.is(0L) );
} }
); );
} }