GroupSequence implements Sequence { @Override public long nextValue() throws SequenceException { boolean isTest = this.isTestSeq(); if (getSequenceRange(isTest) == null) { lock.lock(); try { if (getSequenceRange(isTest) == null) { setSequenceRange(sequenceDao.nextRange(name), isTest); } } finally { lock.unlock(); } } long value = getSequenceRange(isTest).getAndIncrement(); if (value == -1) { lock.lock(); try { for (;;) { if (getSequenceRange(isTest).isOver()) { setSequenceRange(sequenceDao.nextRange(name), isTest); } value = getSequenceRange(isTest).getAndIncrement(); if (value == -1) { continue; } break; } } finally { lock.unlock(); } } if (value < 0) { throw new SequenceException("Sequence value overflow, value = " + value); } return value; }  void init(); @Override long nextValue(); long nextValue(int size); GroupSequenceDao getSequenceDao(); void setSequenceDao(GroupSequenceDao sequenceDao); String getName(); void setName(String name);  }
@Ignore @Test public void test_nextValue() throws SequenceException { Set<Long> set = new HashSet<Long>(); for (int i = 0; i < 10000000; i++) { Long id = sequence.nextValue(); boolean b = set.contains(id); Assert.assertFalse(b); set.add(id); } }