Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ public Version withConnection(HttpURLConnection connection) {
return null;
}
});
versions.remove(null);
return getMinVersionOrUnknown(versions);
}

static Version getMinVersionOrUnknown(List<Version> versions) {
while (versions.remove(null)) {
// remove all unavailable server results before comparing versions
}
if (!versions.isEmpty()) {
return Collections.min(versions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -39,4 +42,25 @@ void testParseVersion() throws IOException {
body = "{\"ok\":{\"build_date\":\"2021-10-13T17:29:41Z\",\"build_sha\":\"04a84d8d3d0358af5e73b3581c4ba37fbdbc979e\",\"version\":\"6.8.20\"}}";
assertThat(ApmServerHealthChecker.parseVersion(body).compareTo(Version.of("6.8.20"))).isEqualTo(0);
}

@Test
void testMinVersionIgnoresUnavailableServers() {
List<Version> versions = new ArrayList<>(Arrays.asList(
Version.of("8.0.0"),
null,
Version.of("7.17.0"),
null
));

assertThat(ApmServerHealthChecker.getMinVersionOrUnknown(versions))
.isEqualTo(Version.of("7.17.0"));
}

@Test
void testMinVersionReturnsUnknownWhenAllServersUnavailable() {
List<Version> versions = new ArrayList<>(Arrays.asList(null, null));

assertThat(ApmServerHealthChecker.getMinVersionOrUnknown(versions))
.isEqualTo(ApmServerHealthChecker.UNKNOWN_VERSION);
}
}
Loading