diff options
author | Boaz Leskes <b.leskes@gmail.com> | 2017-06-15 13:24:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-15 13:24:07 +0200 |
commit | 648b4717a490a942d4cb36aefad886509a2c0f03 (patch) | |
tree | bf199c7b950a39454e62bc07d4215a51fcc843e3 /test/framework | |
parent | 27f12069990f11aab65fd319e507f74ad22cf663 (diff) |
move assertBusy to use CheckException (#25246)
We use assertBusy in many places where the underlying code throw exceptions. Currently we need to wrap those exceptions in a RuntimeException which is ugly.
Diffstat (limited to 'test/framework')
-rw-r--r-- | test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java | 6 | ||||
-rw-r--r-- | test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java | 9 |
2 files changed, 6 insertions, 9 deletions
diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 0d3e8131ab..39dde6c145 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -29,7 +29,6 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter; - import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -48,6 +47,7 @@ import org.elasticsearch.bootstrap.BootstrapForTesting; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtilsForTesting; @@ -692,14 +692,14 @@ public abstract class ESTestCase extends LuceneTestCase { /** * Runs the code block for 10 seconds waiting for no assertion to trip. */ - public static void assertBusy(Runnable codeBlock) throws Exception { + public static void assertBusy(CheckedRunnable<Exception> codeBlock) throws Exception { assertBusy(codeBlock, 10, TimeUnit.SECONDS); } /** * Runs the code block for the provided interval, waiting for no assertions to trip. */ - public static void assertBusy(Runnable codeBlock, long maxWaitTime, TimeUnit unit) throws Exception { + public static void assertBusy(CheckedRunnable<Exception> codeBlock, long maxWaitTime, TimeUnit unit) throws Exception { long maxTimeInMillis = TimeUnit.MILLISECONDS.convert(maxWaitTime, unit); long iterations = Math.max(Math.round(Math.log10(maxTimeInMillis) / Math.log10(2)), 1); long timeInMillis = 1; diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index c4e191e75c..b70638f96e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -2016,12 +2016,9 @@ public final class InternalTestCluster extends TestCluster { // in an assertBusy loop, so it will try for 10 seconds and // fail if it never reached 0 try { - assertBusy(new Runnable() { - @Override - public void run() { - CircuitBreaker reqBreaker = breakerService.getBreaker(CircuitBreaker.REQUEST); - assertThat("Request breaker not reset to 0 on node: " + name, reqBreaker.getUsed(), equalTo(0L)); - } + assertBusy(() -> { + CircuitBreaker reqBreaker = breakerService.getBreaker(CircuitBreaker.REQUEST); + assertThat("Request breaker not reset to 0 on node: " + name, reqBreaker.getUsed(), equalTo(0L)); }); } catch (Exception e) { fail("Exception during check for request breaker reset to 0: " + e); |