private void executeSleep(Sleep sleep) { final long milliseconds = Timespan.toMilliseconds(sleep.value()); try { TimeUnit.MILLISECONDS.sleep(milliseconds); } catch (InterruptedException e) { throw new RuntimeException(e); } }
private void executeSleep(Sleep sleep) { final long milliseconds = Timespan.toMilliseconds(sleep.value()); try { TimeUnit.MILLISECONDS.sleep(milliseconds); } catch (InterruptedException e) { throw new RuntimeException(e); } }
private boolean executeHealthCheck(HealthCheck healthCheck) { final URL url = buildUrl(healthCheck); final int pollIterations = healthCheck.iterations(); final long sleepTime = Timespan.toMilliseconds(healthCheck.interval()); final int responseCode = healthCheck.responseCode(); final String method = healthCheck.method(); final Long connectTimeout = Timespan.toMilliseconds(healthCheck.timeout()); return Ping.ping(pollIterations, sleepTime, TimeUnit.MILLISECONDS, () -> { HttpURLConnection urlConnection = null; try { urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod(method); urlConnection.setConnectTimeout(connectTimeout.intValue()); urlConnection.setReadTimeout(connectTimeout.intValue()); urlConnection.connect(); int connectionResponseCode = urlConnection.getResponseCode(); if (responseCode != connectionResponseCode) { return false; } } catch (IOException e) { return false; } finally { if (urlConnection != null) { urlConnection.disconnect(); } } return true; }); }
private boolean executeHealthCheck(HealthCheck healthCheck) { final URL url = buildUrl(healthCheck); final int pollIterations = healthCheck.iterations(); final long sleepTime = Timespan.toMilliseconds(healthCheck.interval()); final int responseCode = healthCheck.responseCode(); final String method = healthCheck.method(); final Long connectTimeout = Timespan.toMilliseconds(healthCheck.timeout()); return Ping.ping(pollIterations, sleepTime, TimeUnit.MILLISECONDS, () -> { HttpURLConnection urlConnection = null; try { urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod(method); urlConnection.setConnectTimeout(connectTimeout.intValue()); urlConnection.setReadTimeout(connectTimeout.intValue()); urlConnection.connect(); int connectionResponseCode = urlConnection.getResponseCode(); if (responseCode != connectionResponseCode) { return false; } } catch (IOException e) { return false; } finally { if (urlConnection != null) { urlConnection.disconnect(); } } return true; }); }
@Test public void should_transform_from_seconds_and_minutes_string_to_milliseconds() { final long milliseconds = Timespan.toMilliseconds("1m30s"); assertThat(milliseconds, is(90000L)); }
@Test public void should_transform_from_milliseconds_string_to_milleseconds() { final long milliseconds = Timespan.toMilliseconds("250ms"); assertThat(milliseconds, is(250L)); }