diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/PeriodThrottler.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/PeriodThrottler.java index 3985d7da59c..34f4af70b83 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/PeriodThrottler.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/PeriodThrottler.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.xpack.core.watcher.actions.ActionStatus; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; -import org.joda.time.PeriodType; import java.time.Clock; @@ -22,16 +21,10 @@ import static org.elasticsearch.xpack.core.watcher.actions.throttler.Throttler.T public class PeriodThrottler implements Throttler { @Nullable private final TimeValue period; - private final PeriodType periodType; private final Clock clock; public PeriodThrottler(Clock clock, TimeValue period) { - this(clock, period, PeriodType.minutes()); - } - - public PeriodThrottler(Clock clock, TimeValue period, PeriodType periodType) { this.period = period; - this.periodType = periodType; this.clock = clock; } @@ -57,7 +50,7 @@ public class PeriodThrottler implements Throttler { TimeValue timeElapsed = TimeValue.timeValueMillis(clock.millis() - status.lastSuccessfulExecution().timestamp().getMillis()); if (timeElapsed.getMillis() <= period.getMillis()) { return Result.throttle(PERIOD, "throttling interval is set to [{}] but time elapsed since last execution is [{}]", - period.format(periodType), timeElapsed.format(periodType)); + period, timeElapsed); } return Result.NO; } diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/PeriodThrottlerTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/PeriodThrottlerTests.java index c9663694879..89ef2e23ccc 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/PeriodThrottlerTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/PeriodThrottlerTests.java @@ -14,7 +14,6 @@ import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.watch.Payload; import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; import org.joda.time.DateTime; -import org.joda.time.PeriodType; import java.time.Clock; @@ -28,9 +27,8 @@ import static org.mockito.Mockito.when; public class PeriodThrottlerTests extends ESTestCase { public void testBelowPeriodSuccessful() throws Exception { - PeriodType periodType = randomFrom(PeriodType.millis(), PeriodType.seconds(), PeriodType.minutes()); TimeValue period = TimeValue.timeValueSeconds(randomIntBetween(2, 5)); - PeriodThrottler throttler = new PeriodThrottler(Clock.systemUTC(), period, periodType); + PeriodThrottler throttler = new PeriodThrottler(Clock.systemUTC(), period); WatchExecutionContext ctx = mockExecutionContext("_name", Payload.EMPTY); ActionStatus actionStatus = mock(ActionStatus.class); @@ -45,14 +43,13 @@ public class PeriodThrottlerTests extends ESTestCase { assertThat(result, notNullValue()); assertThat(result.throttle(), is(true)); assertThat(result.reason(), notNullValue()); - assertThat(result.reason(), startsWith("throttling interval is set to [" + period.format(periodType) + "]")); + assertThat(result.reason(), startsWith("throttling interval is set to [" + period + "]")); assertThat(result.type(), is(Throttler.Type.PERIOD)); } public void testAbovePeriod() throws Exception { - PeriodType periodType = randomFrom(PeriodType.millis(), PeriodType.seconds(), PeriodType.minutes()); TimeValue period = TimeValue.timeValueSeconds(randomIntBetween(2, 5)); - PeriodThrottler throttler = new PeriodThrottler(Clock.systemUTC(), period, periodType); + PeriodThrottler throttler = new PeriodThrottler(Clock.systemUTC(), period); WatchExecutionContext ctx = mockExecutionContext("_name", Payload.EMPTY); ActionStatus actionStatus = mock(ActionStatus.class); diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpConnectionTimeoutTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpConnectionTimeoutTests.java index 1b66d48ff06..8ac2bef16e8 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpConnectionTimeoutTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpConnectionTimeoutTests.java @@ -40,7 +40,7 @@ public class HttpConnectionTimeoutTests extends ESTestCase { fail("expected timeout exception"); } catch (ConnectTimeoutException ete) { TimeValue timeout = TimeValue.timeValueNanos(System.nanoTime() - start); - logger.info("http connection timed out after {}", timeout.format()); + logger.info("http connection timed out after {}", timeout); // it's supposed to be 10, but we'll give it an error margin of 2 seconds assertThat(timeout.seconds(), greaterThan(8L)); assertThat(timeout.seconds(), lessThan(12L)); @@ -66,7 +66,7 @@ public class HttpConnectionTimeoutTests extends ESTestCase { fail("expected timeout exception"); } catch (ConnectTimeoutException ete) { TimeValue timeout = TimeValue.timeValueNanos(System.nanoTime() - start); - logger.info("http connection timed out after {}", timeout.format()); + logger.info("http connection timed out after {}", timeout); // it's supposed to be 7, but we'll give it an error margin of 2 seconds assertThat(timeout.seconds(), greaterThan(3L)); assertThat(timeout.seconds(), lessThan(7L)); @@ -93,7 +93,7 @@ public class HttpConnectionTimeoutTests extends ESTestCase { fail("expected timeout exception"); } catch (ConnectTimeoutException ete) { TimeValue timeout = TimeValue.timeValueNanos(System.nanoTime() - start); - logger.info("http connection timed out after {}", timeout.format()); + logger.info("http connection timed out after {}", timeout); // it's supposed to be 7, but we'll give it an error margin of 2 seconds assertThat(timeout.seconds(), greaterThan(3L)); assertThat(timeout.seconds(), lessThan(7L)); diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpReadTimeoutTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpReadTimeoutTests.java index 5f344931e1f..2d134681e8b 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpReadTimeoutTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpReadTimeoutTests.java @@ -51,7 +51,7 @@ public class HttpReadTimeoutTests extends ESTestCase { long start = System.nanoTime(); expectThrows(SocketTimeoutException.class, () -> httpClient.execute(request)); TimeValue timeout = TimeValue.timeValueNanos(System.nanoTime() - start); - logger.info("http connection timed out after {}", timeout.format()); + logger.info("http connection timed out after {}", timeout); // it's supposed to be 10, but we'll give it an error margin of 2 seconds assertThat(timeout.seconds(), greaterThan(8L)); @@ -73,7 +73,7 @@ public class HttpReadTimeoutTests extends ESTestCase { long start = System.nanoTime(); expectThrows(SocketTimeoutException.class, () -> httpClient.execute(request)); TimeValue timeout = TimeValue.timeValueNanos(System.nanoTime() - start); - logger.info("http connection timed out after {}", timeout.format()); + logger.info("http connection timed out after {}", timeout); // it's supposed to be 3, but we'll give it an error margin of 2 seconds assertThat(timeout.seconds(), greaterThan(1L)); @@ -96,7 +96,7 @@ public class HttpReadTimeoutTests extends ESTestCase { long start = System.nanoTime(); expectThrows(SocketTimeoutException.class, () -> httpClient.execute(request)); TimeValue timeout = TimeValue.timeValueNanos(System.nanoTime() - start); - logger.info("http connection timed out after {}", timeout.format()); + logger.info("http connection timed out after {}", timeout); // it's supposed to be 3, but we'll give it an error margin of 2 seconds assertThat(timeout.seconds(), greaterThan(1L));