This is an automated email from the ASF dual-hosted git repository.
jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 78d4e56293 GEODE-10254: Use original hostname if host is null. (#7618)
78d4e56293 is described below
commit 78d4e56293c2b60be188928ce0fea2af302b6c2c
Author: Jacob Barrett <[email protected]>
AuthorDate: Mon Apr 25 09:53:10 2022 -0700
GEODE-10254: Use original hostname if host is null. (#7618)
If original hostname was not resolvable then host is null. Use hostname
if host is null when marshaling.
---
.../admin/remote/DistributionLocatorId.java | 4 +++-
.../admin/remote/DistributionLocatorIdTest.java | 21 ++++++++++++++-------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java
b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java
index 8b890489bc..abf5bce370 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/admin/remote/DistributionLocatorId.java
@@ -248,12 +248,14 @@ public class DistributionLocatorId implements
java.io.Serializable {
sb.append(hostnameForClients);
} else if (!isEmpty(bindAddress)) {
sb.append(bindAddress);
- } else {
+ } else if (null != host) {
if (isMcastId()) {
sb.append(host.getHostAddress());
} else {
sb.append(SocketCreator.getHostName(host));
}
+ } else {
+ sb.append(hostname);
}
sb.append("[").append(port).append("]");
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/admin/remote/DistributionLocatorIdTest.java
b/geode-core/src/test/java/org/apache/geode/internal/admin/remote/DistributionLocatorIdTest.java
index 4e1b9b149c..f7bf9f2e95 100644
---
a/geode-core/src/test/java/org/apache/geode/internal/admin/remote/DistributionLocatorIdTest.java
+++
b/geode-core/src/test/java/org/apache/geode/internal/admin/remote/DistributionLocatorIdTest.java
@@ -15,6 +15,7 @@
package org.apache.geode.internal.admin.remote;
+import static
org.apache.geode.internal.admin.remote.DistributionLocatorId.unmarshal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.Mockito.mock;
@@ -56,7 +57,7 @@ class DistributionLocatorIdTest {
DistributionLocatorId distributionLocatorId3 =
new DistributionLocatorId(40404, "127.0.0.1", null, "member3");
DistributionLocatorId distributionLocatorId4 =
- DistributionLocatorId.unmarshal(distributionLocatorId3.marshal());
+ unmarshal(distributionLocatorId3.marshal());
assertThat(distributionLocatorId1).isEqualTo(distributionLocatorId2);
assertThat(distributionLocatorId1).isEqualTo(distributionLocatorId3);
@@ -74,10 +75,17 @@ class DistributionLocatorIdTest {
}
@Test
- void marshalForClientsMarshaledAddressWhenConstructedWithMarshaledAddress() {
- final DistributionLocatorId locatorId =
DistributionLocatorId.unmarshal("localhost[1234]");
+ void
marshalForClientsReturnsOriginalHostnameWhenUnmarshalledHostnameIsResolvable() {
+ final String marshalled = "localhost[1234]";
+ final DistributionLocatorId locatorId = unmarshal(marshalled);
+ assertThat(locatorId.marshalForClients()).isEqualTo(marshalled);
+ }
- assertThat(locatorId.marshalForClients()).isEqualTo("localhost[1234]");
+ @Test
+ void
marshalForClientsReturnsOriginalHostnameWhenUnmarshalledHostnameIsNotResolvable()
{
+ final String marshalled = "unknown.invalid[1234]";
+ final DistributionLocatorId locatorId = unmarshal(marshalled);
+ assertThat(locatorId.marshalForClients()).isEqualTo(marshalled);
}
@Test
@@ -142,9 +150,8 @@ class DistributionLocatorIdTest {
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
- void hashCodeDoesNotThrowWhenHostIsNull() {
- final DistributionLocatorId locatorId =
- DistributionLocatorId.unmarshal("unknown.invalid[1234]");
+ void hashCodeDoesNotThrowWhenHostnameIsNotResolvable() {
+ final DistributionLocatorId locatorId = unmarshal("unknown.invalid[1234]");
assertThatNoException().isThrownBy(locatorId::hashCode);
}
}