@Test public void shouldGenerateKeysInChronologicalOrder() { for (int rnd = Byte.MIN_VALUE; rnd <= Byte.MAX_VALUE; rnd++) { KeyGenerator.randomnessByte = (byte) rnd; KeyGenerator.clock = () -> 1534509528000L; final String newer = KeyGenerator.createKey(); KeyGenerator.clock = () -> 1534245726000L; final String older = KeyGenerator.createKey(); assertThat(newer.compareTo(older)).isGreaterThan(0); } }
public static String createKey() { final long now = clock.getAsLong(); final ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + 1 + 8]); buffer.putLong(now); buffer.put(randomnessByte); buffer.putLong(getRandomPart(now)); return encodeKey(buffer.array()); }
KeyGenerator { public static String createKey() { final long now = clock.getAsLong(); final ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + 1 + 8]); buffer.putLong(now); buffer.put(randomnessByte); buffer.putLong(getRandomPart(now)); return encodeKey(buffer.array()); } }
KeyGenerator { public static String createKey() { final long now = clock.getAsLong(); final ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + 1 + 8]); buffer.putLong(now); buffer.put(randomnessByte); buffer.putLong(getRandomPart(now)); return encodeKey(buffer.array()); } private  KeyGenerator(); }
KeyGenerator { public static String createKey() { final long now = clock.getAsLong(); final ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + 1 + 8]); buffer.putLong(now); buffer.put(randomnessByte); buffer.putLong(getRandomPart(now)); return encodeKey(buffer.array()); } private  KeyGenerator(); static String createKey(); static long getKeyTimeMillis(String key); static String recreateKey(long timestamp, int random1, long random2); }
KeyGenerator { public static String createKey() { final long now = clock.getAsLong(); final ByteBuffer buffer = ByteBuffer.wrap(new byte[8 + 1 + 8]); buffer.putLong(now); buffer.put(randomnessByte); buffer.putLong(getRandomPart(now)); return encodeKey(buffer.array()); } private  KeyGenerator(); static String createKey(); static long getKeyTimeMillis(String key); static String recreateKey(long timestamp, int random1, long random2);  }