From 2f142409155f56948f70112047c5756465bd975d Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 17 Jun 2015 09:17:13 +0200 Subject: [PATCH 1/2] test: increased time throttle timeout to deal with timing issues Original commit: elastic/x-pack-elasticsearch@90fd3c9cd956321c899c3f8530f43dfa458cac99 --- .../actions/throttler/ActionThrottleTests.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java b/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java index 8cdd31f42c1..d2930396fed 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/throttler/ActionThrottleTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.watcher.actions.throttler; -import com.carrotsearch.randomizedtesting.annotations.Repeat; import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.joda.time.DateTime; @@ -56,7 +55,7 @@ import static org.hamcrest.Matchers.greaterThan; */ public class ActionThrottleTests extends AbstractWatcherIntegrationTests { - @Test @Slow @Repeat(iterations = 10) + @Test @Slow public void testSingleActionAckThrottle() throws Exception { boolean useClientForAcking = randomBoolean(); @@ -96,7 +95,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTests { } } - @Test @Slow @Repeat(iterations = 10) + @Test @Slow public void testRandomMultiActionAckThrottle() throws Exception { boolean useClientForAcking = randomBoolean(); @@ -256,11 +255,11 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTests { }, 6, TimeUnit.SECONDS); } - @Test @Slow @Repeat(iterations = 20) + @Test @Slow public void testWatchThrottlePeriod() throws Exception { WatchSourceBuilder watchSourceBuilder = watchBuilder() .trigger(schedule(interval("60m"))) - .defaultThrottlePeriod(new TimeValue(1, TimeUnit.SECONDS)); + .defaultThrottlePeriod(new TimeValue(20, TimeUnit.SECONDS)); AvailableAction availableAction = randomFrom(AvailableAction.values()); watchSourceBuilder.addAction("default_global_throttle", availableAction.action()); @@ -296,7 +295,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTests { assertThat(resultStatus.toString(), equalTo("throttled")); if (timeWarped()) { - timeWarp().clock().fastForwardSeconds(1); + timeWarp().clock().fastForwardSeconds(20); } assertBusy(new Runnable() { @Override @@ -315,7 +314,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTests { throw new ElasticsearchException("failed to execute", ioe); } } - }, 1, TimeUnit.SECONDS); + }, 20, TimeUnit.SECONDS); } @Test @Slow From b82fca337912d150e4da4f05f4bcca169b59aa31 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 17 Jun 2015 09:47:30 +0200 Subject: [PATCH 2/2] We should cope with the situation when a watch is going to be executed whilst shutting down. The execution service will throw an exection if we acquire a watch lock or add a watch to the current executions if Watcher has stopped or is stopping. We should deal with this sitation by properly catching those failures. FYI if a watch managed to put itself to the current executions a shutdown will wait until a watch execution is finished. Original commit: elastic/x-pack-elasticsearch@5692316072c73c0b61e0c055f34f4e35c9bdeb31 --- .../watcher/execution/CurrentExecutions.java | 5 ++--- .../watcher/execution/ExecutionService.java | 18 ++++++++++-------- .../support/WatcherInactiveException.java | 19 +++++++++++++++++++ .../watcher/watch/WatchLockService.java | 6 +++--- 4 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/elasticsearch/watcher/support/WatcherInactiveException.java diff --git a/src/main/java/org/elasticsearch/watcher/execution/CurrentExecutions.java b/src/main/java/org/elasticsearch/watcher/execution/CurrentExecutions.java index 959e436dd31..a3619ba0fbb 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/CurrentExecutions.java +++ b/src/main/java/org/elasticsearch/watcher/execution/CurrentExecutions.java @@ -5,9 +5,8 @@ */ package org.elasticsearch.watcher.execution; -import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ConcurrentCollections; +import org.elasticsearch.watcher.support.WatcherInactiveException; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; @@ -28,7 +27,7 @@ public class CurrentExecutions implements Iterable