diff --git a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java index 4eb674397be..a280d4e687c 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java +++ b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java @@ -586,7 +586,7 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { logger.info("--> deleting index " + IDX); assertAcked(client().admin().indices().prepareDelete(IDX)); - assertPathHasBeenCleared(dataPath); + assertBusyPathHasBeenCleared(dataPath); //norelease //TODO: uncomment the test below when https://github.com/elastic/elasticsearch/issues/17695 is resolved. //assertIndicesDirsDeleted(nodes); @@ -647,7 +647,7 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { assertAcked(client().admin().indices().prepareDelete(IDX)); - assertPathHasBeenCleared(dataPath); + assertBusyPathHasBeenCleared(dataPath); //norelease //TODO: uncomment the test below when https://github.com/elastic/elasticsearch/issues/17695 is resolved. //assertIndicesDirsDeleted(nodes); @@ -839,7 +839,7 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { logger.info("--> deleting closed index"); client().admin().indices().prepareDelete(IDX).get(); - assertPathHasBeenCleared(dataPath); + assertBusyPathHasBeenCleared(dataPath); assertIndicesDirsDeleted(nodes); } diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index ccc1f0a6b36..52aa07b3eb3 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -556,7 +556,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { SearchResponse response = client().prepareSearch("test").get(); assertHitCount(response, 1L); client().admin().indices().prepareDelete("test").get(); - assertPathHasBeenCleared(idxPath); + assertBusyPathHasBeenCleared(idxPath); } public void testExpectedShardSizeIsPresent() throws InterruptedException { @@ -639,8 +639,8 @@ public class IndexShardTests extends ESSingleNodeTestCase { assertThat("found the hit", resp.getHits().getTotalHits(), equalTo(1L)); assertAcked(client().admin().indices().prepareDelete(INDEX)); - assertPathHasBeenCleared(startDir.toAbsolutePath().toString()); - assertPathHasBeenCleared(endDir.toAbsolutePath().toString()); + assertBusyPathHasBeenCleared(startDir.toAbsolutePath()); + assertBusyPathHasBeenCleared(endDir.toAbsolutePath()); } public void testShardStats() throws IOException { 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 22216efa15b..972c1a50fbc 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -70,6 +70,7 @@ import org.junit.Rule; import org.junit.rules.RuleChain; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -672,16 +673,16 @@ public abstract class ESTestCase extends LuceneTestCase { } /** - * Asserts that there are no files in the specified path + * Asserts busily that there are no files in the specified path */ - public void assertPathHasBeenCleared(String path) throws Exception { - assertPathHasBeenCleared(PathUtils.get(path)); + public void assertBusyPathHasBeenCleared(Path path) throws Exception { + assertBusy(() -> assertPathHasBeenCleared(path)); } /** * Asserts that there are no files in the specified path */ - public void assertPathHasBeenCleared(Path path) throws Exception { + public void assertPathHasBeenCleared(Path path) { logger.info("--> checking that [{}] has been cleared", path); int count = 0; StringBuilder sb = new StringBuilder(); @@ -702,6 +703,8 @@ public abstract class ESTestCase extends LuceneTestCase { sb.append("\n"); } } + } catch (IOException e) { + throw new UncheckedIOException(e); } } sb.append("]");