HHH-10418 : test case showing inconsistency between SessionFactoryImpl and CacheImpl

This commit is contained in:
Gail Badner 2018-01-03 21:43:20 -08:00
parent 79dbc715f4
commit 317e0b0ece
1 changed files with 22 additions and 0 deletions

View File

@ -19,6 +19,10 @@ import org.hibernate.Hibernate;
import org.hibernate.annotations.Cache; import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.cache.spi.Region;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.RegionAccessStrategy;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.stat.SecondLevelCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics;
import org.hibernate.stat.Statistics; import org.hibernate.stat.Statistics;
@ -30,6 +34,8 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/** /**
* @author Gail Badner * @author Gail Badner
@ -208,6 +214,22 @@ public class EntitiesAndCollectionsInSameRegionTest extends SingleNodeTest {
); );
} }
@Test
@TestForIssue(jiraKey = "HHH-10418")
public void testSessionFactoryImplCachImplConsistent() {
// When there is an entity region and collection region with the same name,
// * SessionFactoryImplementor#getSecondLevelCacheRegionAccessStrategy should return an EntityRegionAccessStrategy;
// * SessionFactoryImplementor#getSecondLevelCacheRegionAccessStrategy should return an EntityRegion.
final RegionAccessStrategy regionAccessStrategy = sessionFactory().getSecondLevelCacheRegionAccessStrategy(
REGION_NAME
);
assertTrue( EntityRegionAccessStrategy.class.isInstance( regionAccessStrategy ) );
final EntityRegionAccessStrategy entityRegionAccessStrategy = (EntityRegionAccessStrategy) regionAccessStrategy;
assertSame( entityRegionAccessStrategy.getRegion(), sessionFactory().getSecondLevelCacheRegion( REGION_NAME ) );
}
@Entity(name = "AnEntity") @Entity(name = "AnEntity")
@Cache( usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = REGION_NAME) @Cache( usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = REGION_NAME)
public static class AnEntity { public static class AnEntity {