You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2025/12/10 07:55:02 UTC

(lucene) branch branch_10x updated (467966329c6 -> 643b4f4135f)

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a change to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


    from 467966329c6 Check node existence before making reverse link in HNSW graph indexing (#15478)
     new 25c4baff1d6 Support `@SuppressAssertingFormats` (#15490)
     new 643b4f4135f Backport to pre-java25 #15490

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 lucene/CHANGES.txt                                 |  2 +
 .../tests/codecs/asserting/AssertingCodec.java     | 61 +++++++++++++++++++---
 .../apache/lucene/tests/util/LuceneTestCase.java   | 15 ++++++
 .../util/TestRuleSetupAndRestoreClassEnv.java      |  2 +-
 4 files changed, 72 insertions(+), 8 deletions(-)


(lucene) 02/02: Backport to pre-java25 #15490

Posted by dw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 643b4f4135f535abde257f4774f7fa1db539d8f2
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Wed Dec 10 08:54:53 2025 +0100

    Backport to pre-java25 #15490
---
 .../java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java
index c81e831a721..363d8ac9a37 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java
@@ -107,7 +107,9 @@ public class AssertingCodec extends FilterCodec {
     Class<?> targetClass;
     try {
       targetClass = RandomizedContext.current().getTargetClass();
-    } catch (IllegalStateException _) {
+    } catch (
+        @SuppressWarnings("unused")
+        IllegalStateException ignored) {
       // Not under any randomized context.
       targetClass = null;
     }


(lucene) 01/02: Support `@SuppressAssertingFormats` (#15490)

Posted by dw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 25c4baff1d6d0596a68225c092c3d865671c20c4
Author: Prudhvi Godithi <pg...@amazon.com>
AuthorDate: Tue Dec 9 22:41:07 2025 -0800

    Support `@SuppressAssertingFormats` (#15490)
    
    * Support SuppressAssertingFormats
    
    Signed-off-by: Prudhvi Godithi <pg...@amazon.com>
    
    * Moved suppressed formats under AssertingCodec's constructor; initialized depending on the target class from RandomizedContext.
    
    * Remove unused field.
    
    * Remove unused import.
    
    ---------
    
    Signed-off-by: Prudhvi Godithi <pg...@amazon.com>
    Co-authored-by: Dawid Weiss <da...@carrotsearch.com>
---
 lucene/CHANGES.txt                                 |  2 +
 .../tests/codecs/asserting/AssertingCodec.java     | 59 +++++++++++++++++++---
 .../apache/lucene/tests/util/LuceneTestCase.java   | 15 ++++++
 .../util/TestRuleSetupAndRestoreClassEnv.java      |  2 +-
 4 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 63c5db66269..d6230ee20c7 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -59,6 +59,8 @@ New Features
  * GITHUB#15415: Add fallback support to Lucene104ScalarQuantizedVectorsFormat getFloatVectorValues when there are
    no full-precision vectors present (Pulkit Gupta)
 
+ * GITHUB#15468: Add support for `@SuppressAssertingFormats` annotation for fine-grained control over `AssertingCodec` formats (Prudhvi Godithi)
+
 Improvements
 ---------------------
 * GITHUB#15148: Add support uint8 distance and allow 8 bit scalar quantization (Trevor McCulloch)
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java
index 0aded31855e..c81e831a721 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingCodec.java
@@ -16,6 +16,10 @@
  */
 package org.apache.lucene.tests.codecs.asserting;
 
+import com.carrotsearch.randomizedtesting.RandomizedContext;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.stream.Collectors;
 import org.apache.lucene.codecs.DocValuesFormat;
 import org.apache.lucene.codecs.FilterCodec;
 import org.apache.lucene.codecs.KnnVectorsFormat;
@@ -28,11 +32,28 @@ import org.apache.lucene.codecs.TermVectorsFormat;
 import org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat;
 import org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat;
 import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
+import org.apache.lucene.tests.util.LuceneTestCase;
 import org.apache.lucene.tests.util.TestUtil;
 
 /** Acts like the default codec but with additional asserts. */
 public class AssertingCodec extends FilterCodec {
 
+  /** Enum representing asserting format types that can be suppressed. */
+  public enum Format {
+    STORED_FIELDS,
+    TERM_VECTORS,
+    NORMS,
+    LIVE_DOCS,
+    POINTS,
+    KNN_VECTORS
+  }
+
+  private final EnumSet<Format> suppressedFormats;
+
+  private boolean isSuppressed(Format format) {
+    return suppressedFormats.contains(format);
+  }
+
   static void assertThread(String object, Thread creationThread) {
     if (creationThread != Thread.currentThread()) {
       throw new AssertionError(
@@ -81,6 +102,24 @@ public class AssertingCodec extends FilterCodec {
 
   public AssertingCodec() {
     super("Asserting", TestUtil.getDefaultCodec());
+
+    var suppressedFormats = EnumSet.noneOf(AssertingCodec.Format.class);
+    Class<?> targetClass;
+    try {
+      targetClass = RandomizedContext.current().getTargetClass();
+    } catch (IllegalStateException _) {
+      // Not under any randomized context.
+      targetClass = null;
+    }
+
+    if (targetClass != null
+        && targetClass.isAnnotationPresent(LuceneTestCase.SuppressAssertingFormats.class)) {
+      suppressedFormats.addAll(
+          Arrays.asList(
+              targetClass.getAnnotation(LuceneTestCase.SuppressAssertingFormats.class).value()));
+    }
+
+    this.suppressedFormats = suppressedFormats;
   }
 
   @Override
@@ -90,12 +129,12 @@ public class AssertingCodec extends FilterCodec {
 
   @Override
   public TermVectorsFormat termVectorsFormat() {
-    return vectors;
+    return isSuppressed(Format.TERM_VECTORS) ? delegate.termVectorsFormat() : vectors;
   }
 
   @Override
   public StoredFieldsFormat storedFieldsFormat() {
-    return storedFields;
+    return isSuppressed(Format.STORED_FIELDS) ? delegate.storedFieldsFormat() : storedFields;
   }
 
   @Override
@@ -105,27 +144,33 @@ public class AssertingCodec extends FilterCodec {
 
   @Override
   public NormsFormat normsFormat() {
-    return norms;
+    return isSuppressed(Format.NORMS) ? delegate.normsFormat() : norms;
   }
 
   @Override
   public LiveDocsFormat liveDocsFormat() {
-    return liveDocs;
+    return isSuppressed(Format.LIVE_DOCS) ? delegate.liveDocsFormat() : liveDocs;
   }
 
   @Override
   public PointsFormat pointsFormat() {
-    return pointsFormat;
+    return isSuppressed(Format.POINTS) ? delegate.pointsFormat() : pointsFormat;
   }
 
   @Override
   public KnnVectorsFormat knnVectorsFormat() {
-    return knnVectorsFormat;
+    return isSuppressed(Format.KNN_VECTORS) ? delegate.knnVectorsFormat() : knnVectorsFormat;
   }
 
   @Override
   public String toString() {
-    return "Asserting(" + delegate + ")";
+    return "Asserting("
+        + delegate
+        + (suppressedFormats.isEmpty()
+            ? ""
+            : ", suppressed: "
+                + suppressedFormats.stream().map(Enum::toString).collect(Collectors.joining(", ")))
+        + ")";
   }
 
   /**
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
index 95f16bc4f56..2615fa1dd1c 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
@@ -177,6 +177,7 @@ import org.apache.lucene.store.MergeInfo;
 import org.apache.lucene.store.NRTCachingDirectory;
 import org.apache.lucene.store.ReadOnceHint;
 import org.apache.lucene.tests.analysis.MockAnalyzer;
+import org.apache.lucene.tests.codecs.asserting.AssertingCodec;
 import org.apache.lucene.tests.index.AlcoholicMergePolicy;
 import org.apache.lucene.tests.index.AssertingDirectoryReader;
 import org.apache.lucene.tests.index.AssertingLeafReader;
@@ -356,6 +357,20 @@ public abstract class LuceneTestCase extends Assert {
     String[] value();
   }
 
+  /**
+   * Annotation for test classes that should avoid specific asserting formats within the {@link
+   * AssertingCodec} while keeping other asserting formats active.
+   *
+   * @see org.apache.lucene.tests.codecs.asserting.AssertingCodec.Format
+   */
+  @Documented
+  @Inherited
+  @Retention(RetentionPolicy.RUNTIME)
+  @Target(ElementType.TYPE)
+  public @interface SuppressAssertingFormats {
+    AssertingCodec.Format[] value();
+  }
+
   /**
    * Annotation for test classes that should avoid always omit actual fsync calls from reaching the
    * filesystem.
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleSetupAndRestoreClassEnv.java
index e4c0625e7c5..f5ab9b3a173 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleSetupAndRestoreClassEnv.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleSetupAndRestoreClassEnv.java
@@ -166,7 +166,7 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
 
             @Override
             public String toString() {
-              return super.toString() + ": " + format.toString() + ", " + dvFormat.toString();
+              return super.toString() + ": " + format + ", " + dvFormat;
             }
           };
     } else if ("SimpleText".equals(TEST_CODEC)