HHH-10219 - Infinite loop generating IDs if using negative increment
(cherry picked from commit cd7212a1e8
)
This commit is contained in:
parent
deea4adfe9
commit
ca46d28db3
|
@ -37,10 +37,13 @@ public final class NoopOptimizer extends AbstractOptimizer {
|
||||||
// reliable as it might be mutated by multipled threads.
|
// reliable as it might be mutated by multipled threads.
|
||||||
// The lastSourceValue field is only accessed by tests,
|
// The lastSourceValue field is only accessed by tests,
|
||||||
// so this is not a concern.
|
// so this is not a concern.
|
||||||
IntegralDataTypeHolder value = null;
|
IntegralDataTypeHolder value = callback.getNextValue();
|
||||||
while ( value == null || value.lt( 1 ) ) {
|
if ( incrementSize > 0 ) {
|
||||||
value = callback.getNextValue();
|
while ( value.lt( 1 ) ) {
|
||||||
|
value = callback.getNextValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSourceValue = value;
|
lastSourceValue = value;
|
||||||
return value.makeValue();
|
return value.makeValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,28 @@ public class OptimizerUnitTest extends BaseUnitTestCase {
|
||||||
assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
|
assertEquals( 11, sequence.getTimesCalled() ); // an extra time to get to 1 initially
|
||||||
assertEquals( 10, sequence.getCurrentValue() );
|
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
|
@Test
|
||||||
public void testBasicHiLoOptimizerUsage() {
|
public void testBasicHiLoOptimizerUsage() {
|
||||||
|
|
Loading…
Reference in New Issue