SegmentedIdGenerator implements IdGenerator { @Override public synchronized long nextValue() { if (offset == 0) { newSegment(); } if (++offset == SEGMENT_SIZE){ offset = 0; } return ++value; } SegmentedIdGenerator(long initialValue,
                              IdGeneratorService service); @Override // IdGenerator synchronized long nextValue();  }
@Test public void testIncrement() { final long initialValue = 1000; final long serviceInitialValue = -1; final long maxValue = 10000000; IdGeneratorService service = new LocalIdService(serviceInitialValue); SegmentedIdGenerator id = new SegmentedIdGenerator(initialValue, service); for (long i = initialValue + 1; i <= maxValue; i++) { assertThat(id.nextValue(), is(i)); } }