IdGenerator { public static Id generate(String prefix) { final IdInfo idInfo = random(); DateTime dateTime = new DateTime(idInfo.time); final String id = String.format("%s%s%04d%03d", prefix, formatter.print(dateTime), nodeId, idInfo.exponent); return Id.builder() .id(id) .exponent(idInfo.exponent) .generatedDate(dateTime.toDate()) .node(nodeId) .build(); }  static void initialize(int node); static void cleanUp(); static void initialize(
            int node, List<IdValidationConstraint> globalConstraints, Map<String, List<IdValidationConstraint>> domainSpecificConstraints); static synchronized void registerGlobalConstraints(IdValidationConstraint... constraints); static synchronized void registerGlobalConstraints(List<IdValidationConstraint> constraints); static synchronized void registerDomainSpecificConstraints(String domain, IdValidationConstraint... validationConstraints); static synchronized void registerDomainSpecificConstraints(String domain, List<IdValidationConstraint> validationConstraints); static Id generate(String prefix); static Optional<Id> generateWithConstraints(String prefix, String domain); static Optional<Id> generateWithConstraints(String prefix, String domain, boolean skipGlobal); static Optional<Id> generateWithConstraints(String prefix, final List<IdValidationConstraint> inConstraints); static Optional<Id> generateWithConstraints(String prefix, final List<IdValidationConstraint> inConstraints, boolean skipGlobal);  }
@Test public void testGenerate() throws Exception { IdGenerator.initialize(23); int numRunners = 20; ImmutableList.Builder<Runner> listBuilder = ImmutableList.builder(); for (int i = 0; i < numRunners; i++) { listBuilder.add(new Runner()); } List<Runner> runners = listBuilder.build(); ExecutorService executorService = Executors.newFixedThreadPool(numRunners); for(Runner runner : runners) { executorService.submit(runner); } Thread.sleep(10000); executorService.shutdownNow(); long totalCount = runners.stream().mapToLong(Runner::getCount).sum(); log.debug("Generated ID count: {}", totalCount); log.debug("Generated ID rate: {}/sec", totalCount/10); Assert.assertTrue(totalCount > 0); }