Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.lucene.tests.codecs.asserting;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.KnnVectorsFormat;
Expand All @@ -33,6 +36,18 @@
/** Acts like the default codec but with additional asserts. */
public class AssertingCodec extends FilterCodec {

private static volatile Set<String> suppressedFormats = Collections.emptySet();

/** Set the formats to suppress. Use simple class names like "AssertingStoredFieldsFormat". */
public static void setSuppressedFormats(Set<String> formats) {
suppressedFormats =
formats == null || formats.isEmpty() ? Collections.emptySet() : new HashSet<>(formats);
}

private static boolean isSuppressed(String formatName) {
return suppressedFormats.contains(formatName);
}

static void assertThread(String object, Thread creationThread) {
if (creationThread != Thread.currentThread()) {
throw new AssertionError(
Expand Down Expand Up @@ -90,12 +105,14 @@ public PostingsFormat postingsFormat() {

@Override
public TermVectorsFormat termVectorsFormat() {
return vectors;
return isSuppressed("AssertingTermVectorsFormat") ? delegate.termVectorsFormat() : vectors;
}

@Override
public StoredFieldsFormat storedFieldsFormat() {
return storedFields;
return isSuppressed("AssertingStoredFieldsFormat")
? delegate.storedFieldsFormat()
: storedFields;
}

@Override
Expand All @@ -105,22 +122,24 @@ public DocValuesFormat docValuesFormat() {

@Override
public NormsFormat normsFormat() {
return norms;
return isSuppressed("AssertingNormsFormat") ? delegate.normsFormat() : norms;
}

@Override
public LiveDocsFormat liveDocsFormat() {
return liveDocs;
return isSuppressed("AssertingLiveDocsFormat") ? delegate.liveDocsFormat() : liveDocs;
}

@Override
public PointsFormat pointsFormat() {
return pointsFormat;
return isSuppressed("AssertingPointsFormat") ? delegate.pointsFormat() : pointsFormat;
}

@Override
public KnnVectorsFormat knnVectorsFormat() {
return knnVectorsFormat;
return isSuppressed("AssertingKnnVectorsFormat")
? delegate.knnVectorsFormat()
: knnVectorsFormat;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@ public abstract class LuceneTestCase extends Assert {
String[] value();
}

/**
* Annotation for test classes that should avoid specific asserting formats within the Asserting
* codec (e.g., AssertingStoredFieldsFormat) while keeping other asserting formats active.
*
* <p>Use the simple class name of the format to suppress, e.g., "AssertingStoredFieldsFormat".
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SuppressAssertingFormats {
String[] value();
}

/**
* Annotation for test classes that should avoid mock filesystem types (because they test a bug
* that only happens on linux, for example).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.lucene.tests.search.similarities.AssertingSimilarity;
import org.apache.lucene.tests.search.similarities.RandomSimilarity;
import org.apache.lucene.tests.util.LuceneTestCase.LiveIWCFlushMode;
import org.apache.lucene.tests.util.LuceneTestCase.SuppressAssertingFormats;
import org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.PrintStreamInfoStream;
Expand All @@ -76,6 +77,11 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
*/
HashSet<String> avoidCodecs;

/**
* @see SuppressAssertingFormats
*/
HashSet<String> avoidAssertingFormats;

static class ThreadNameFixingPrintStreamInfoStream extends PrintStreamInfoStream {
public ThreadNameFixingPrintStreamInfoStream(PrintStream out) {
super(out);
Expand Down Expand Up @@ -127,6 +133,13 @@ protected void before() throws Exception {
avoidCodecs.addAll(Arrays.asList(a.value()));
}

avoidAssertingFormats = new HashSet<>();
if (targetClass.isAnnotationPresent(SuppressAssertingFormats.class)) {
SuppressAssertingFormats a = targetClass.getAnnotation(SuppressAssertingFormats.class);
avoidAssertingFormats.addAll(Arrays.asList(a.value()));
}
AssertingCodec.setSuppressedFormats(avoidAssertingFormats);

savedCodec = Codec.getDefault();
int randomVal = random.nextInt(11);
if ("default".equals(TEST_CODEC)) {
Expand Down
Loading