From 868100c79cf6acf7c66d728a8c30e6bcb50ff6f4 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 17 Mar 2015 16:03:41 -0700 Subject: [PATCH] Add consistency to UUIDUtils handling * Use "_" instead of "-" --- .../main/java/io/druid/common/utils/UUIDUtils.java | 4 ++-- .../java/io/druid/common/utils/UUIDUtilsTest.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/io/druid/common/utils/UUIDUtils.java b/common/src/main/java/io/druid/common/utils/UUIDUtils.java index a8412f07e37..2f7f6cea238 100644 --- a/common/src/main/java/io/druid/common/utils/UUIDUtils.java +++ b/common/src/main/java/io/druid/common/utils/UUIDUtils.java @@ -28,7 +28,7 @@ import java.util.UUID; */ public class UUIDUtils { - public static final String UUID_DELIM = "-"; + public static final String UUID_DELIM = "_"; /** * Generates a universally unique identifier. @@ -51,7 +51,7 @@ public class UUIDUtils extra = Joiner.on(UUID_DELIM).join(extraStrings); } } - final String uuid = UUID.randomUUID().toString(); + final String uuid = UUID.randomUUID().toString().replace("-", ""); // We don't use "-" in general, so remove them here. return extra == null ? uuid : (extra + UUID_DELIM + uuid); } } diff --git a/common/src/test/java/io/druid/common/utils/UUIDUtilsTest.java b/common/src/test/java/io/druid/common/utils/UUIDUtilsTest.java index 06656de73b5..bf420a21b27 100644 --- a/common/src/test/java/io/druid/common/utils/UUIDUtilsTest.java +++ b/common/src/test/java/io/druid/common/utils/UUIDUtilsTest.java @@ -91,8 +91,15 @@ public class UUIDUtilsTest String uuidString ) { - UUID uuid = UUID.fromString(uuidString); - Assert.assertEquals(uuid.toString(), uuidString); + // Since we strip the "-" from the string, we need to break them back out + final ArrayList strings = new ArrayList<>(); + strings.add(uuidString.substring(0, 8)); + strings.add(uuidString.substring(8, 12)); + strings.add(uuidString.substring(12, 16)); + strings.add(uuidString.substring(16, 20)); + strings.add(uuidString.substring(20, 32)); + UUID uuid = UUID.fromString(Joiner.on('-').join(strings)); + Assert.assertEquals(uuid.toString().replace("-", ""), uuidString); } @Test