diff --git a/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java b/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java index ff011f59dbd43..df5e14b0c9e49 100644 --- a/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java +++ b/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java @@ -107,6 +107,8 @@ public class LuceneTests extends OpenSearchTestCase { private static final NamedWriteableRegistry EMPTY_REGISTRY = new NamedWriteableRegistry(Collections.emptyList()); + public static final String OLDER_VERSION_INDEX_ZIP_RELATIVE_PATH = "/indices/bwc/os-1.3.0/testIndex-os-1.3.0.zip"; + public void testCleanIndex() throws IOException { MockDirectoryWrapper dir = newMockDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(); @@ -332,10 +334,9 @@ public void testNumDocs() throws IOException { * in the README here. */ public void testReadSegmentInfosExtendedCompatibility() throws IOException { - final String pathToTestIndex = "/indices/bwc/os-1.3.0/testIndex-os-1.3.0.zip"; final Version minVersion = LegacyESVersion.V_7_2_0; Path tmp = createTempDir(); - TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp); + TestUtil.unzip(getClass().getResourceAsStream(OLDER_VERSION_INDEX_ZIP_RELATIVE_PATH), tmp); try (MockDirectoryWrapper dir = newMockFSDirectory(tmp)) { // The standard API will throw an exception expectThrows(IndexFormatTooOldException.class, () -> Lucene.readSegmentInfos(dir)); diff --git a/server/src/test/java/org/opensearch/index/engine/ReadOnlyEngineTests.java b/server/src/test/java/org/opensearch/index/engine/ReadOnlyEngineTests.java index a2647902f3c0d..288822ab1589f 100644 --- a/server/src/test/java/org/opensearch/index/engine/ReadOnlyEngineTests.java +++ b/server/src/test/java/org/opensearch/index/engine/ReadOnlyEngineTests.java @@ -38,6 +38,7 @@ import org.apache.lucene.tests.util.TestUtil; import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; +import org.opensearch.common.lucene.LuceneTests; import org.opensearch.common.lucene.index.OpenSearchDirectoryReader; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; @@ -243,9 +244,8 @@ public void testReadOldIndices() throws Exception { IOUtils.close(engine, store); // The index has one document in it, so the checkpoint cannot be NO_OPS_PERFORMED final AtomicLong globalCheckpoint = new AtomicLong(0); - final String pathToTestIndex = "/indices/bwc/os-1.3.0/testIndex-os-1.3.0.zip"; Path tmp = createTempDir(); - TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp); + TestUtil.unzip(getClass().getResourceAsStream(LuceneTests.OLDER_VERSION_INDEX_ZIP_RELATIVE_PATH), tmp); FeatureFlagSetter.set(FeatureFlags.SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings( "index", @@ -266,9 +266,8 @@ public void testReadOldIndicesFailure() throws IOException { IOUtils.close(engine, store); // The index has one document in it, so the checkpoint cannot be NO_OPS_PERFORMED final AtomicLong globalCheckpoint = new AtomicLong(0); - final String pathToTestIndex = "/indices/bwc/os-1.3.0/testIndex-os-1.3.0.zip"; Path tmp = createTempDir(); - TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp); + TestUtil.unzip(getClass().getResourceAsStream(LuceneTests.OLDER_VERSION_INDEX_ZIP_RELATIVE_PATH), tmp); try (Store store = createStore(newFSDirectory(tmp))) { EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null, null, globalCheckpoint::get); try { diff --git a/server/src/test/java/org/opensearch/index/store/StoreTests.java b/server/src/test/java/org/opensearch/index/store/StoreTests.java index 8b44258c5acd6..542f95a4894e2 100644 --- a/server/src/test/java/org/opensearch/index/store/StoreTests.java +++ b/server/src/test/java/org/opensearch/index/store/StoreTests.java @@ -69,6 +69,7 @@ import org.opensearch.common.SuppressForbidden; import org.opensearch.common.UUIDs; import org.opensearch.common.lucene.Lucene; +import org.opensearch.common.lucene.LuceneTests; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.FeatureFlags; @@ -1284,9 +1285,8 @@ public void testSegmentReplicationDiff() { @SuppressForbidden(reason = "sets the SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY feature flag") public void testReadSegmentsFromOldIndices() throws Exception { int expectedIndexCreatedVersionMajor = SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION.luceneVersion.major; - final String pathToTestIndex = "/indices/bwc/os-1.3.0/testIndex-os-1.3.0.zip"; Path tmp = createTempDir(); - TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp); + TestUtil.unzip(getClass().getResourceAsStream(LuceneTests.OLDER_VERSION_INDEX_ZIP_RELATIVE_PATH), tmp); final ShardId shardId = new ShardId("index", "_na_", 1); Store store = null; @@ -1309,10 +1309,9 @@ public void testReadSegmentsFromOldIndices() throws Exception { } public void testReadSegmentsFromOldIndicesFailure() throws IOException { - final String pathToTestIndex = "/indices/bwc/os-1.3.0/testIndex-os-1.3.0.zip"; final ShardId shardId = new ShardId("index", "_na_", 1); Path tmp = createTempDir(); - TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp); + TestUtil.unzip(getClass().getResourceAsStream(LuceneTests.OLDER_VERSION_INDEX_ZIP_RELATIVE_PATH), tmp); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings( "index", Settings.builder()