fix FileSystemUtils failures

This commit is contained in:
Robert Muir 2015-04-17 08:26:25 -04:00
parent c421948300
commit 2d9e5b4807
21 changed files with 42 additions and 34 deletions

View File

@ -258,6 +258,8 @@ public final class FileSystemUtils {
Files.walkFileTree(source, new TreeCopier(source, destination, true));
}
}
// TODO: note that this will fail if source and target are on different NIO.2 filesystems.
static class TreeCopier extends SimpleFileVisitor<Path> {
private final Path source;

View File

@ -55,7 +55,7 @@ public class NamingConventionTests extends ElasticsearchTestCase {
String[] packages = {"org.elasticsearch", "org.apache.lucene"};
for (final String packageName : packages) {
final String path = "/" + packageName.replace('.', '/');
final Path startPath = getResourcePath(path);
final Path startPath = getDataPath(path);
final Set<Path> ignore = Sets.newHashSet(PathUtils.get("/org/elasticsearch/stresstest"), PathUtils.get("/org/elasticsearch/benchmark/stress"));
Files.walkFileTree(startPath, new FileVisitor<Path>() {
private Path pkgPrefix = PathUtils.get(path).getParent();

View File

@ -85,7 +85,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio
@Before
public void initIndexesList() throws Exception {
indexes = new ArrayList<>();
Path dir = getResourcePath(".");
Path dir = getDataPath(".");
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "index-*.zip")) {
for (Path path : stream) {
indexes.add(path.getFileName().toString());
@ -153,7 +153,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio
String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT);
// decompress the index
Path backwardsIndex = getResourcePath(indexFile);
Path backwardsIndex = getDataPath(indexFile);
try (InputStream stream = Files.newInputStream(backwardsIndex)) {
TestUtil.unzip(stream, unzipDir);
}

View File

@ -95,7 +95,7 @@ public class RestoreBackwardsCompatTests extends AbstractSnapshotTests {
private List<String> repoVersions() throws Exception {
List<String> repoVersions = newArrayList();
Path repoFiles = getResourcePath(".");
Path repoFiles = getDataPath(".");
try (DirectoryStream<Path> stream = Files.newDirectoryStream(repoFiles, "repo-*.zip")) {
for (Path entry : stream) {
String fileName = entry.getFileName().toString();

View File

@ -49,7 +49,7 @@ public class RoutingBackwardCompatibilityUponUpgradeTests extends ElasticsearchI
}
private void test(String name, Class<? extends HashFunction> expectedHashFunction, boolean expectedUseType) throws Exception {
Path zippedIndexDir = getResourcePath("/org/elasticsearch/cluster/routing/" + name + ".zip");
Path zippedIndexDir = getDataPath("/org/elasticsearch/cluster/routing/" + name + ".zip");
Settings baseSettings = prepareBackwardsDataDir(zippedIndexDir);
internalCluster().startNode(ImmutableSettings.builder()
.put(baseSettings)

View File

@ -45,7 +45,7 @@ public class BalanceUnbalancedClusterTest extends CatAllocationTestBase {
@Override
protected Path getCatPath() throws IOException {
Path tmp = newTempDirPath();
try (InputStream stream = Files.newInputStream(getResourcePath("/org/elasticsearch/cluster/routing/issue_9023.zip"))) {
try (InputStream stream = Files.newInputStream(getDataPath("/org/elasticsearch/cluster/routing/issue_9023.zip"))) {
TestUtil.unzip(stream, tmp);
}
return tmp.resolve("issue_9023");

View File

@ -55,7 +55,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase {
// We first copy sources test files from src/test/resources
// Because after when the test runs, src files are moved to their destination
final Path path = getResourcePath("/org/elasticsearch/common/io/copyappend");
final Path path = getDataPath("/org/elasticsearch/common/io/copyappend");
FileSystemUtils.copyDirectoryRecursively(path, src);
}

View File

@ -52,7 +52,7 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase {
super.setUp();
this.testLevel = Log4jESLoggerFactory.getLogger("test").getLevel();
LogConfigurator.reset();
Path configDir = getResourcePath("config");
Path configDir = getDataPath("config");
// Need to set custom path.conf so we can use a custom logging.yml file for the test
Settings settings = ImmutableSettings.builder()
.put("path.conf", configDir.toAbsolutePath())

View File

@ -56,7 +56,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase {
public void testResolveMultipleConfigs() throws Exception {
String level = Log4jESLoggerFactory.getLogger("test").getLevel();
try {
Path configDir = getResourcePath("config");
Path configDir = getDataPath("config");
Settings settings = ImmutableSettings.builder()
.put("path.conf", configDir.toAbsolutePath())
.build();

View File

@ -33,7 +33,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase {
@Test
public void testDedup() throws IOException {
Settings settings = settingsBuilder()
.put("path.conf", getResourcePath("/indices/analyze/conf_dir"))
.put("path.conf", getDataPath("/indices/analyze/conf_dir"))
.put("index.analysis.filter.en_US.type", "hunspell")
.put("index.analysis.filter.en_US.locale", "en_US")
.build();
@ -45,7 +45,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase {
assertThat(hunspellTokenFilter.dedup(), is(true));
settings = settingsBuilder()
.put("path.conf", getResourcePath("/indices/analyze/conf_dir"))
.put("path.conf", getDataPath("/indices/analyze/conf_dir"))
.put("index.analysis.filter.en_US.type", "hunspell")
.put("index.analysis.filter.en_US.dedup", false)
.put("index.analysis.filter.en_US.locale", "en_US")

View File

@ -66,7 +66,7 @@ public class TemplateQueryParserTest extends ElasticsearchTestCase {
@Before
public void setup() throws IOException {
Settings settings = ImmutableSettings.settingsBuilder()
.put("path.conf", this.getResourcePath("config"))
.put("path.conf", this.getDataPath("config"))
.put("name", getClass().getName())
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build();

View File

@ -66,7 +66,7 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder().put(super.nodeSettings(nodeOrdinal))
.put("path.conf", this.getResourcePath("config")).build();
.put("path.conf", this.getDataPath("config")).build();
}
@Test

View File

@ -42,7 +42,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase {
@Test
public void testV0LegacyTranslogVersion() throws Exception {
Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v0.binary");
Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v0.binary");
assertThat("test file should exist", Files.exists(translogFile), equalTo(true));
TranslogStream stream = TranslogStreams.translogStreamFor(translogFile);
assertThat("a version0 stream is returned", stream instanceof LegacyTranslogStream, equalTo(true));
@ -75,7 +75,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase {
@Test
public void testV1ChecksummedTranslogVersion() throws Exception {
Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1.binary");
Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1.binary");
assertThat("test file should exist", Files.exists(translogFile), equalTo(true));
TranslogStream stream = TranslogStreams.translogStreamFor(translogFile);
assertThat("a version1 stream is returned", stream instanceof ChecksummedTranslogStream, equalTo(true));
@ -111,7 +111,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase {
@Test
public void testCorruptedTranslogs() throws Exception {
try {
Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1-corrupted-magic.binary");
Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1-corrupted-magic.binary");
assertThat("test file should exist", Files.exists(translogFile), equalTo(true));
TranslogStream stream = TranslogStreams.translogStreamFor(translogFile);
fail("should have thrown an exception about the header being corrupt");
@ -121,7 +121,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase {
}
try {
Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-invalid-first-byte.binary");
Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-invalid-first-byte.binary");
assertThat("test file should exist", Files.exists(translogFile), equalTo(true));
TranslogStream stream = TranslogStreams.translogStreamFor(translogFile);
fail("should have thrown an exception about the header being corrupt");
@ -131,7 +131,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase {
}
try {
Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1-corrupted-body.binary");
Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1-corrupted-body.binary");
assertThat("test file should exist", Files.exists(translogFile), equalTo(true));
TranslogStream stream = TranslogStreams.translogStreamFor(translogFile);
try (StreamInput in = stream.openInput(translogFile)) {
@ -154,7 +154,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase {
@Test
public void testTruncatedTranslog() throws Exception {
try {
Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1-truncated.binary");
Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1-truncated.binary");
assertThat("test file should exist", Files.exists(translogFile), equalTo(true));
TranslogStream stream = TranslogStreams.translogStreamFor(translogFile);
try (StreamInput in = stream.openInput(translogFile)) {

View File

@ -45,7 +45,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest {
@Test
public void testLocaleDirectoryWithNodeLevelConfig() throws Exception {
Settings settings = ImmutableSettings.settingsBuilder()
.put("path.conf", getResourcePath("/indices/analyze/conf_dir"))
.put("path.conf", getDataPath("/indices/analyze/conf_dir"))
.put(HUNSPELL_LAZY_LOAD, randomBoolean())
.put(HUNSPELL_IGNORE_CASE, true)
.build();
@ -59,7 +59,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest {
@Test
public void testLocaleDirectoryWithLocaleSpecificConfig() throws Exception {
Settings settings = ImmutableSettings.settingsBuilder()
.put("path.conf", getResourcePath("/indices/analyze/conf_dir"))
.put("path.conf", getDataPath("/indices/analyze/conf_dir"))
.put(HUNSPELL_LAZY_LOAD, randomBoolean())
.put(HUNSPELL_IGNORE_CASE, true)
.put("indices.analysis.hunspell.dictionary.en_US.strict_affix_parsing", false)
@ -82,7 +82,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest {
@Test
public void testCustomizeLocaleDirectory() throws Exception {
Settings settings = ImmutableSettings.settingsBuilder()
.put(HUNSPELL_LOCATION, getResourcePath("/indices/analyze/conf_dir/hunspell"))
.put(HUNSPELL_LOCATION, getDataPath("/indices/analyze/conf_dir/hunspell"))
.build();
internalCluster().startNode(settings);
@ -93,7 +93,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest {
@Test
public void testDicWithNoAff() throws Exception {
Settings settings = ImmutableSettings.settingsBuilder()
.put("path.conf", getResourcePath("/indices/analyze/no_aff_conf_dir"))
.put("path.conf", getDataPath("/indices/analyze/no_aff_conf_dir"))
.put(HUNSPELL_LAZY_LOAD, randomBoolean())
.build();
@ -112,7 +112,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest {
@Test
public void testDicWithTwoAffs() throws Exception {
Settings settings = ImmutableSettings.settingsBuilder()
.put("path.conf", getResourcePath("/indices/analyze/two_aff_conf_dir"))
.put("path.conf", getDataPath("/indices/analyze/two_aff_conf_dir"))
.put(HUNSPELL_LAZY_LOAD, randomBoolean())
.build();

View File

@ -42,7 +42,7 @@ public abstract class PluginTestCase extends ElasticsearchIntegrationTest {
ImmutableSettings.Builder settings = settingsBuilder();
settings.put(nodeSettings);
if (resource != null) {
settings.put("path.plugins", getResourcePath(pluginDir).toAbsolutePath());
settings.put("path.plugins", getDataPath(pluginDir).toAbsolutePath());
}
if (pluginClassNames.length > 0) {

View File

@ -49,7 +49,7 @@ public class SitePluginTests extends ElasticsearchIntegrationTest {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Path pluginDir = getResourcePath("/org/elasticsearch/plugins");
Path pluginDir = getDataPath("/org/elasticsearch/plugins");
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("path.plugins", pluginDir.toAbsolutePath())

View File

@ -44,7 +44,7 @@ public class OnDiskScriptTests extends ElasticsearchIntegrationTest {
public Settings nodeSettings(int nodeOrdinal) {
//Set path so ScriptService will pick up the test scripts
return settingsBuilder().put(super.nodeSettings(nodeOrdinal))
.put("path.conf", this.getResourcePath("config"))
.put("path.conf", this.getDataPath("config"))
.put("script.engine.expression.file.aggs", "off")
.put("script.engine.mustache.file.aggs", "off")
.put("script.engine.mustache.file.search", "off")

View File

@ -79,7 +79,7 @@ public class SignificantTermsSignificanceScoreTests extends ElasticsearchIntegra
return settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("plugin.types", CustomSignificanceHeuristicPlugin.class.getName())
.put("path.conf", this.getResourcePath("config"))
.put("path.conf", this.getDataPath("config"))
.build();
}

View File

@ -115,7 +115,7 @@ public class ScriptedMetricTests extends ElasticsearchIntegrationTest {
protected Settings nodeSettings(int nodeOrdinal) {
Settings settings = ImmutableSettings.settingsBuilder()
.put(super.nodeSettings(nodeOrdinal))
.put("path.conf", getResourcePath("/org/elasticsearch/search/aggregations/metrics/scripted/conf"))
.put("path.conf", getDataPath("/org/elasticsearch/search/aggregations/metrics/scripted/conf"))
.build();
return settings;
}

View File

@ -57,6 +57,8 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@ -173,11 +175,15 @@ public abstract class ElasticsearchTestCase extends ESTestCase {
* return URL encoded paths if the parent path contains spaces or other
* non-standard characters.
*/
public Path getResourcePath(String relativePath) {
@Override
public Path getDataPath(String relativePath) {
// we override LTC behavior here: wrap even resources with mockfilesystems,
// because some code is buggy when it comes to multiple nio.2 filesystems
// (e.g. FileSystemUtils, and likely some tests)
try {
return getDataPath(relativePath);
} catch (IOException e) {
throw new RuntimeException(e);
return PathUtils.get(getClass().getResource(relativePath).toURI());
} catch (Exception e) {
throw new RuntimeException("resource not found: " + relativePath, e);
}
}

View File

@ -86,7 +86,7 @@ public class TribeUnitTests extends ElasticsearchTestCase {
@Test
public void testThatTribeClientsIgnoreGlobalConfig() throws Exception {
Path pathConf = getResourcePath("elasticsearch.yml").getParent();
Path pathConf = getDataPath("elasticsearch.yml").getParent();
Settings settings = ImmutableSettings.builder().put("config.ignore_system_properties", true).put("path.conf", pathConf).build();
assertTribeNodeSuccesfullyCreated(settings);
}