diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java index 88a3199a1a4..681e035f8a2 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -1116,7 +1116,10 @@ public class TestAddIndexes extends LuceneTestCase { w3.close(); // we should now see segments_X, // _Y.cfs,_Y.cfe, _Z.si - assertEquals("Only one compound segment should exist, but got: " + Arrays.toString(dir.listAll()), 4, dir.listAll().length); + SegmentInfos sis = new SegmentInfos(); + sis.read(dir); + assertEquals("Only one compound segment should exist", 1, sis.size()); + assertTrue(sis.info(0).info.getUseCompoundFile()); dir.close(); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java index e3efa9cb62f..ab8f3f6cbb7 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java @@ -22,7 +22,6 @@ import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.lucene.analysis.MockAnalyzer; -import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriterConfig.OpenMode; @@ -84,6 +83,13 @@ public class TestIndexFileDeleter extends LuceneTestCase { Term searchTerm = new Term("id", "7"); writer.deleteDocuments(searchTerm); writer.close(); + + // read in index to try to not depend on codec-specific filenames so much + SegmentInfos sis = new SegmentInfos(); + sis.read(dir); + SegmentInfo si0 = sis.info(0).info; + SegmentInfo si1 = sis.info(1).info; + SegmentInfo si3 = sis.info(3).info; // Now, artificially create an extra .del file & extra // .s0 file: @@ -110,11 +116,13 @@ public class TestIndexFileDeleter extends LuceneTestCase { // non-existent segment: copyFile(dir, "_0_1" + ext, "_188_1" + ext); + String cfsFiles0[] = si0.getCodec().compoundFormat().files(si0); + // Create a bogus segment file: - copyFile(dir, "_0.cfs", "_188.cfs"); + copyFile(dir, cfsFiles0[0], "_188.cfs"); // Create a bogus fnm file when the CFS already exists: - copyFile(dir, "_0.cfs", "_0.fnm"); + copyFile(dir, cfsFiles0[0], "_0.fnm"); // Create some old segments file: copyFile(dir, "segments_2", "segments"); @@ -124,8 +132,14 @@ public class TestIndexFileDeleter extends LuceneTestCase { // TODO: assert is bogus (relies upon codec-specific filenames) assertTrue(slowFileExists(dir, "_3.fdt") || slowFileExists(dir, "_3.fld")); - assertTrue(!slowFileExists(dir, "_3.cfs")); - copyFile(dir, "_1.cfs", "_3.cfs"); + + String cfsFiles3[] = si3.getCodec().compoundFormat().files(si3); + for (String f : cfsFiles3) { + assertTrue(!slowFileExists(dir, f)); + } + + String cfsFiles1[] = si1.getCodec().compoundFormat().files(si1); + copyFile(dir, cfsFiles1[0], "_3.cfs"); String[] filesPre = dir.listAll(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index 0de4e4e4829..e4e833a8f0d 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -1326,6 +1326,7 @@ public class TestIndexWriter extends LuceneTestCase { public void testDeleteUnusedFiles() throws Exception { + assumeFalse("test relies on exact filenames", Codec.getDefault() instanceof SimpleTextCodec); for(int iter=0;iter<2;iter++) { MockDirectoryWrapper dir = newMockDirectory(); // relies on windows semantics dir.setEnableVirusScanner(false); // but ensures files are actually deleted diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java index 2ad49e5cdf8..3cf0320fd61 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java @@ -1231,17 +1231,19 @@ public class TestIndexWriterExceptions extends LuceneTestCase { long gen = SegmentInfos.getLastCommitGeneration(dir); assertTrue("segment generation should be > 0 but got " + gen, gen > 0); - - String[] files = dir.listAll(); + boolean corrupted = false; - for(int i=0;i