[TEST] Skip invalid random file names

This commit is contained in:
Simon Willnauer 2015-05-25 22:41:11 +02:00
parent 00ce0a18c5
commit 430be0d7cb
1 changed files with 11 additions and 6 deletions

View File

@ -53,10 +53,7 @@ import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
@ -143,11 +140,19 @@ public class TranslogTests extends ElasticsearchTestCase {
assertThat(Translog.parseIdFromFileName(file), equalTo(-1l));
}
private static String randomNonTranslogPatternString(int min, int max) {
private String randomNonTranslogPatternString(int min, int max) {
String string;
boolean validPathString = false;
do {
validPathString = false;
string = randomRealisticUnicodeOfCodepointLength(randomIntBetween(min, max));
} while (Translog.PARSE_ID_PATTERN.matcher(string).matches());
try {
translogDir.resolve(string);
validPathString = true;
} catch (InvalidPathException ex) {
// some FS don't like our random file names -- let's just skip these random choices
}
} while (Translog.PARSE_ID_PATTERN.matcher(string).matches() && validPathString);
return string;
}