int increment = 10;
Long next;
// test historic sequence behavior, where the initial values start at 1...
SourceMock sequence = new SourceMock( 1 );
Optimizer optimizer = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
for ( int i = 1; i <= increment; i++ ) {
next = ( Long ) optimizer.generate( sequence );
assertEquals( i, next.intValue() );
}
assertEquals( 1, sequence.getTimesCalled() ); // once to initialze state
assertEquals( 1, sequence.getCurrentValue() );
// force a "clock over"
next = ( Long ) optimizer.generate( sequence );
assertEquals( 11, next.intValue() );
assertEquals( 2, sequence.getTimesCalled() );
assertEquals( 2, 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 = OptimizerFactory.buildOptimizer( OptimizerFactory.HILO, Long.class, increment );
for ( int i = 1; i <= increment; i++ ) {
next = ( Long ) optimizer.generate( sequence );
assertEquals( i, next.intValue() );
}
assertEquals( 2, sequence.getTimesCalled() ); // here have have an extra call to get to 1 initially
assertEquals( 1, sequence.getCurrentValue() );
// force a "clock over"
next = ( Long ) optimizer.generate( sequence );
assertEquals( 11, next.intValue() );
assertEquals( 3, sequence.getTimesCalled() );
assertEquals( 2, sequence.getCurrentValue() );
}