### Question:
UUIDSequence implements KeySequence { @Override public CharSequence nextReaderKey() { long current = readerIndex.get(); if (readerKeysAvailable() > 0 && readerIndex.compareAndSet(current, current + 1L)) { return new UUID(seqId, current + 1L).toString(); } return null; } UUIDSequence(KeySequenceConfig keySequenceConfig); @Override CharSequence nextReaderKey(); @Override CharSequence nextWriterKey(); @Override long readerKeysAvailable(); @Override KeySequenceConfig getConfig(boolean sharedInstance); @Override Iterator<CharSequence> nextReaderKeys(long maxKeys); @Override boolean equals(Object obj); @Override int hashCode(); static final int RESERVED_KEYS; }### Answer:
@Test public void returnsNextReaderKeyExcludingCurrent() { CharSequence expectedFirstKey = getNextExpectedKey(RESERVED_KEYS + 1); CharSequence expectedSecondKey = getNextExpectedKey(RESERVED_KEYS + 2); KeySequenceConfig config = createDefaultTestWriterIndexConfig(RESERVED_KEYS + 2); KeySequence sequence = createDefaultTestUUIDSequence(config); CharSequence key1 = sequence.nextReaderKey(); CharSequence key2 = sequence.nextReaderKey(); assertEquals(expectedFirstKey, key1); assertEquals(expectedSecondKey, key2); }
@Test public void returnsNullReaderKeyIfReaderKeyEqualsInitialWriterKey() { KeySequenceConfig config = createDefaultTestKeySequenceConfig(); KeySequence sequence = createDefaultTestUUIDSequence(config); CharSequence readerKey1 = sequence.nextReaderKey(); assertNull(readerKey1); }
@Test public void returnsNullReaderKeyIfReaderKeyEqualsWriterKey() { KeySequenceConfig config = createDefaultTestKeySequenceConfig(); KeySequence sequence = createDefaultTestUUIDSequence(config); CharSequence readerKey1 = sequence.nextReaderKey(); CharSequence readerKey2 = sequence.nextReaderKey(); assertNull(readerKey1); assertNull(readerKey2); }