HHH-11709 : test case

This commit is contained in:
Gail Badner 2017-04-28 19:30:17 -07:00
parent dfbeb1ce37
commit d211b41319
1 changed files with 149 additions and 0 deletions

View File

@ -144,6 +144,155 @@ public class NegativeValueSequenceTest {
}
}
@Test
@TestForIssue( jiraKey = "HHH-11709" )
public void testPositiveOneAllocationSizeNoopOptimizer() {
ServiceRegistryImplementor serviceRegistry = null;
SessionFactoryImplementor sessionFactory = null;
Session session = null;
try {
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000116" );
Metadata metadata = new MetadataSources( serviceRegistry )
.addAnnotatedClass( PositiveOneIncrementSize.class )
.buildMetadata();
// PositiveOneIncrementSize ID has allocationSize == 1, so warning should not be triggered.
assertEquals( false, triggerable.wasTriggered() );
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
assertOptimizer( sessionFactory, PositiveOneIncrementSize.class, NoopOptimizer.class );
session = sessionFactory.openSession();
session.getTransaction().begin();
// initial value is -5; sequence should be incremented by 1 (since allocationSize is 1)
for ( Integer i = -5; i <= 5; i++ ) {
PositiveOneIncrementSize theEntity = new PositiveOneIncrementSize();
session.persist( theEntity );
assertEquals( i, theEntity.id );
}
}
finally {
if ( session != null ) {
session.getTransaction().rollback();
session.close();
}
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistry != null ) {
serviceRegistry.destroy();
}
}
}
@Test
@TestForIssue( jiraKey = "HHH-11709" )
public void testPositiveTwoAllocationSizeNoopOptimizer() {
ServiceRegistryImplementor serviceRegistry = null;
SessionFactoryImplementor sessionFactory = null;
Session session = null;
try {
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.PREFERRED_POOLED_OPTIMIZER, "none" )
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000116" );
Metadata metadata = new MetadataSources( serviceRegistry )
.addAnnotatedClass( PositiveTwoIncrementSize.class )
.buildMetadata();
// NoopOptimizer is preferred (due to setting AvailableSettings.PREFERRED_POOLED_OPTIMIZER to "false")
// PositiveTwoIncrementSize ID has allocationSize == 2, so warning should be triggered.
assertEquals( true, triggerable.wasTriggered() );
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
assertOptimizer( sessionFactory, PositiveTwoIncrementSize.class, NoopOptimizer.class );
session = sessionFactory.openSession();
session.getTransaction().begin();
// initial value is -5; sequence should be incremented by 1
// (since NoopOptimizer positive default allocationSize is 1)
for ( Integer i = -5; i <= 5; i++ ) {
PositiveTwoIncrementSize theEntity = new PositiveTwoIncrementSize();
session.persist( theEntity );
assertEquals( i, theEntity.id );
}
}
finally {
if ( session != null ) {
session.getTransaction().rollback();
session.close();
}
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistry != null ) {
serviceRegistry.destroy();
}
}
}
@Test
@TestForIssue( jiraKey = "HHH-11709" )
public void testPositiveTwoAllocationSizePooledOptimizer() {
ServiceRegistryImplementor serviceRegistry = null;
SessionFactoryImplementor sessionFactory = null;
Session session = null;
try {
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000116" );
Metadata metadata = new MetadataSources( serviceRegistry )
.addAnnotatedClass( PositiveTwoIncrementSize.class )
.buildMetadata();
// PositiveTwoIncrementSize ID has allocationSize == 2, so PooledOptimizer should be used.
// Warning should not be triggered.
assertEquals( false, triggerable.wasTriggered() );
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
assertOptimizer( sessionFactory, PositiveTwoIncrementSize.class, PooledOptimizer.class );
session = sessionFactory.openSession();
session.getTransaction().begin();
// initial value is -5; sequence should be incremented by 1
// (since NoopOptimizer positive default allocationSize is 1)
for ( Integer i = -5; i <= 5; i++ ) {
PositiveTwoIncrementSize theEntity = new PositiveTwoIncrementSize();
session.persist( theEntity );
assertEquals( i, theEntity.id );
}
}
finally {
if ( session != null ) {
session.getTransaction().rollback();
session.close();
}
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistry != null ) {
serviceRegistry.destroy();
}
}
}
private void assertOptimizer(
SessionFactoryImplementor sessionFactory,
Class<?> entityClass,