@Override public void close() { for ( StoreType type : StoreType.values() ) { IdSequence generator = idGenerator( type ); if ( generator instanceof RenewableBatchIdSequence ) { ((RenewableBatchIdSequence)generator).close(); } } } }
@Test public void shouldHandleCloseWithNoCurrentBatch() { // when ids.close(); // then assertTrue( excessIds.isEmpty() ); }
@Test public void shouldOnlyCloseOnce() { // given for ( int i = 0; i < BATCH_SIZE / 2; i++ ) { ids.nextId(); } // when ids.close(); // then for ( long i = BATCH_SIZE / 2; i < BATCH_SIZE; i++ ) { assertTrue( excessIds.remove( i ) ); } // and when closing one more time ids.close(); // then assertTrue( excessIds.isEmpty() ); }
@Test public void shouldGiveBackExcessIdsOnClose() { // given for ( int i = 0; i < BATCH_SIZE / 2; i++ ) { ids.nextId(); } // when ids.close(); // then assertEquals( BATCH_SIZE - BATCH_SIZE / 2, excessIds.size() ); for ( long i = BATCH_SIZE / 2; i < BATCH_SIZE; i++ ) { assertTrue( excessIds.contains( i ) ); } }
@Override public void close() { for ( StoreType type : StoreType.values() ) { IdSequence generator = idGenerator( type ); if ( generator instanceof RenewableBatchIdSequence ) { ((RenewableBatchIdSequence)generator).close(); } } } }