This is an automated email from the ASF dual-hosted git repository.

chenhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 14c2ffe07d feat: support `equalsAndHashcode` for BookieServerInfo 
(#4686)
14c2ffe07d is described below

commit 14c2ffe07d7258e765081634b2bd6788edf4286f
Author: Qiang Zhao <[email protected]>
AuthorDate: Tue Nov 25 09:16:01 2025 +0800

    feat: support `equalsAndHashcode` for BookieServerInfo (#4686)
    
    * feat: support equalsAndHashcode for BookieServerInfo
    
    Signed-off-by: mattisonchao <[email protected]>
    
    * change order
    
    * fix checkstyle
    
    * fix checkstyle
    
    ---------
    
    Signed-off-by: mattisonchao <[email protected]>
---
 .../bookkeeper/discover/BookieServiceInfo.java     | 38 ++++++++++++++++++++++
 .../bookkeeper/discover/BookieServiceInfoTest.java | 22 +++++++++++++
 2 files changed, 60 insertions(+)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/discover/BookieServiceInfo.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/discover/BookieServiceInfo.java
index 8b23a70143..c465938311 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/discover/BookieServiceInfo.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/discover/BookieServiceInfo.java
@@ -20,6 +20,7 @@ package org.apache.bookkeeper.discover;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.function.Supplier;
 
 /**
@@ -150,6 +151,26 @@ public final class BookieServiceInfo {
             this.extensions = extensions;
         }
 
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (!(o instanceof Endpoint)) {
+                return false;
+            }
+            final Endpoint endpoint = (Endpoint) o;
+            return port == endpoint.port && Objects.equals(id, endpoint.id) && 
Objects.equals(host, endpoint.host)
+                    && Objects.equals(protocol, endpoint.protocol) && 
Objects.equals(auth, endpoint.auth)
+                    && Objects.equals(extensions, endpoint.extensions);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(id, port, host, protocol, auth, extensions);
+        }
+
         @Override
         public String toString() {
             return "EndpointInfo{" + "id=" + id + ", port=" + port + ", host=" 
+ host + ", protocol=" + protocol + ", "
@@ -158,6 +179,23 @@ public final class BookieServiceInfo {
 
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof BookieServiceInfo)) {
+            return false;
+        }
+        final BookieServiceInfo that = (BookieServiceInfo) o;
+        return Objects.equals(properties, that.properties) && 
Objects.equals(endpoints, that.endpoints);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(properties, endpoints);
+    }
+
     @Override
     public String toString() {
         return "BookieServiceInfo{" + "properties=" + properties + ", 
endpoints=" + endpoints + '}';
diff --git 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/discover/BookieServiceInfoTest.java
 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/discover/BookieServiceInfoTest.java
index 4173d63000..3bbda71c51 100644
--- 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/discover/BookieServiceInfoTest.java
+++ 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/discover/BookieServiceInfoTest.java
@@ -22,6 +22,9 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -29,6 +32,7 @@ import java.util.Map;
 import java.util.Objects;
 import org.apache.bookkeeper.discover.BookieServiceInfo.Endpoint;
 import org.apache.bookkeeper.net.BookieId;
+import org.junit.Assert;
 import org.junit.Test;
 
 /**
@@ -90,4 +94,22 @@ public class BookieServiceInfoTest {
         assertEquals(expected.getProperties(), provided.getProperties());
     }
 
+    @Test
+    public void testComparableBookieServerInfo() throws Exception {
+        final BookieServiceInfo.Endpoint endpoint = new 
BookieServiceInfo.Endpoint(
+                "http", 8080, "host1", "HTTP",
+                Lists.newArrayList("auth1"), Lists.newArrayList("ext1")
+        );
+        final Map<String, String> properties1 = Maps.newHashMap();
+        properties1.put("key", "value");
+        final BookieServiceInfo info = new BookieServiceInfo(
+                properties1,
+                Lists.newArrayList(endpoint)
+        );
+        final ObjectMapper objectMapper = new ObjectMapper();
+        final String bData = objectMapper.writeValueAsString(info);
+        final BookieServiceInfo another = objectMapper.readValue(bData, 
BookieServiceInfo.class);
+        Assert.assertEquals(info, another);
+    }
+
 }

Reply via email to