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.
This commit is contained in:
Ryan Ernst 2015-04-15 23:09:21 -07:00
parent e5a699fa05
commit 4d44fa0192
11 changed files with 23 additions and 22 deletions

View File

@ -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<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

@ -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<Path> 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);
}

View File

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

View File

@ -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<? extends HashFunction> 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)

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 = 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"));

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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() {

View File

@ -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());

View File

@ -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);
}