Utils { public static String buildUUID(String id) { return Utils.getBuilder() .append(id) .append(Long.toHexString(Utils.getNowMicrosUtc())) .toString(); } private  Utils(); static void registerCustomJsonMapper(Class<?> clazz,
            JsonMapper mapper); static void registerCustomKryoSerializer(ThreadLocal<Kryo> kryoThreadLocal,
            boolean isDocumentSerializer); static T clone(T t); static T cloneObject(T t); static String computeSignature(ServiceDocument s, ServiceDocumentDescription description); static byte[] getBuffer(int capacity); static int toBytes(Object o, byte[] buffer, int position); static Object fromBytes(byte[] bytes); static Object fromBytes(byte[] bytes, int position, int length); static ServiceDocument fromQueryBinaryDocument(String link, Object binaryData); static void performMaintenance(); static String computeHash(CharSequence content); static String toJson(Object body); static String toJsonHtml(Object body); @Deprecated static String toJson(boolean hideSensitiveFields, boolean useHtmlFormatting, Object body); static String toJson(Set<JsonMapper.JsonOptions> options, Object body); static T fromJson(String json, Class<T> clazz); static T fromJson(Object json, Class<T> clazz); static T fromJson(Object json, Type type); static T getJsonMapValue(Object json, String key, Class<T> valueClazz); static T getJsonMapValue(Object json, String key, Type valueType); static String toString(Throwable t); static String toString(Map<?, Throwable> exceptions); static void log(Class<?> type, String classOrUri, Level level, String fmt,
            Object... args); static void log(Class<?> type, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            String fmt, Object... args); static void log(Logger lg, Integer nestingLevel, String classOrUri, Level level,
            Supplier<String> messageSupplier); static void logWarning(String fmt, Object... args); static String toDocumentKind(Class<?> type); static String fromDocumentKind(String kind); static String registerKind(Class<?> type, String kind); static Class<?> getTypeFromKind(String kind); static String buildKind(Class<?> type); static ServiceErrorResponse toServiceErrorResponse(Throwable e); static ServiceErrorResponse toValidationErrorResponse(Throwable t, Operation op); static boolean isValidationError(Throwable e); static String buildServicePath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Class<? extends Service> klass); static String buildUiResourceUriPrefixPath(Service service); static String buildCustomUiResourceUriPrefixPath(Service service); static Object setJsonProperty(Object body, String fieldName, String fieldValue); static String validateServiceOption(EnumSet<ServiceOption> options,
            ServiceOption option); static void setFactoryAvailabilityIfOwner(ServiceHost host, String factoryLink,
            String factoryNodeSelectorPath, boolean isAvailable); static boolean isReachable(SystemHostInfo systemInfo, InetAddress addr, long timeoutMs); static boolean isReachableByPing(SystemHostInfo systemInfo, InetAddress addr,
            long timeoutMs); static String getNormalizedHostAddress(SystemHostInfo systemInfo, InetAddress addr); static void encodeAndTransferLinkedStateToBody(Operation source, Operation target,
            boolean useBinary); static byte[] encodeBody(Operation op, boolean isRequest); static byte[] encodeBody(Operation op, Object body, String contentType, boolean isRequest); static void decodeBody(Operation op, ByteBuffer buffer, boolean isRequest); static void decodeBody(
            Operation op, ByteBuffer buffer, boolean isRequest, boolean compressed); static String decodeIfText(ByteBuffer buffer, String contentType); static ByteBuffer compressGZip(String text); static boolean isContentTypeKryoBinary(String contentType); static Path getServiceUiResourcePath(Service s); static boolean mergeWithState(
            ServiceDocumentDescription desc,
            T source, T patch); static boolean mergeWithState(T currentState, Operation op); static EnumSet<MergeResult> mergeWithStateAdvanced(
            ServiceDocumentDescription desc, T currentState, Class<T> type, Operation op); static void validateState(
            ServiceDocumentDescription desc, T state); static long fromNowMicrosUtc(long deltaMicros); static boolean beforeNow(long microsUtc); static long getSystemNowMicrosUtc(); static long getNowMicrosUtc(); static void setTimeDriftThreshold(long micros); static void resetTimeComparisonEpsilonMicros(); static void setTimeComparisonEpsilonMicros(long micros); static long getTimeComparisonEpsilonMicros(); static boolean isWithinTimeComparisonEpsilon(long timeMicros); static StringBuilder getBuilder(); static boolean updateCollections(T currentState,
            ServiceStateCollectionUpdateRequest patchBody); static boolean updateMaps(T currentState,
            ServiceStateMapUpdateRequest patchBody); static String buildUUID(String id); static T buildServiceConfig(T config, Service service); static final String PROPERTY_NAME_PREFIX; static final Charset CHARSET_OBJECT; static final String CHARSET; static final String UI_DIRECTORY_NAME; static final String PROPERTY_NAME_TIME_COMPARISON; static final int DEFAULT_IO_THREAD_COUNT; static final int DEFAULT_THREAD_COUNT; static final long DEFAULT_TIME_DRIFT_THRESHOLD_MICROS; }
@Test public void buildUUID() { CommandLineArgumentParser.parseFromProperties(this); Utils.setTimeDriftThreshold(TimeUnit.HOURS.toMicros(1)); try { Logger log = Logger.getAnonymousLogger(); String baseId = Utils.computeHash("some id"); Set<String> set = new ConcurrentSkipListSet<>(); int threadCount = Utils.DEFAULT_THREAD_COUNT; int iterations = this.iterationCount; log.info("Starting uniqueness check, thread count: " + threadCount); TestContext ctx = new TestContext(threadCount, Duration.ofSeconds(30)); for (int t = 0; t < threadCount; t++) { ForkJoinPool.commonPool().execute(() -> { for (int i = 0; i < iterations / threadCount; i++) { String value = Utils.buildUUID(baseId); if (!set.add(value)) { ctx.fail(new IllegalStateException("Duplicate: " + value)); } } ctx.complete(); }); } ctx.await(); set.clear(); System.gc(); int sum = 0; long start = System.nanoTime(); for (int i = 0; i < iterations; i++) { sum += Utils.buildUUID(baseId).length(); } long end = System.nanoTime(); log.info("iterations: " + iterations); log.info("Total chars: " + sum); double thpt = this.iterationCount / ((end - start) / 1000000000.0); log.info("Throughput (calls / sec): " + thpt); this.testResults.getReport().lastValue(TestResults.KEY_THROUGHPUT, thpt); } finally { Utils.setTimeDriftThreshold(Utils.DEFAULT_TIME_DRIFT_THRESHOLD_MICROS); } }