Explorar el Código

Add helper method so indices path is not copied all over

Ryan Ernst hace 10 años
padre
commit
5c810eff59

+ 1 - 2
core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java

@@ -98,8 +98,7 @@ public class OldIndexBackwardsCompatibilityIT extends ESIntegTestCase {
 
     private List<String> loadIndexesList(String prefix) throws IOException {
         List<String> indexes = new ArrayList<>();
-        Path dir = getDataPath("/indices/bwc");
-        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, prefix + "-*.zip")) {
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), prefix + "-*.zip")) {
             for (Path path : stream) {
                 indexes.add(path.getFileName().toString());
             }

+ 5 - 9
core/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatIT.java

@@ -62,12 +62,12 @@ public class RestoreBackwardsCompatIT extends AbstractSnapshotIntegTestCase {
             // Configure using path.repo
             return settingsBuilder()
                     .put(super.nodeSettings(nodeOrdinal))
-                    .put("path.repo", reposRoot())
+                    .put("path.repo", getBwcIndicesPath())
                     .build();
         } else {
             // Configure using url white list
             try {
-                URI repoJarPatternUri = new URI("jar:" + reposRoot().toUri().toString() + "*.zip!/repo/");
+                URI repoJarPatternUri = new URI("jar:" + getBwcIndicesPath().toUri().toString() + "*.zip!/repo/");
                 return settingsBuilder()
                         .put(super.nodeSettings(nodeOrdinal))
                         .putArray("repositories.url.allowed_urls", repoJarPatternUri.toString())
@@ -128,10 +128,6 @@ public class RestoreBackwardsCompatIT extends AbstractSnapshotIntegTestCase {
         }
     }
 
-    private Path reposRoot() {
-        return getDataPath("/indices/bwc");
-    }
-
     private List<String> repoVersions() throws Exception {
         return listRepoVersions("repo");
     }
@@ -142,7 +138,7 @@ public class RestoreBackwardsCompatIT extends AbstractSnapshotIntegTestCase {
 
     private List<String> listRepoVersions(String prefix) throws Exception {
         List<String> repoVersions = new ArrayList<>();
-        Path repoFiles = reposRoot();
+        Path repoFiles = getBwcIndicesPath();
         try (DirectoryStream<Path> stream = Files.newDirectoryStream(repoFiles, prefix + "-*.zip")) {
             for (Path entry : stream) {
                 String fileName = entry.getFileName().toString();
@@ -155,8 +151,8 @@ public class RestoreBackwardsCompatIT extends AbstractSnapshotIntegTestCase {
     }
 
     private void createRepo(String prefix, String version, String repo) throws Exception {
-        String repoFile = "/indices/bwc/" + prefix + "-" + version + ".zip";
-        URI repoFileUri = getDataPath(repoFile).toUri();
+        Path repoFile = getBwcIndicesPath().resolve(prefix + "-" + version + ".zip");
+        URI repoFileUri = repoFile.toUri();
         URI repoJarUri = new URI("jar:" + repoFileUri.toString() + "!/repo/");
         logger.info("-->  creating repository [{}] for version [{}]", repo, version);
         assertAcked(client().admin().cluster().preparePutRepository(repo)

+ 1 - 2
core/src/test/java/org/elasticsearch/common/util/MultiDataPathUpgraderTests.java

@@ -133,8 +133,7 @@ public class MultiDataPathUpgraderTests extends ESTestCase {
      */
     public void testUpgradeRealIndex() throws IOException, URISyntaxException {
         List<Path> indexes = new ArrayList<>();
-        Path dir = getDataPath("/indices/bwc");
-        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "index-*.zip")) {
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) {
             for (Path path : stream) {
                 indexes.add(path);
             }

+ 1 - 2
core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

@@ -1786,8 +1786,7 @@ public class InternalEngineTests extends ESTestCase {
 
     public void testUpgradeOldIndex() throws IOException {
         List<Path> indexes = new ArrayList<>();
-        Path dir = getDataPath("/indices/bwc");
-        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "index-*.zip")) {
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) {
             for (Path path : stream) {
                 indexes.add(path);
             }

+ 1 - 2
core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java

@@ -1157,8 +1157,7 @@ public class TranslogTests extends ESTestCase {
 
     public void testUpgradeOldTranslogFiles() throws IOException {
         List<Path> indexes = new ArrayList<>();
-        Path dir = getDataPath("/indices/bwc");
-        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "index-*.zip")) {
+        try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) {
             for (Path path : stream) {
                 indexes.add(path);
             }

+ 4 - 0
core/src/test/java/org/elasticsearch/test/ESTestCase.java

@@ -488,6 +488,10 @@ public abstract class ESTestCase extends LuceneTestCase {
         }
     }
 
+    public Path getBwcIndicesPath() {
+        return getDataPath("/indices/bwc");
+    }
+
     /** Returns a random number of temporary paths. */
     public String[] tmpPaths() {
         final int numPaths = TestUtil.nextInt(random(), 1, 3);