Fix test failure on win 11.

This commit is contained in:
zhouhui 2024-03-14 15:25:22 +08:00
parent b527e101e7
commit cbfcbb84b4
2 changed files with 32 additions and 2 deletions

View File

@ -41,6 +41,9 @@ public final class Constants {
/** True iff running on Windows. */ /** True iff running on Windows. */
public static final boolean WINDOWS = OS_NAME.startsWith("Windows"); public static final boolean WINDOWS = OS_NAME.startsWith("Windows");
/** True iff running on Windows and the version is on or after Windows 11. */
public static final boolean ON_OR_AFTER_WINDOWS_11 = onOrAfterWindows(11);
/** True iff running on SunOS. */ /** True iff running on SunOS. */
public static final boolean SUN_OS = OS_NAME.startsWith("SunOS"); public static final boolean SUN_OS = OS_NAME.startsWith("SunOS");
@ -100,6 +103,24 @@ public final class Constants {
/** true iff we know FMA has faster throughput than separate mul/add. */ /** true iff we know FMA has faster throughput than separate mul/add. */
public static final boolean HAS_FAST_SCALAR_FMA = hasFastScalarFMA(); public static final boolean HAS_FAST_SCALAR_FMA = hasFastScalarFMA();
private static boolean onOrAfterWindows(float version){
if(WINDOWS){
String[] s = OS_NAME.split(" ");
// False for Windows Server 2022, etc.
if(s.length == 2){
try{
if(Float.parseFloat(s[1]) >= version){
return true;
}
}catch (NumberFormatException e){
// False for Windows XP, etc.
return false;
}
}
}
return false;
}
private static boolean hasFastVectorFMA() { private static boolean hasFastVectorFMA() {
if (HAS_FMA) { if (HAS_FMA) {
String value = getSysProp("lucene.useVectorFMA", "auto"); String value = getSysProp("lucene.useVectorFMA", "auto");

View File

@ -1298,13 +1298,21 @@ public class TestIndexWriter extends LuceneTestCase {
// NOTE: here we rely on "Windows" behavior, i.e. even though IW wanted to delete _0.cfs // NOTE: here we rely on "Windows" behavior, i.e. even though IW wanted to delete _0.cfs
// since it was merged away, because we have a reader open against this file, // since it was merged away, because we have a reader open against this file,
// it should still be here: // it should still be here:
assertTrue(Files.exists(indexPath.resolve("_0.cfs"))); if(iter == 1 && Constants.ON_OR_AFTER_WINDOWS_11){
assertFalse(Files.exists(indexPath.resolve("_0.cfs")));
}else{
assertTrue(Files.exists(indexPath.resolve("_0.cfs")));
}
// forceMerge created this // forceMerge created this
// assertTrue(files.contains("_2.cfs")); // assertTrue(files.contains("_2.cfs"));
w.deleteUnusedFiles(); w.deleteUnusedFiles();
// r still holds this file open // r still holds this file open
assertTrue(Files.exists(indexPath.resolve("_0.cfs"))); if(iter == 1 && Constants.ON_OR_AFTER_WINDOWS_11){
assertFalse(Files.exists(indexPath.resolve("_0.cfs")));
}else{
assertTrue(Files.exists(indexPath.resolve("_0.cfs")));
}
// assertTrue(files.contains("_2.cfs")); // assertTrue(files.contains("_2.cfs"));
r.close(); r.close();
@ -1324,6 +1332,7 @@ public class TestIndexWriter extends LuceneTestCase {
} }
} }
public void testDeleteUnusedFiles2() throws Exception { public void testDeleteUnusedFiles2() throws Exception {
// Validates that iw.deleteUnusedFiles() also deletes unused index commits // Validates that iw.deleteUnusedFiles() also deletes unused index commits
// in case a deletion policy which holds onto commits is used. // in case a deletion policy which holds onto commits is used.