@Test public void testCreateKey() { String last = KeyGenerator.createKey(); for (int i = 0; i < 1000000; i++) { final String lastKey = last; final String key = KeyGenerator.createKey(); assertThat(key).is(new Condition<>((other) -> lastKey.compareTo(other) < 0, "greater than " + lastKey)); last = key; } }
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);  }