### Question:
QueryIdGenerator { public synchronized QueryId createNextQueryId() { if (counter > 99_999) { while (MILLISECONDS.toSeconds(nowInMillis()) == lastTimeInSeconds) { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } counter = 0; } long now = nowInMillis(); if (MILLISECONDS.toSeconds(now) != lastTimeInSeconds) { lastTimeInSeconds = MILLISECONDS.toSeconds(now); lastTimestamp = TIMESTAMP_FORMAT.print(now); if (MILLISECONDS.toDays(now) != lastTimeInDays) { lastTimeInDays = MILLISECONDS.toDays(now); counter = 0; } } return new QueryId(format("%s_%05d_%s", lastTimestamp, counter++, coordinatorId)); } QueryIdGenerator(); String getCoordinatorId(); synchronized QueryId createNextQueryId();  }### Answer:
@Test public void testCreateNextQueryId() { TestIdGenerator idGenerator = new TestIdGenerator(); long millis = new DateTime(2001, 7, 14, 1, 2, 3, 4, DateTimeZone.UTC).getMillis(); idGenerator.setNow(millis); for (int i = 0; i < 100_000; i++) { assertEquals(idGenerator.createNextQueryId(), new QueryId(format("20010714_010203_%05d_%s", i, idGenerator.getCoordinatorId()))); } millis += 1000; idGenerator.setNow(millis); for (int i = 0; i < 100_000; i++) { assertEquals(idGenerator.createNextQueryId(), new QueryId(format("20010714_010204_%05d_%s", i, idGenerator.getCoordinatorId()))); } millis += 1000; idGenerator.setNow(millis); for (int i = 0; i < 100; i++) { assertEquals(idGenerator.createNextQueryId(), new QueryId(format("20010714_010205_%05d_%s", i, idGenerator.getCoordinatorId()))); } millis = new DateTime(2001, 7, 15, 0, 0, 0, 0, DateTimeZone.UTC).getMillis(); idGenerator.setNow(millis); for (int i = 0; i < 100_000; i++) { assertEquals(idGenerator.createNextQueryId(), new QueryId(format("20010715_000000_%05d_%s", i, idGenerator.getCoordinatorId()))); } }