Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
@@ -123,17 +123,27 @@ public class ConfigServerConfigDataResource extends ConfigDataResource {
|
||||
}
|
||||
|
||||
private boolean uriEqual(String thisUriString, String thatUriString) {
|
||||
UriComponents thisUri = UriComponentsBuilder.fromHttpUrl(thisUriString).build();
|
||||
UriComponents thatUri = UriComponentsBuilder.fromHttpUrl(thatUriString).build();
|
||||
return Objects.equals(thisUri.getHost(), thatUri.getHost())
|
||||
&& Objects.equals(thisUri.getPort(), thatUri.getPort())
|
||||
&& Objects.equals(thisUri.getPath(), thatUri.getPath());
|
||||
try {
|
||||
UriComponents thisUri = UriComponentsBuilder.fromHttpUrl(thisUriString).build();
|
||||
UriComponents thatUri = UriComponentsBuilder.fromHttpUrl(thatUriString).build();
|
||||
return Objects.equals(thisUri.getHost(), thatUri.getHost())
|
||||
&& Objects.equals(thisUri.getPort(), thatUri.getPort())
|
||||
&& Objects.equals(thisUri.getPath(), thatUri.getPath());
|
||||
}
|
||||
catch (Exception e) {
|
||||
return Objects.equals(thisUriString, thatUriString);
|
||||
}
|
||||
}
|
||||
|
||||
private int urisHashCode(String[] uris) {
|
||||
return Arrays.stream(uris).mapToInt(uriString -> {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(uriString).build();
|
||||
return Objects.hash(uriComponents.getHost(), uriComponents.getPath(), uriComponents.getPort());
|
||||
try {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(uriString).build();
|
||||
return Objects.hash(uriComponents.getHost(), uriComponents.getPath(), uriComponents.getPort());
|
||||
}
|
||||
catch (Exception e) {
|
||||
return Arrays.hashCode(uris);
|
||||
}
|
||||
}).sum();
|
||||
}
|
||||
|
||||
|
||||
@@ -318,4 +318,15 @@ class ConfigServerConfigDataResourceTests {
|
||||
assertThat(r1.hashCode()).isNotEqualTo(r2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidUri() {
|
||||
ConfigClientProperties r1Properties = new ConfigClientProperties();
|
||||
r1Properties.setUri(new String[] { "//" });
|
||||
ConfigServerConfigDataResource r1 = new ConfigServerConfigDataResource(r1Properties, true, null);
|
||||
ConfigClientProperties r2Properties = new ConfigClientProperties();
|
||||
r2Properties.setUri(new String[] { "//" });
|
||||
ConfigServerConfigDataResource r2 = new ConfigServerConfigDataResource(r2Properties, true, null);
|
||||
assertThat(r1).isEqualTo(r2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user