DATAGEODE-283 - Polish.

Resolves gh-32.
This commit is contained in:
John Blum
2019-12-13 12:32:15 -08:00
parent ebac373709
commit be37ee199b
2 changed files with 20 additions and 12 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
* where hostname is the network name or IP address of the host. * where hostname is the network name or IP address of the host.
* *
* @author John Blum * @author John Blum
* @author Jacob Barret
* @see java.lang.Cloneable * @see java.lang.Cloneable
* @see java.lang.Comparable * @see java.lang.Comparable
* @since 1.6.3 * @since 1.6.3
@@ -37,6 +38,8 @@ public class ConnectionEndpoint implements Cloneable, Comparable<ConnectionEndpo
protected static final int DEFAULT_PORT = 0; // ephemeral port protected static final int DEFAULT_PORT = 0; // ephemeral port
protected static final String DEFAULT_HOST = "localhost"; protected static final String DEFAULT_HOST = "localhost";
protected static final String GEMFIRE_HOST_PORT_SEPARATOR = "[";
protected static final String STANDARD_HOST_PORT_SEPARATOR = ":";
private final int port; private final int port;
private final String host; private final String host;
@@ -93,13 +96,10 @@ public class ConnectionEndpoint implements Cloneable, Comparable<ConnectionEndpo
} }
static int indexOfPort(String host) { static int indexOfPort(String host) {
for (int i = 0; i < host.length(); ++i) {
char c = host.charAt(i); int indexOfPort = host.indexOf(GEMFIRE_HOST_PORT_SEPARATOR);
if (':' == c || '[' == c) {
return i; return indexOfPort > -1 ? indexOfPort : host.indexOf(STANDARD_HOST_PORT_SEPARATOR);
}
}
return -1;
} }
static String parseDigits(String value) { static String parseDigits(String value) {

View File

@@ -26,6 +26,7 @@ import org.junit.Test;
* Unit Tests for {@link ConnectionEndpoint}. * Unit Tests for {@link ConnectionEndpoint}.
* *
* @author John Blum * @author John Blum
* @author Jacob Barret
* @see java.net.InetSocketAddress * @see java.net.InetSocketAddress
* @see org.junit.Test * @see org.junit.Test
* @see org.springframework.data.gemfire.support.ConnectionEndpoint * @see org.springframework.data.gemfire.support.ConnectionEndpoint
@@ -100,7 +101,7 @@ public class ConnectionEndpointUnitTests {
} }
@Test @Test
public void parseWithHostPortWithColon() { public void parseWithHostPortSeparatedByColon() {
ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.parse("skullbox:12345", 80); ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.parse("skullbox:12345", 80);
@@ -132,7 +133,7 @@ public class ConnectionEndpointUnitTests {
} }
@Test @Test
public void parseWithHostPortHavingSpacingWithColon() { public void parseWithHostPortHavingSpacingSeparatedByColon() {
ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.parse(" saturn :1 23 4 "); ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.parse(" saturn :1 23 4 ");
@@ -189,10 +190,10 @@ public class ConnectionEndpointUnitTests {
} }
@Test @Test
public void parseWithHostUsingDefaultPortWithColon() { public void parseWithHostUsingDefaultPortSeparatedByColon() {
ConnectionEndpoint connectionEndpoint = ConnectionEndpoint connectionEndpoint =
ConnectionEndpoint.parse("mercury:oneTwoThreeFourFive", 80); ConnectionEndpoint.parse("mercury:oneTwoThreeFourFive", 80);
assertThat(connectionEndpoint).isNotNull(); assertThat(connectionEndpoint).isNotNull();
assertThat(connectionEndpoint.getHost()).isEqualTo("mercury"); assertThat(connectionEndpoint.getHost()).isEqualTo("mercury");
@@ -246,7 +247,7 @@ public class ConnectionEndpointUnitTests {
} }
@Test @Test
public void parseWithPortUsingDefaultHostWithColon() { public void parseWithPortUsingDefaultHostSeparatedByColon() {
ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.parse(":12345", 80); ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.parse(":12345", 80);
@@ -317,7 +318,9 @@ public class ConnectionEndpointUnitTests {
@Test @Test
public void indexOfPort() { public void indexOfPort() {
assertThat(ConnectionEndpoint.indexOfPort("")).isEqualTo(-1); assertThat(ConnectionEndpoint.indexOfPort("")).isEqualTo(-1);
assertThat(ConnectionEndpoint.indexOfPort(" ")).isEqualTo(-1);
assertThat(ConnectionEndpoint.indexOfPort("a")).isEqualTo(-1); assertThat(ConnectionEndpoint.indexOfPort("a")).isEqualTo(-1);
assertThat(ConnectionEndpoint.indexOfPort(":")).isEqualTo(0); assertThat(ConnectionEndpoint.indexOfPort(":")).isEqualTo(0);
assertThat(ConnectionEndpoint.indexOfPort("a:")).isEqualTo(1); assertThat(ConnectionEndpoint.indexOfPort("a:")).isEqualTo(1);
@@ -325,6 +328,11 @@ public class ConnectionEndpointUnitTests {
assertThat(ConnectionEndpoint.indexOfPort("a:b")).isEqualTo(1); assertThat(ConnectionEndpoint.indexOfPort("a:b")).isEqualTo(1);
assertThat(ConnectionEndpoint.indexOfPort("ab:")).isEqualTo(2); assertThat(ConnectionEndpoint.indexOfPort("ab:")).isEqualTo(2);
assertThat(ConnectionEndpoint.indexOfPort("ab:c")).isEqualTo(2); assertThat(ConnectionEndpoint.indexOfPort("ab:c")).isEqualTo(2);
}
@Test
@SuppressWarnings("all")
public void indexOfPortWithNull() {
assertThatThrownBy(() -> ConnectionEndpoint.indexOfPort(null)).isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ConnectionEndpoint.indexOfPort(null)).isInstanceOf(NullPointerException.class);
} }