This is an automated email from the ASF dual-hosted git repository. jiangtian pushed a commit to branch add_mustoverride_check in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a425f1865846954aa523f40bfa344a4cd07244f4 Author: Tian Jiang <[email protected]> AuthorDate: Thu Jan 29 18:13:14 2026 +0800 Add must override check --- .../org/apache/iotdb/db/utils/AnnotationTest.java | 59 ++++++++++++++++++++++ pom.xml | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java index 91ae2097089..9594ab6cdcb 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java @@ -23,15 +23,20 @@ import org.apache.iotdb.commons.utils.TestOnly; import com.tngtech.archunit.core.domain.JavaClass; import com.tngtech.archunit.core.domain.JavaClasses; +import com.tngtech.archunit.core.domain.JavaMethod; import com.tngtech.archunit.core.domain.properties.CanBeAnnotated; import com.tngtech.archunit.core.importer.ClassFileImporter; import com.tngtech.archunit.core.importer.ImportOption; import com.tngtech.archunit.core.importer.ImportOption.DoNotIncludeTests; import com.tngtech.archunit.lang.ArchRule; +import org.apache.tsfile.utils.MustOverride; import org.junit.Test; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; @@ -71,4 +76,58 @@ public class AnnotationTest { } catch (OutOfMemoryError ignored) { } } + + @Test + public void checkMustOverride() { + try { + JavaClasses productionClasses = + new ClassFileImporter() + .withImportOption(new DoNotIncludeTests()) + .importPackages("org.apache.iotdb", "org.apache.tsfile"); + + Map<JavaClass, List<JavaMethod>> classAndMethodsMustOverride = new HashMap<>(); + for (JavaClass productionClass : productionClasses) { + for (JavaMethod method : productionClass.getMethods()) { + if (method.isAnnotatedWith(MustOverride.class)) { + classAndMethodsMustOverride + .computeIfAbsent(productionClass, k -> new ArrayList<>()) + .add(method); + } + } + } + + List<String> failures = new ArrayList<>(); + for (JavaClass productionClass : productionClasses) { + for (Entry<JavaClass, List<JavaMethod>> entry : classAndMethodsMustOverride.entrySet()) { + JavaClass classWithTargetMethod = entry.getKey(); + if (productionClass.isAssignableTo(classWithTargetMethod.getName())) { + List<JavaMethod> classesWithMustOverride = entry.getValue(); + for (JavaMethod javaMethod : classesWithMustOverride) { + boolean methodImplemented = false; + for (JavaMethod method : productionClass.getMethods()) { + if (method.getName().equals(javaMethod.getName()) + && method.getParameters().equals(javaMethod.getParameters())) { + methodImplemented = true; + break; + } + } + if (!methodImplemented) { + failures.add( + String.format( + "Class %s does not implement method %s annotated with @MustOverride from class %s", + productionClass.getName(), + javaMethod.getName(), + classWithTargetMethod.getName())); + } + } + } + } + } + + if (!failures.isEmpty()) { + throw new AssertionError(String.join("\n", failures)); + } + } catch (OutOfMemoryError ignored) { + } + } } diff --git a/pom.xml b/pom.xml index c3b80202a01..0c3c9f526cb 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ <thrift.version>0.14.1</thrift.version> <xz.version>1.9</xz.version> <zstd-jni.version>1.5.6-3</zstd-jni.version> - <tsfile.version>2.2.1-260115-SNAPSHOT</tsfile.version> + <tsfile.version>2.2.1-260129-2-SNAPSHOT</tsfile.version> </properties> <!-- if we claim dependencies in dependencyManagement, then we do not claim
