HHH-10219 - Infinite loop generating IDs if using negative increment

This commit is contained in:
Steve Ebersole 2015-11-06 10:34:31 -06:00
parent ae9ff5587e
commit cd7212a1e8
2 changed files with 28 additions and 3 deletions

View File

@ -37,10 +37,13 @@ public final class NoopOptimizer extends AbstractOptimizer {
// reliable as it might be mutated by multipled threads.
// The lastSourceValue field is only accessed by tests,
// so this is not a concern.
IntegralDataTypeHolder value = null;
while ( value == null || value.lt( 1 ) ) {
value = callback.getNextValue();
IntegralDataTypeHolder value = callback.getNextValue();
if ( incrementSize > 0 ) {
while ( value.lt( 1 ) ) {
value = callback.getNextValue();
}
}
lastSourceValue = value;
return value.makeValue();
}

View File

@ -42,6 +42,28 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
assertEquals( 10, sequence.getCurrentValue() );
}
@Test
public void testBasicNoOptimizerUsageWithNegativeValues() {
// test historic sequence behavior, where the initial values start at 1...
SourceMock sequence = new SourceMock( -1, -1 );
Optimizer optimizer = buildNoneOptimizer( -1, -1 );
for ( int i = 1; i < 11; i++ ) {
final Long next = ( Long ) optimizer.generate( sequence );
assertEquals( -i, next.intValue() );
}
assertEquals( 10, sequence.getTimesCalled() );
assertEquals( -10, sequence.getCurrentValue() );
// test historic table behavior, where the initial values started at 0 (we now force 1 to be the first used id value)
sequence = new SourceMock( 0 );
optimizer = buildNoneOptimizer( -1, 1 );
for ( int i = 1; i < 11; i++ ) {
final Long next = ( Long ) optimizer.generate( sequence );
assertEquals( i, next.intValue() );
}
assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
assertEquals( 10, sequence.getCurrentValue() );
}
@Test
public void testBasicHiLoOptimizerUsage() {