kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [kafka] branch trunk updated: KAFKA-8643; Bring back public MemberDescription constructor (#7060)
Date Fri, 12 Jul 2019 04:54:56 GMT
This is an automated email from the ASF dual-hosted git repository.

jgus pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 25f4e3c  KAFKA-8643; Bring back public MemberDescription constructor (#7060)
25f4e3c is described below

commit 25f4e3c7d4a50a55e3d66ea479e40a38c841ba39
Author: Boyang Chen <boyang@confluent.io>
AuthorDate: Thu Jul 11 21:54:34 2019 -0700

    KAFKA-8643; Bring back public MemberDescription constructor (#7060)
    
    This patch fixes a compatibility breaking `MemberDescription` constructor change in #6957.
It also updates `equals` and `hashCode` for the new `groupInstanceId` field that was added
in the same patch.
    
    Reviewers: Ismael Juma <ismael@juma.me.uk>, Jason Gustafson <jason@confluent.io>
---
 .../kafka/clients/admin/MemberDescription.java     |  20 ++--
 .../kafka/clients/admin/MemberDescriptionTest.java | 102 +++++++++++++++++++++
 2 files changed, 116 insertions(+), 6 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/clients/admin/MemberDescription.java b/clients/src/main/java/org/apache/kafka/clients/admin/MemberDescription.java
index 5d66227..7bc6b14 100644
--- a/clients/src/main/java/org/apache/kafka/clients/admin/MemberDescription.java
+++ b/clients/src/main/java/org/apache/kafka/clients/admin/MemberDescription.java
@@ -30,11 +30,11 @@ public class MemberDescription {
     private final String host;
     private final MemberAssignment assignment;
 
-    MemberDescription(String memberId,
-                      Optional<String> groupInstanceId,
-                      String clientId,
-                      String host,
-                      MemberAssignment assignment) {
+    public MemberDescription(String memberId,
+                             Optional<String> groupInstanceId,
+                             String clientId,
+                             String host,
+                             MemberAssignment assignment) {
         this.memberId = memberId == null ? "" : memberId;
         this.groupInstanceId = groupInstanceId;
         this.clientId = clientId == null ? "" : clientId;
@@ -43,6 +43,12 @@ public class MemberDescription {
             new MemberAssignment(Collections.emptySet()) : assignment;
     }
 
+    public MemberDescription(String memberId,
+                             String clientId,
+                             String host,
+                             MemberAssignment assignment) {
+        this(memberId, Optional.empty(), clientId, host, assignment);
+    }
 
     @Override
     public boolean equals(Object o) {
@@ -50,6 +56,7 @@ public class MemberDescription {
         if (o == null || getClass() != o.getClass()) return false;
         MemberDescription that = (MemberDescription) o;
         return memberId.equals(that.memberId) &&
+            groupInstanceId.equals(that.groupInstanceId) &&
             clientId.equals(that.clientId) &&
             host.equals(that.host) &&
             assignment.equals(that.assignment);
@@ -57,7 +64,7 @@ public class MemberDescription {
 
     @Override
     public int hashCode() {
-        return Objects.hash(memberId, clientId, host, assignment);
+        return Objects.hash(memberId, groupInstanceId, clientId, host, assignment);
     }
 
     /**
@@ -98,6 +105,7 @@ public class MemberDescription {
     @Override
     public String toString() {
         return "(memberId=" + memberId +
+            ", groupInstanceId=" + groupInstanceId.orElse("null") +
             ", clientId=" + clientId +
             ", host=" + host +
             ", assignment=" + assignment + ")";
diff --git a/clients/src/test/java/org/apache/kafka/clients/admin/MemberDescriptionTest.java
b/clients/src/test/java/org/apache/kafka/clients/admin/MemberDescriptionTest.java
new file mode 100644
index 0000000..be30975
--- /dev/null
+++ b/clients/src/test/java/org/apache/kafka/clients/admin/MemberDescriptionTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.TopicPartition;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class MemberDescriptionTest {
+
+    private static final String MEMBER_ID = "member_id";
+    private static final Optional<String> INSTANCE_ID = Optional.of("instanceId");
+    private static final String CLIENT_ID = "client_id";
+    private static final String HOST = "host";
+    private static final MemberAssignment ASSIGNMENT;
+    private static final MemberDescription STATIC_MEMBER_DESCRIPTION;
+
+    static {
+        ASSIGNMENT = new MemberAssignment(Collections.singleton(new TopicPartition("topic",
1)));
+        STATIC_MEMBER_DESCRIPTION = new MemberDescription(MEMBER_ID,
+                                                          INSTANCE_ID,
+                                                          CLIENT_ID,
+                                                          HOST,
+                                                          ASSIGNMENT);
+    }
+
+    @Test
+    public void testEqualsWithoutGroupInstanceId() {
+        MemberDescription dynamicMemberDescription = new MemberDescription(MEMBER_ID,
+                                                                           CLIENT_ID,
+                                                                           HOST,
+                                                                           ASSIGNMENT);
+
+        MemberDescription identityDescription = new MemberDescription(MEMBER_ID,
+                                                                      CLIENT_ID,
+                                                                      HOST,
+                                                                      ASSIGNMENT);
+
+        assertNotEquals(STATIC_MEMBER_DESCRIPTION, dynamicMemberDescription);
+        assertNotEquals(STATIC_MEMBER_DESCRIPTION.hashCode(), dynamicMemberDescription.hashCode());
+
+        // Check self equality.
+        assertEquals(dynamicMemberDescription, dynamicMemberDescription);
+        assertEquals(dynamicMemberDescription, identityDescription);
+        assertEquals(dynamicMemberDescription.hashCode(), identityDescription.hashCode());
+    }
+
+    @Test
+    public void testEqualsWithGroupInstanceId() {
+        // Check self equality.
+        assertEquals(STATIC_MEMBER_DESCRIPTION, STATIC_MEMBER_DESCRIPTION);
+
+        MemberDescription identityDescription = new MemberDescription(MEMBER_ID,
+                                                                      INSTANCE_ID,
+                                                                      CLIENT_ID,
+                                                                      HOST,
+                                                                      ASSIGNMENT);
+
+        assertEquals(STATIC_MEMBER_DESCRIPTION, identityDescription);
+        assertEquals(STATIC_MEMBER_DESCRIPTION.hashCode(), identityDescription.hashCode());
+    }
+
+    @Test
+    public void testNonEqual() {
+        MemberDescription newMemberDescription = new MemberDescription("new_member",
+                                                                       INSTANCE_ID,
+                                                                       CLIENT_ID,
+                                                                       HOST,
+                                                                       ASSIGNMENT);
+
+        assertNotEquals(STATIC_MEMBER_DESCRIPTION, newMemberDescription);
+        assertNotEquals(STATIC_MEMBER_DESCRIPTION.hashCode(), newMemberDescription.hashCode());
+
+        MemberDescription newInstanceDescription = new MemberDescription(MEMBER_ID,
+                                                                         Optional.of("new_instance"),
+                                                                         CLIENT_ID,
+                                                                         HOST,
+                                                                         ASSIGNMENT);
+
+        assertNotEquals(STATIC_MEMBER_DESCRIPTION, newInstanceDescription);
+        assertNotEquals(STATIC_MEMBER_DESCRIPTION.hashCode(), newInstanceDescription.hashCode());
+    }
+}


Mime
View raw message