Skip to content

Commit

Permalink
Allow null values for healthcheck (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
krutsko committed Jun 11, 2021
1 parent 17ea7ca commit dc65995
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,15 @@ public Builder setHealthCheckUrls(String relativeUrl,
if (explicitUrl != null) {
result.healthCheckUrl = explicitUrl.replace(
hostNameInterpolationExpression, result.hostName);
} else if (result.isUnsecurePortEnabled) {
} else if (result.isUnsecurePortEnabled && relativeUrl != null) {
result.healthCheckUrl = HTTP_PROTOCOL + result.hostName + COLON
+ result.port + relativeUrl;
}

if (secureExplicitUrl != null) {
result.secureHealthCheckUrl = secureExplicitUrl.replace(
hostNameInterpolationExpression, result.hostName);
} else if (result.isSecurePortEnabled) {
} else if (result.isSecurePortEnabled && relativeUrl != null) {
result.secureHealthCheckUrl = HTTPS_PROTOCOL + result.hostName
+ COLON + result.securePort + relativeUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ public void testHealthCheckSetContainsValidUrlEntries() throws Exception {
assertThat(instanceInfo.getHealthCheckUrls().size(), is(equalTo(2)));
}

@Test
public void testNullUrlEntries() throws Exception {
Builder builder = newBuilder()
.setAppName("test")
.setNamespace("eureka.")
.setHostName("localhost")
.setPort(80)
.setSecurePort(443)
.setHealthCheckUrls(null, null, null)
.setStatusPageUrl(null, null)
.setHomePageUrl(null, null)
.enablePort(PortType.SECURE, true);

// No URLs for healthcheck , status , homepage
InstanceInfo noHealtcheckInstanceInfo = builder.build();
assertThat(noHealtcheckInstanceInfo.getHealthCheckUrls().size(), is(equalTo(0)));
assertThat(noHealtcheckInstanceInfo.getStatusPageUrl(), nullValue());
assertThat(noHealtcheckInstanceInfo.getHomePageUrl(), nullValue());
}

@Test
public void testGetIdWithInstanceIdUsed() {
InstanceInfo baseline = InstanceInfoGenerator.takeOne();
Expand Down

0 comments on commit dc65995

Please sign in to comment.