[TEST] Relax path clearing assertion on Windows

This commit is contained in:
Simon Willnauer 2015-02-19 09:34:02 +01:00
parent 2dc70597c2
commit 3fe2d7cda8
1 changed files with 15 additions and 3 deletions

View File

@ -27,8 +27,10 @@ import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.store.StoreRateLimiting;
import org.apache.lucene.util.AbstractRandomizedTest;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.TestUtil;
import org.elasticsearch.ElasticsearchException;
@ -1804,7 +1806,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
*/
public void assertPathHasBeenCleared(Path path) throws Exception {
logger.info("--> checking that [{}] has been cleared", path);
int count = 0;
final List<Path> foundFiles = new ArrayList<>();
StringBuilder sb = new StringBuilder();
sb.append("[");
if (Files.exists(path)) {
@ -1814,7 +1816,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
if (Files.isDirectory(file)) {
assertPathHasBeenCleared(file);
} else if (Files.isRegularFile(file)) {
count++;
foundFiles.add(file);
sb.append(file.toAbsolutePath().toString());
sb.append("\n");
}
@ -1822,7 +1824,17 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
}
}
sb.append("]");
assertThat(count + " files exist that should have been cleaned:\n" + sb.toString(), count, equalTo(0));
if (Constants.WINDOWS) {
if (foundFiles.size() > 0) {
for (Path file : foundFiles) {
// for now on windows we only ensure that there is at least no segments_N file left on the path
// we don't have a retry mechanism in place yet.
assertFalse(foundFiles.size() + " files exist that should have been cleaned:\n" + sb.toString(), file.getFileName().toString().startsWith(IndexFileNames.SEGMENTS));
}
}
} else {
assertThat(foundFiles.size() + " files exist that should have been cleaned:\n" + sb.toString(), foundFiles.size(), equalTo(0));
}
}
protected static class NumShards {