Skip to content

Commit

Permalink
rh-che eclipse-che#500: Adding 'successThreshold' property to server …
Browse files Browse the repository at this point in the history
…checkers. Introduce wsagent ping success threshold

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
  • Loading branch information
ibuziuk committed Jan 26, 2018
1 parent 0c78fa9 commit f8763dd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public HttpConnectionServerChecker(
String serverRef,
long period,
long timeout,
int successThreshold,
TimeUnit timeUnit,
Timer timer) {
super(machineName, serverRef, period, timeout, timeUnit, timer);
super(machineName, serverRef, period, timeout, successThreshold, timeUnit, timer);
this.url = url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public abstract class ServerChecker {
private final String serverRef;
private final long period;
private final long deadLine;
private final int successThreshold;
private final CompletableFuture<String> reportFuture;
private final Timer timer;

Expand All @@ -37,6 +38,8 @@ public abstract class ServerChecker {
* @param machineName name of machine to whom the server belongs
* @param serverRef reference of the server
* @param period period between unsuccessful availability checks, measured in {@code timeUnit}
* @param successThreshold number of sequential successful pings of server after which it is
* treated as available
* @param timeout max time allowed for the server availability checks to last before server is
* treated unavailable, measured in {@code timeUnit}
* @param timeUnit measurement unit for {@code period} and {@code timeout} parameters
Expand All @@ -46,10 +49,12 @@ protected ServerChecker(
String serverRef,
long period,
long timeout,
int successThreshold,
TimeUnit timeUnit,
Timer timer) {
this.machineName = machineName;
this.serverRef = serverRef;
this.successThreshold = successThreshold;
this.timer = timer;
this.period = TimeUnit.MILLISECONDS.convert(period, timeUnit);
this.reportFuture = new CompletableFuture<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ ServerChecker doCreateChecker(URL url, String serverRef) {
// workaround needed because terminal server doesn't have endpoint to check it readiness
if ("terminal".equals(serverRef)) {
return new TerminalHttpConnectionServerChecker(
url, machineName, serverRef, 3, 180, TimeUnit.SECONDS, timer);
url, machineName, serverRef, 3, 180, 1, TimeUnit.SECONDS, timer);
}
// TODO do not hardcode timeouts, use server conf instead
return new HttpConnectionServerChecker(
url, machineName, serverRef, 3, 180, TimeUnit.SECONDS, timer);
url, machineName, serverRef, 3, 180, 1, TimeUnit.SECONDS, timer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class TerminalHttpConnectionServerChecker extends HttpConnectionServerChecker {
String serverRef,
long period,
long timeout,
int successThreshold,
TimeUnit timeUnit,
Timer timer) {
super(url, machineName, serverRef, period, timeout, timeUnit, timer);
super(url, machineName, serverRef, period, timeout, successThreshold, timeUnit, timer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setUp() throws Exception {
checker =
spy(
new HttpConnectionServerChecker(
SERVER_URL, MACHINE_NAME, SERVER_REF, 1, 10, TimeUnit.SECONDS, timer));
SERVER_URL, MACHINE_NAME, SERVER_REF, 1, 10, 1, TimeUnit.SECONDS, timer));

doReturn(conn).when(checker).createConnection(nullable(URL.class));
when(conn.getResponseCode()).thenReturn(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TerminalHttpConnectionServerCheckerTest {
public void setUp() throws Exception {
checker =
new TerminalHttpConnectionServerChecker(
new URL("http://localhost"), MACHINE_NAME, SERVER_REF, 1, 10, TimeUnit.SECONDS, timer);
new URL("http://localhost"), MACHINE_NAME, SERVER_REF, 1, 10, 1, TimeUnit.SECONDS, timer);
}

@Test
Expand Down

0 comments on commit f8763dd

Please sign in to comment.