From 88c08c807e279dbea234669a6653e31a156d2f32 Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Mon, 3 Aug 2026 12:23:38 +0200 Subject: [PATCH 1/5] [FLINK-40311][tests] Rename `EndiannessAccessChecks` to `EndiannessAccessChecksTest` --- ...iannessAccessChecks.java => EndiannessAccessChecksTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename flink-core/src/test/java/org/apache/flink/core/memory/{EndiannessAccessChecks.java => EndiannessAccessChecksTest.java} (99%) diff --git a/flink-core/src/test/java/org/apache/flink/core/memory/EndiannessAccessChecks.java b/flink-core/src/test/java/org/apache/flink/core/memory/EndiannessAccessChecksTest.java similarity index 99% rename from flink-core/src/test/java/org/apache/flink/core/memory/EndiannessAccessChecks.java rename to flink-core/src/test/java/org/apache/flink/core/memory/EndiannessAccessChecksTest.java index 053c895cac9bb..06b3fe78fb7c0 100644 --- a/flink-core/src/test/java/org/apache/flink/core/memory/EndiannessAccessChecks.java +++ b/flink-core/src/test/java/org/apache/flink/core/memory/EndiannessAccessChecksTest.java @@ -29,7 +29,7 @@ * Verifies correct accesses with regards to endianness in {@link MemorySegment} (in both heap and * off-heap modes). */ -class EndiannessAccessChecks { +class EndiannessAccessChecksTest { @Test void testOnHeapSegment() { From 3cffa3ce75a966043d6aaee3483e3a3fd134bec7 Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Mon, 3 Aug 2026 12:25:05 +0200 Subject: [PATCH 2/5] [FLINK-40310][tests] Rename `CsvBulkWriterIT` to `CsvBulkWriterTest` --- ...vBulkWriterIT.java => CsvBulkWriterITCase.java} | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) rename flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/{CsvBulkWriterIT.java => CsvBulkWriterITCase.java} (92%) diff --git a/flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/CsvBulkWriterIT.java b/flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/CsvBulkWriterITCase.java similarity index 92% rename from flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/CsvBulkWriterIT.java rename to flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/CsvBulkWriterITCase.java index aa070b22abad5..349c7c9461da4 100644 --- a/flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/CsvBulkWriterIT.java +++ b/flink-formats/flink-csv/src/test/java/org/apache/flink/formats/csv/CsvBulkWriterITCase.java @@ -27,10 +27,13 @@ import org.apache.flink.connector.datagen.source.TestDataGenerators; import org.apache.flink.connector.file.sink.FileSink; import org.apache.flink.core.fs.FSDataOutputStream; +import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.test.junit5.MiniClusterExtension; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; import java.io.File; @@ -44,7 +47,14 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CsvBulkWriterIT { +class CsvBulkWriterITCase { + + @RegisterExtension + static final MiniClusterExtension MINI_CLUSTER = + new MiniClusterExtension( + new MiniClusterResourceConfiguration.Builder() + .setNumberTaskManagers(2) + .build()); @TempDir File outDir; @@ -53,7 +63,7 @@ public class CsvBulkWriterIT { * flush signal from Flink. */ @Test - public void testNoDataIsWrittenBeforeFlinkFlush() throws Exception { + void testNoDataIsWrittenBeforeFlinkFlush() throws Exception { Configuration config = new Configuration(); config.set( From 7c829b8f568d0a3c4210960f2bdd10bfbf1641b6 Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Tue, 4 Aug 2026 09:06:33 +0200 Subject: [PATCH 3/5] [FLINK-40307][table] was never executed in CI --- ....java => RestoreTestCompletenessTest.java} | 84 +++++++++++++------ 1 file changed, 60 insertions(+), 24 deletions(-) rename flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/{RestoreTestCompleteness.java => RestoreTestCompletenessTest.java} (60%) diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/RestoreTestCompleteness.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/RestoreTestCompletenessTest.java similarity index 60% rename from flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/RestoreTestCompleteness.java rename to flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/RestoreTestCompletenessTest.java index 9e6e124449a22..99ac5b09182ee 100644 --- a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/RestoreTestCompleteness.java +++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/testutils/RestoreTestCompletenessTest.java @@ -19,6 +19,13 @@ package org.apache.flink.table.planner.plan.nodes.exec.testutils; import org.apache.flink.table.planner.plan.nodes.exec.ExecNode; +import org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecHashAggregate; +import org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecNestedLoopJoin; +import org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecSortAggregate; +import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecDeltaJoin; +import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecGlobalWindowAggregate; +import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecLocalWindowAggregate; +import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecProcessTableFunction; import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecPythonCalc; import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecPythonCorrelate; import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecPythonGroupAggregate; @@ -30,7 +37,6 @@ import org.apache.flink.shaded.guava33.com.google.common.reflect.ClassPath; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -42,21 +48,34 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.assertj.core.api.Assertions.fail; + /** Validate restore tests exists for Exec Nodes. */ -public class RestoreTestCompleteness { +class RestoreTestCompletenessTest { private static final Set>> SKIP_EXEC_NODES = - new HashSet>>() { - { - /** Ignoring python based exec nodes temporarily. */ - add(StreamExecPythonCalc.class); - add(StreamExecPythonCorrelate.class); - add(StreamExecPythonOverAggregate.class); - add(StreamExecPythonGroupAggregate.class); - add(StreamExecPythonGroupTableAggregate.class); - add(StreamExecPythonGroupWindowAggregate.class); - } - }; + Set.of( + /* Ignoring python based exec nodes temporarily. */ + StreamExecPythonCalc.class, + StreamExecPythonCorrelate.class, + StreamExecPythonOverAggregate.class, + StreamExecPythonGroupAggregate.class, + StreamExecPythonGroupTableAggregate.class, + StreamExecPythonGroupWindowAggregate.class, + + // Covered by tests in WindowAggregateEventTimeRestoreTest + StreamExecLocalWindowAggregate.class, + StreamExecGlobalWindowAggregate.class, + // restore tests for delta join and PTF were added in later releases + StreamExecDeltaJoin.class, + StreamExecProcessTableFunction.class, + + // There is jira for these 2 batch tests + // https://issues.apache.org/jira/browse/FLINK-40306 + BatchExecHashAggregate.class, + BatchExecNestedLoopJoin.class, + // restore tests for batch sort aggregate was added in later releases + BatchExecSortAggregate.class); private Class> getExecNode(Class restoreTest) throws NoSuchMethodException, @@ -85,7 +104,7 @@ private List>> getChildExecNodes(Class restoreTes } @Test - public void testMissingRestoreTest() + void testMissingRestoreTest() throws IOException, NoSuchMethodException, InstantiationException, @@ -95,12 +114,14 @@ public void testMissingRestoreTest() ExecNodeMetadataUtil.getVersionedExecNodes(); Set classesInPackage = - ClassPath.from(this.getClass().getClassLoader()) - .getTopLevelClassesRecursive( - "org.apache.flink.table.planner.plan.nodes.exec.stream") - .stream() - .filter(x -> RestoreTestBase.class.isAssignableFrom(x.load())) - .collect(Collectors.toSet()); + new HashSet<>( + gatherClasses( + RestoreTestBase.class, + "org.apache.flink.table.planner.plan.nodes.exec.stream")); + classesInPackage.addAll( + gatherClasses( + BatchRestoreTestBase.class, + "org.apache.flink.table.planner.plan.nodes.exec.batch")); Set>> execNodesWithRestoreTests = new HashSet<>(); @@ -116,18 +137,33 @@ public void testMissingRestoreTest() } } + Set>> productionExecNodes = ExecNodeMetadataUtil.execNodes(); for (Map.Entry>> entry : versionedExecNodes.entrySet()) { ExecNodeNameVersion execNodeNameVersion = entry.getKey(); Class> execNode = entry.getValue(); - if (!SKIP_EXEC_NODES.contains(execNode)) { - final String msg = + // Ignore test-only nodes that other tests leak into the shared LOOKUP_MAP via + // addTestNode(). + if (!productionExecNodes.contains(execNode)) { + continue; + } + if (!SKIP_EXEC_NODES.contains(execNode) + && !execNodesWithRestoreTests.contains(execNode)) { + fail( "Missing restore test for " + execNodeNameVersion + "\nPlease add a restore test for " - + execNode.toString(); - Assertions.assertTrue(execNodesWithRestoreTests.contains(execNode), msg); + + execNode.toString()); } } } + + private Set gatherClasses(Class clazz, String packageName) + throws IOException { + return ClassPath.from(this.getClass().getClassLoader()) + .getTopLevelClassesRecursive(packageName) + .stream() + .filter(x -> clazz.isAssignableFrom(x.load())) + .collect(Collectors.toSet()); + } } From b989e2af2c3c1c8d2bfbc1975b163ca65af4d241 Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Mon, 3 Aug 2026 12:46:46 +0200 Subject: [PATCH 4/5] [FLINK-40284][tests] Make tests ending with `Tests` executing in CI --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b366431452bc9..d9f01ea355847 100644 --- a/pom.xml +++ b/pom.xml @@ -217,7 +217,7 @@ under the License. - **/*Test.* + **/*Test.*,**/Tests.* 1.1.10.7 3.18.0 From ccfdf455dce023c8f6c74541c461a3ebeef65ab9 Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Mon, 3 Aug 2026 12:35:20 +0200 Subject: [PATCH 5/5] [FLINK-40284][tests] Archunit should fail in case of tests not matching name requirements This closes #28887. --- .../TestCodeArchitectureTestBase.java | 3 + .../architecture/rules/TestNamingRules.java | 86 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/TestNamingRules.java diff --git a/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/TestCodeArchitectureTestBase.java b/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/TestCodeArchitectureTestBase.java index a33ad9b6d6653..9b7984d002b75 100644 --- a/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/TestCodeArchitectureTestBase.java +++ b/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/TestCodeArchitectureTestBase.java @@ -19,6 +19,7 @@ package org.apache.flink.architecture; import org.apache.flink.architecture.rules.ITCaseRules; +import org.apache.flink.architecture.rules.TestNamingRules; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.junit.ArchTests; @@ -33,4 +34,6 @@ public class TestCodeArchitectureTestBase { @ArchTest public static final ArchTests ITCASE = ArchTests.in(ITCaseRules.class); + + @ArchTest public static final ArchTests TEST_NAMING = ArchTests.in(TestNamingRules.class); } diff --git a/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/TestNamingRules.java b/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/TestNamingRules.java new file mode 100644 index 0000000000000..79810fa043f72 --- /dev/null +++ b/flink-architecture-tests/flink-architecture-tests-test/src/main/java/org/apache/flink/architecture/rules/TestNamingRules.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.architecture.rules; + +import com.tngtech.archunit.base.DescribedPredicate; +import com.tngtech.archunit.core.domain.JavaClass; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.lang.ArchRule; + +import java.util.Arrays; +import java.util.List; + +import static com.tngtech.archunit.core.domain.JavaModifier.ABSTRACT; +import static org.apache.flink.architecture.common.GivenJavaClasses.javaClassesThat; + +/** + * Rules ensuring executable test classes are named so the build actually runs them. + * + *

Surefire only runs the unit include pattern {@code **}{@code /*Test.*} in the {@code test} + * phase; integration tests follow the {@code *ITCase} convention. A concrete class that carries (or + * inherits) JUnit test methods but is named otherwise (e.g. {@code *Tests}) is silently skipped by + * the unit run. This rule flags such classes so they are renamed to {@code *Test} or {@code + * *ITCase}. + */ +public class TestNamingRules { + + /** JUnit 5 and (for modules still mid-migration) JUnit 4 test method annotations. */ + private static final List TEST_METHOD_ANNOTATIONS = + Arrays.asList( + "org.junit.jupiter.api.Test", + "org.junit.jupiter.api.TestTemplate", + "org.junit.jupiter.api.RepeatedTest", + "org.junit.jupiter.api.TestFactory", + "org.junit.jupiter.params.ParameterizedTest", + "org.junit.Test"); + + /** + * A class JUnit would execute: it declares or inherits a test method. {@code getAllMethods()} + * covers inherited {@code @TestTemplate} methods, e.g. semantic-test suites that only extend a + * base and add no annotation themselves. + */ + private static final DescribedPredicate ARE_EXECUTABLE_TEST_CLASSES = + DescribedPredicate.describe( + "are executable JUnit test classes", + clazz -> + clazz.getAllMethods().stream() + .anyMatch( + method -> + TEST_METHOD_ANNOTATIONS.stream() + .anyMatch(method::isAnnotatedWith))); + + @ArchTest + public static final ArchRule TEST_CLASSES_SHOULD_BE_NAMED_TEST_OR_ITCASE = + javaClassesThat() + .areTopLevelClasses() + .and() + .doNotHaveModifier(ABSTRACT) + .and(ARE_EXECUTABLE_TEST_CLASSES) + .should() + .haveSimpleNameEndingWith("Test") + .orShould() + .haveSimpleNameEndingWith("Tests") + .orShould() + .haveSimpleNameEndingWith("ITCase") + // not every module has such classes + .allowEmptyShould(true) + .as( + "Executable test classes must be named *Test[s] or *ITCase so the surefire " + + "include pattern runs them"); +}