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 10:51:46 UTC

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

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



##########
File path: clients/src/main/java/org/apache/kafka/common/protocol/types/Type.java
##########
@@ -331,14 +331,14 @@ public String documentation() {
     public static final DocumentedType UUID = new DocumentedType() {
         @Override
         public void write(ByteBuffer buffer, Object o) {
-            final java.util.UUID uuid = (java.util.UUID) o;
+            final org.apache.kafka.common.UUID uuid = (org.apache.kafka.common.UUID) o;

Review comment:
       We have already imported UUID, do we need to qualify here? I can see it was this way before, but not sure why.

##########
File path: clients/src/main/java/org/apache/kafka/common/protocol/types/Type.java
##########
@@ -331,14 +331,14 @@ public String documentation() {
     public static final DocumentedType UUID = new DocumentedType() {
         @Override
         public void write(ByteBuffer buffer, Object o) {
-            final java.util.UUID uuid = (java.util.UUID) o;
+            final org.apache.kafka.common.UUID uuid = (org.apache.kafka.common.UUID) o;
             buffer.putLong(uuid.getMostSignificantBits());
             buffer.putLong(uuid.getLeastSignificantBits());
         }
 
         @Override
         public Object read(ByteBuffer buffer) {
-            return new java.util.UUID(buffer.getLong(), buffer.getLong());
+            return new org.apache.kafka.common.UUID(buffer.getLong(), buffer.getLong());

Review comment:
       Same as before, why don't we just use `UUID` since package was imported?

##########
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:
       Should we have a separate unit test for `UUID.randomUUID` to verify it is not zero or the sentinel?




----------------------------------------------------------------
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