@@ -89,7 +89,7 @@ public class ServerPropertiesHostLocator implements HostLocator {
|
||||
return this.port;
|
||||
}
|
||||
Integer port;
|
||||
if (this.serverProperties != null && this.serverProperties.getPort() != null) {
|
||||
if (this.serverProperties != null && this.serverProperties.getPort() != null && this.serverProperties.getPort() > 0) {
|
||||
port = this.serverProperties.getPort();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -89,6 +89,17 @@ public class ServerPropertiesHostLocatorTests {
|
||||
assertThat(locator.locate(this.span).getServiceName()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativePortFromServerProperties() throws UnknownHostException {
|
||||
ServerProperties properties = new ServerProperties();
|
||||
properties.setPort(-1);
|
||||
|
||||
ServerPropertiesHostLocator locator = new ServerPropertiesHostLocator(properties,
|
||||
"unknown", new ZipkinProperties(),localAddress(ADR1234));
|
||||
|
||||
assertThat(locator.locate(this.span).getPort()).isEqualTo((short) 8080);
|
||||
}
|
||||
|
||||
private InetUtils localAddress(byte[] address) throws UnknownHostException {
|
||||
InetUtils mocked = Mockito.spy(new InetUtils(new InetUtilsProperties()));
|
||||
Mockito.when(mocked.findFirstNonLoopbackAddress())
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ServerPropertiesEndpointLocator implements EndpointLocator {
|
||||
return this.port;
|
||||
}
|
||||
Integer port;
|
||||
if (this.serverProperties!=null && this.serverProperties.getPort() != null) {
|
||||
if (this.serverProperties!=null && this.serverProperties.getPort() != null && this.serverProperties.getPort() > 0) {
|
||||
port = this.serverProperties.getPort();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -83,6 +83,17 @@ public class ServerPropertiesEndpointLocatorTests {
|
||||
assertThat(locator.local().serviceName).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativePortFromServerProperties() throws UnknownHostException {
|
||||
ServerProperties properties = new ServerProperties();
|
||||
properties.setPort(-1);
|
||||
|
||||
ServerPropertiesEndpointLocator locator = new ServerPropertiesEndpointLocator(
|
||||
properties, "unknown", new ZipkinProperties(),localAddress(ADDRESS1234));
|
||||
|
||||
assertThat(locator.local().port).isEqualTo((short) 8080);
|
||||
}
|
||||
|
||||
private InetUtils localAddress(byte[] address) throws UnknownHostException {
|
||||
InetUtils mocked = Mockito.spy(new InetUtils(new InetUtilsProperties()));
|
||||
Mockito.when(mocked.findFirstNonLoopbackAddress())
|
||||
|
||||
Reference in New Issue
Block a user