Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -150,6 +151,26 @@ public void setExtensions(List<String> extensions) {
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 + ", "
Expand All @@ -158,6 +179,23 @@ public String toString() {

}

@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 + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
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;
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;

/**
Expand Down Expand Up @@ -90,4 +94,22 @@ private void assertBookieServiceInfoEquals(BookieServiceInfo expected, BookieSer
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);
}

}
Loading