From cbfcbb84b46a2da0249558a961e1dcc5d87a59a7 Mon Sep 17 00:00:00 2001 From: zhouhui Date: Thu, 14 Mar 2024 15:25:22 +0800 Subject: [PATCH] Fix test failure on win 11. --- .../org/apache/lucene/util/Constants.java | 21 +++++++++++++++++++ .../apache/lucene/index/TestIndexWriter.java | 13 ++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/Constants.java b/lucene/core/src/java/org/apache/lucene/util/Constants.java index 97728f585da..b44ec57ce0f 100644 --- a/lucene/core/src/java/org/apache/lucene/util/Constants.java +++ b/lucene/core/src/java/org/apache/lucene/util/Constants.java @@ -41,6 +41,9 @@ public final class Constants { /** True iff running on 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. */ 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. */ 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() { if (HAS_FMA) { String value = getSysProp("lucene.useVectorFMA", "auto"); 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 61e5f7e361d..3a35a4a4a58 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -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 // since it was merged away, because we have a reader open against this file, // 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 // assertTrue(files.contains("_2.cfs")); w.deleteUnusedFiles(); // 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")); r.close(); @@ -1324,6 +1332,7 @@ public class TestIndexWriter extends LuceneTestCase { } } + public void testDeleteUnusedFiles2() throws Exception { // Validates that iw.deleteUnusedFiles() also deletes unused index commits // in case a deletion policy which holds onto commits is used.