[TEST] Fix tests that rely on assumption that data dirs are removed after index deletion (#18681)

Relates to #18602
This commit is contained in:
Yannick Welsch 2016-06-01 17:02:09 +02:00
parent bdd1d0703d
commit c20bf5d747
3 changed files with 13 additions and 10 deletions

View File

@ -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);
}

View File

@ -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 {

View File

@ -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("]");