From 4d44fa0192edd4c62c2446cebd30038ef473aca7 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 15 Apr 2015 23:09:21 -0700 Subject: [PATCH] Fixed test using .getURI() for resource paths to use .getPath() instead. We should probalby ban .getURI()? Also added a couple nocommits for some issues with tests after mockfs is working again. But I also re-enabled the mockfs suppression in the base test case for now. --- .../org/elasticsearch/NamingConventionTests.java | 3 ++- .../OldIndexBackwardsCompatibilityTests.java | 4 ++-- .../bwcompat/RestoreBackwardsCompatTests.java | 2 +- ...ingBackwardCompatibilityUponUpgradeTests.java | 4 +++- .../common/io/FileSystemUtilsTests.java | 5 +++-- .../common/logging/log4j/Log4jESLoggerTests.java | 2 +- .../logging/log4j/LoggingConfigurationTests.java | 2 +- .../nodesinfo/SimpleNodesInfoTests.java | 2 +- .../elasticsearch/plugins/SitePluginTests.java | 16 ++++++---------- .../test/ElasticsearchIntegrationTest.java | 3 ++- .../org/elasticsearch/tribe/TribeUnitTests.java | 2 +- 11 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/elasticsearch/NamingConventionTests.java b/src/test/java/org/elasticsearch/NamingConventionTests.java index 252ab0cefda..2206da6601a 100644 --- a/src/test/java/org/elasticsearch/NamingConventionTests.java +++ b/src/test/java/org/elasticsearch/NamingConventionTests.java @@ -43,6 +43,7 @@ import java.util.Set; /** * Simple class that ensures that all subclasses concrete of ElasticsearchTestCase end with either Test | Tests */ +@LuceneTestCase.SuppressFileSystems("*") // nocommit: ignore rules aren't working for some reason with mockfs public class NamingConventionTests extends ElasticsearchTestCase { // see https://github.com/elasticsearch/elasticsearch/issues/9945 @@ -54,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 = PathUtils.get(NamingConventionTests.class.getResource(path).toURI()); + final Path startPath = PathUtils.get(NamingConventionTests.class.getResource(path).getPath()); final Set ignore = Sets.newHashSet(PathUtils.get("/org/elasticsearch/stresstest"), PathUtils.get("/org/elasticsearch/benchmark/stress")); Files.walkFileTree(startPath, new FileVisitor() { private Path pkgPrefix = PathUtils.get(path).getParent(); diff --git a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 2e47caa052c..de7c3490d87 100644 --- a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -90,7 +90,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio public static void initIndexesList() throws Exception { indexes = new ArrayList<>(); URL dirUrl = OldIndexBackwardsCompatibilityTests.class.getResource("."); - Path dir = PathUtils.get(dirUrl.toURI()); + Path dir = PathUtils.get(dirUrl.getPath()); try (DirectoryStream stream = Files.newDirectoryStream(dir, "index-*.zip")) { for (Path path : stream) { indexes.add(path.getFileName().toString()); @@ -159,7 +159,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT); // decompress the index - Path backwardsIndex = PathUtils.get(getClass().getResource(indexFile).toURI()); + Path backwardsIndex = PathUtils.get(getClass().getResource(indexFile).getPath()); try (InputStream stream = Files.newInputStream(backwardsIndex)) { TestUtil.unzip(stream, unzipDir); } diff --git a/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java index f61cf9b3db8..e665487fae5 100644 --- a/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java @@ -95,7 +95,7 @@ public class RestoreBackwardsCompatTests extends AbstractSnapshotTests { public static List repoVersions() throws Exception { List repoVersions = newArrayList(); - Path repoFiles = PathUtils.get(RestoreBackwardsCompatTests.class.getResource(".").toURI()); + Path repoFiles = PathUtils.get(RestoreBackwardsCompatTests.class.getResource(".").getPath()); try (DirectoryStream stream = Files.newDirectoryStream(repoFiles, "repo-*.zip")) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); diff --git a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java index 15c6954ef38..23404077f4d 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java +++ b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.cluster.routing; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.action.get.GetResponse; @@ -38,6 +39,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; @ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numDataNodes = 0, minNumDataNodes = 0, maxNumDataNodes = 0) +@LuceneTestCase.SuppressFileSystems("*") // extra files break the single data cluster expectation when unzipping the static index public class RoutingBackwardCompatibilityUponUpgradeTests extends ElasticsearchIntegrationTest { public void testDefaultRouting() throws Exception { @@ -49,7 +51,7 @@ public class RoutingBackwardCompatibilityUponUpgradeTests extends ElasticsearchI } private void test(String name, Class expectedHashFunction, boolean expectedUseType) throws Exception { - Path zippedIndexDir = PathUtils.get(getClass().getResource("/org/elasticsearch/cluster/routing/" + name + ".zip").toURI()); + Path zippedIndexDir = PathUtils.get(getClass().getResource("/org/elasticsearch/cluster/routing/" + name + ".zip").getPath()); Settings baseSettings = prepareBackwardsDataDir(zippedIndexDir); internalCluster().startNode(ImmutableSettings.builder() .put(baseSettings) diff --git a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java index 794f800269e..b70115c718a 100644 --- a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java +++ b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java @@ -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 = PathUtils.get(FileSystemUtilsTests.class.getResource("/org/elasticsearch/common/io/copyappend").toURI()); + final Path path = PathUtils.get(FileSystemUtilsTests.class.getResource("/org/elasticsearch/common/io/copyappend").getPath()); FileSystemUtils.copyDirectoryRecursively(path, src); } @@ -162,9 +162,10 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { } @Test + @AwaitsFix(bugUrl = "FilterPath equality?") // nocommit: mockfs causes FilterPaths here, but the equality doesnt seem to work public void testAppend() { assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 0), - PathUtils.get("/foo/bar/hello/world/this_is/awesome")); + PathUtils.get("/foo/bar/hello/world/this_is/awesome")); assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 2), PathUtils.get("/foo/bar/this_is/awesome")); diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java index c3513822781..7fa1d4bbea1 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java @@ -130,7 +130,7 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase { private static Path resolveConfigDir() throws Exception { URL url = Log4jESLoggerTests.class.getResource("config"); - return PathUtils.get(url.toURI()); + return PathUtils.get(url.getPath()); } private static class TestAppender extends AppenderSkeleton { diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java index ac72682a2c9..88759582d3a 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java @@ -146,7 +146,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { private static Path resolveConfigDir() throws Exception { URL url = LoggingConfigurationTests.class.getResource("config"); - return PathUtils.get(url.toURI()); + return PathUtils.get(url.getPath()); } private static String loggingConfiguration(String suffix) { diff --git a/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java b/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java index dfd50b2e327..d2ddf7e1b98 100644 --- a/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java +++ b/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java @@ -163,7 +163,7 @@ public class SimpleNodesInfoTests extends ElasticsearchIntegrationTest { ImmutableSettings.Builder settings = settingsBuilder(); settings.put(nodeSettings); if (resource != null) { - settings.put("path.plugins", PathUtils.get(resource.toURI()).toAbsolutePath()); + settings.put("path.plugins", PathUtils.get(resource.getPath()).toAbsolutePath()); } if (pluginClassNames.length > 0) { diff --git a/src/test/java/org/elasticsearch/plugins/SitePluginTests.java b/src/test/java/org/elasticsearch/plugins/SitePluginTests.java index eeec0c685d7..19640de4d95 100644 --- a/src/test/java/org/elasticsearch/plugins/SitePluginTests.java +++ b/src/test/java/org/elasticsearch/plugins/SitePluginTests.java @@ -49,16 +49,12 @@ public class SitePluginTests extends ElasticsearchIntegrationTest { @Override protected Settings nodeSettings(int nodeOrdinal) { - try { - Path pluginDir = PathUtils.get(SitePluginTests.class.getResource("/org/elasticsearch/plugins").toURI()); - return settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("path.plugins", pluginDir.toAbsolutePath()) - .put("force.http.enabled", true) - .build(); - } catch (URISyntaxException ex) { - throw new RuntimeException(ex); - } + Path pluginDir = PathUtils.get(SitePluginTests.class.getResource("/org/elasticsearch/plugins").getPath()); + return settingsBuilder() + .put(super.nodeSettings(nodeOrdinal)) + .put("path.plugins", pluginDir.toAbsolutePath()) + .put("force.http.enabled", true) + .build(); } public HttpRequestBuilder httpClient() { diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 96a23ed9f7d..0a8a3cc92ad 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -27,6 +27,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; import org.apache.http.impl.client.HttpClients; import org.apache.lucene.store.StoreRateLimiting; import org.apache.lucene.util.IOUtils; @@ -1931,7 +1932,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase assertTrue(Files.exists(dataDir)); Path[] list = FileSystemUtils.files(dataDir); if (list.length != 1) { - throw new IllegalStateException("Backwards index must contain exactly one cluster"); + throw new IllegalStateException("Backwards index must contain exactly one cluster\n" + StringUtils.join(list, "\n")); } Path src = list[0]; Path dest = dataDir.resolve(internalCluster().getClusterName()); diff --git a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index 1308dc59811..7722504f11c 100644 --- a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -87,7 +87,7 @@ public class TribeUnitTests extends ElasticsearchTestCase { @Test public void testThatTribeClientsIgnoreGlobalConfig() throws Exception { - Path pathConf = PathUtils.get(TribeUnitTests.class.getResource("elasticsearch.yml").toURI()).getParent(); + Path pathConf = PathUtils.get(TribeUnitTests.class.getResource("elasticsearch.yml").getPath()).getParent(); Settings settings = ImmutableSettings.builder().put("config.ignore_system_properties", true).put("path.conf", pathConf).build(); assertTribeNodeSuccesfullyCreated(settings); }