You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/10/20 15:16:45 UTC

[GitHub] [kafka] jolshan commented on a change in pull request #9454: KAFKA-10618: Add UUID class, use in protocols

jolshan commented on a change in pull request #9454:
URL: https://github.com/apache/kafka/pull/9454#discussion_r508597656



##########
File path: clients/src/test/java/org/apache/kafka/common/UUIDTest.java
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.common;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class UUIDTest {
+
+    @Test
+    public void testSignificantBits() {
+        UUID id = new UUID(34L, 98L);
+
+        assertEquals(id.getMostSignificantBits(), 34L);
+        assertEquals(id.getLeastSignificantBits(), 98L);
+    }
+
+    @Test
+    public void testUUIDEquality() {
+        UUID id1 = new UUID(12L, 13L);
+        UUID id2 = new UUID(12L, 13L);
+        UUID id3 = new UUID(24L, 38L);
+
+        assertEquals(UUID.ZERO_UUID, UUID.ZERO_UUID);
+        assertEquals(id1, id2);
+        assertNotEquals(id1, id3);
+
+        assertEquals(UUID.ZERO_UUID.hashCode(), UUID.ZERO_UUID.hashCode());
+        assertEquals(id1.hashCode(), id2.hashCode());
+        assertNotEquals(id1.hashCode(), id3.hashCode());
+    }
+
+    @Test
+    public void testStringConversion() {
+        UUID id = UUID.randomUUID();

Review comment:
       I thought about that, but since the likelihood we would get the zero/sentinel id is so low even if they were allowed, I didn't know if the test would be useful. The sentinel ID is also a private variable, but I suppose I could just construct a new one if we want to test. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org