From c7b45b2cc7b9f115a9a942d68693c8b411cf578a Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 23 May 2016 16:17:43 -0700 Subject: [PATCH] Tests: Remove unnecessary Callable variant of assertBusy The assertBusy method currently has both a Runnable and Callable version. This has caused confusion with type inference and lambdas sometimes, in particular with java 9. This change removes the callable version as nothing was actually using it. --- .../index/reindex/CancelTests.java | 2 +- .../org/elasticsearch/test/ESTestCase.java | 20 +++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/CancelTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/CancelTests.java index 5a778d0b0fa..e2cc5b43f0a 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/CancelTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/CancelTests.java @@ -137,7 +137,7 @@ public class CancelTests extends ReindexTestCase { ALLOWED_OPERATIONS.release(BLOCKING_OPERATIONS); // Checks that no more operations are executed - assertBusy(() -> ALLOWED_OPERATIONS.availablePermits() == 0 && ALLOWED_OPERATIONS.getQueueLength() == 0); + assertBusy(() -> assertTrue(ALLOWED_OPERATIONS.availablePermits() == 0 && ALLOWED_OPERATIONS.getQueueLength() == 0)); // And check the status of the response BulkIndexByScrollResponse response = future.get(); 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 67d93c6887a..6ed9a746f46 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -443,24 +443,13 @@ 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 { - assertBusy(Executors.callable(codeBlock), 10, TimeUnit.SECONDS); - } - - public static void assertBusy(Runnable codeBlock, long maxWaitTime, TimeUnit unit) throws Exception { - assertBusy(Executors.callable(codeBlock), maxWaitTime, unit); - } - - /** - * Runs the code block for 10 seconds waiting for no assertion to trip. - */ - public static V assertBusy(Callable codeBlock) throws Exception { - return assertBusy(codeBlock, 10, TimeUnit.SECONDS); + assertBusy(codeBlock, 10, TimeUnit.SECONDS); } /** * Runs the code block for the provided interval, waiting for no assertions to trip. */ - public static V assertBusy(Callable codeBlock, long maxWaitTime, TimeUnit unit) throws Exception { + public static void assertBusy(Runnable 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; @@ -468,7 +457,8 @@ public abstract class ESTestCase extends LuceneTestCase { List failures = new ArrayList<>(); for (int i = 0; i < iterations; i++) { try { - return codeBlock.call(); + codeBlock.run(); + return; } catch (AssertionError e) { failures.add(e); } @@ -479,7 +469,7 @@ public abstract class ESTestCase extends LuceneTestCase { timeInMillis = maxTimeInMillis - sum; Thread.sleep(Math.max(timeInMillis, 0)); try { - return codeBlock.call(); + codeBlock.run(); } catch (AssertionError e) { for (AssertionError failure : failures) { e.addSuppressed(failure);