From 5c810eff599d1ad0bc0d6613021f8243ff4338f5 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 9 Sep 2015 15:51:34 -0700 Subject: [PATCH] Add helper method so indices path is not copied all over --- .../bwcompat/OldIndexBackwardsCompatibilityIT.java | 3 +-- .../bwcompat/RestoreBackwardsCompatIT.java | 14 +++++--------- .../common/util/MultiDataPathUpgraderTests.java | 3 +-- .../index/engine/InternalEngineTests.java | 3 +-- .../index/translog/TranslogTests.java | 3 +-- .../java/org/elasticsearch/test/ESTestCase.java | 4 ++++ 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java index 94a285e0696..7b927c1e588 100644 --- a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java +++ b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java @@ -98,8 +98,7 @@ public class OldIndexBackwardsCompatibilityIT extends ESIntegTestCase { private List loadIndexesList(String prefix) throws IOException { List indexes = new ArrayList<>(); - Path dir = getDataPath("/indices/bwc"); - try (DirectoryStream stream = Files.newDirectoryStream(dir, prefix + "-*.zip")) { + try (DirectoryStream stream = Files.newDirectoryStream(getBwcIndicesPath(), prefix + "-*.zip")) { for (Path path : stream) { indexes.add(path.getFileName().toString()); } diff --git a/core/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatIT.java b/core/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatIT.java index f47c9dfb103..9ef4238e3b9 100644 --- a/core/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatIT.java +++ b/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 repoVersions() throws Exception { return listRepoVersions("repo"); } @@ -142,7 +138,7 @@ public class RestoreBackwardsCompatIT extends AbstractSnapshotIntegTestCase { private List listRepoVersions(String prefix) throws Exception { List repoVersions = new ArrayList<>(); - Path repoFiles = reposRoot(); + Path repoFiles = getBwcIndicesPath(); try (DirectoryStream 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) diff --git a/core/src/test/java/org/elasticsearch/common/util/MultiDataPathUpgraderTests.java b/core/src/test/java/org/elasticsearch/common/util/MultiDataPathUpgraderTests.java index c46bb4777d0..6d39510f4b1 100644 --- a/core/src/test/java/org/elasticsearch/common/util/MultiDataPathUpgraderTests.java +++ b/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 indexes = new ArrayList<>(); - Path dir = getDataPath("/indices/bwc"); - try (DirectoryStream stream = Files.newDirectoryStream(dir, "index-*.zip")) { + try (DirectoryStream stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) { for (Path path : stream) { indexes.add(path); } diff --git a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index bba853c27ab..35939d37807 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/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 indexes = new ArrayList<>(); - Path dir = getDataPath("/indices/bwc"); - try (DirectoryStream stream = Files.newDirectoryStream(dir, "index-*.zip")) { + try (DirectoryStream stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) { for (Path path : stream) { indexes.add(path); } diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index c834cc84a58..93bc537299c 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/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 indexes = new ArrayList<>(); - Path dir = getDataPath("/indices/bwc"); - try (DirectoryStream stream = Files.newDirectoryStream(dir, "index-*.zip")) { + try (DirectoryStream stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) { for (Path path : stream) { indexes.add(path); } diff --git a/core/src/test/java/org/elasticsearch/test/ESTestCase.java b/core/src/test/java/org/elasticsearch/test/ESTestCase.java index 05acf01f5cf..2916cbb0d48 100644 --- a/core/src/test/java/org/elasticsearch/test/ESTestCase.java +++ b/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);