From 430be0d7cbc8e096e6a27bad26dc07ba5ed3a25c Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 25 May 2015 22:41:11 +0200 Subject: [PATCH] [TEST] Skip invalid random file names --- .../index/translog/TranslogTests.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index 6083734475d..58f4759d79f 100644 --- a/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -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; }