iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

Remove JUnit4 dependency from Flink

Open nastra opened this issue 1 year ago • 22 comments

Feature Request / Improvement

I started removing JUnit4 from Flink via the below diff

diff --git a/flink/v2.0/build.gradle b/flink/v2.0/build.gradle
index c0de408e98..ef4635e133 100644
--- a/flink/v2.0/build.gradle
+++ b/flink/v2.0/build.gradle
@@ -68,7 +68,9 @@ project(":iceberg-flink:iceberg-flink-${flinkMajorVersion}") {

     implementation libs.datasketches

-    testImplementation libs.flink20.connector.test.utils
+    testImplementation(libs.flink20.connector.test.utils) {
+      exclude group: 'junit'
+    }
     testImplementation libs.flink20.core
     testImplementation libs.flink20.runtime
     testImplementation(libs.flink20.test.utilsjunit) {
diff --git a/flink/v2.0/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergSink.java b/flink/v2.0/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergSink.java
index b02b3337dc..362d004cfe 100644
--- a/flink/v2.0/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergSink.java
+++ b/flink/v2.0/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergSink.java
@@ -21,6 +21,7 @@ package org.apache.iceberg.flink.sink;
 import static org.apache.iceberg.flink.TestFixtures.DATABASE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assumptions.assumeThat;

 import java.io.IOException;
 import java.util.Collections;
@@ -55,7 +56,6 @@ import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
 import org.apache.iceberg.relocated.com.google.common.collect.Lists;
 import org.apache.iceberg.relocated.com.google.common.collect.Maps;
 import org.apache.iceberg.types.Types;
-import org.junit.Assume;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.TestTemplate;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -421,8 +421,9 @@ public class TestIcebergSink extends TestFlinkIcebergSinkBase {

   @TestTemplate
   void testErrorOnNullForRequiredField() throws Exception {
-    Assume.assumeFalse(
-        "ORC file format supports null values even for required fields.", format == FileFormat.ORC);
+    assumeThat(format)
+        .as("ORC file format supports null values even for required fields.")
+        .isEqualTo(FileFormat.ORC);

However, there is still TestIcebergSourceFailover that uses MiniClusterWithClientResource which requires JUnit4. This would be good to convert so that we can eventually remove all JUnit4 dependencies across the codebase. We would also need to backport the fix to Flink 1.20 & 1.19.

Query engine

None

Willingness to contribute

  • [ ] I can contribute this improvement/feature independently
  • [ ] I would be willing to contribute this improvement/feature with guidance from the Iceberg community
  • [x] I cannot contribute this improvement/feature at this time

nastra avatar Apr 30 '25 08:04 nastra

@nastra I can work for this to remove JUnit 4 along with the Spark migration. But if anyone is already working on this or will work, I could collaborate the migration for this.

tomtongue avatar Apr 30 '25 11:04 tomtongue

@nastra I can work for this to remove JUnit 4 along with the Spark migration. But if anyone is already working on this or will work, I could collaborate the migration for this.

Hello, I'm a developer who is eager to properly learn Apache Iceberg and contribute to the project. I would love to work on this issue and submit a PR—would that be okay?

JeonDaehong avatar May 07 '25 21:05 JeonDaehong

@JeonDaehong welcome to the community. We always welcome new contributions, so feel free to work on this. You might also want to sync up with @tomtongue, since he expressed interest as well.

nastra avatar May 08 '25 05:05 nastra

@JeonDaehong welcome to the community. We always welcome new contributions, so feel free to work on this. You might also want to sync up with @tomtongue, since he expressed interest as well.

Thank you! It would be great to work together on this. I'll start by forking the project and begin making and testing changes from today.

JeonDaehong avatar May 08 '25 05:05 JeonDaehong

@JeonDaehong thanks for helping this, as @nastra is mentioning, I will be able to work for Flink migration, but maybe I'll take a little bit time for starting the Flink migration, so it would be great if you start working on this first.

tomtongue avatar May 08 '25 05:05 tomtongue

@JeonDaehong thanks for helping this, as @nastra is mentioning, I will be able to work for Flink migration, but maybe I'll take a little bit time for starting the Flink migration, so it would be greate if you start working on this first.

Alright !

Once I complete the migration work and confirm the tests pass successfully, I’ll open a PR and reference this issue link. It might take a bit of time, but I’ll do my best to achieve a good result.

Thank you!

JeonDaehong avatar May 08 '25 06:05 JeonDaehong

@nastra @tomtongue

Would it be okay to migrate only the TestIcebergSourceFailover class, which uses MiniClusterWithClientResource, to JUnit 5 and run the build/test to verify everything works? (Planning to apply the same change to both the 1.20 and 1.19 packages as well.)

Since this is my first PR contribution, I wanted to ask and make sure! :D

JeonDaehong avatar May 08 '25 14:05 JeonDaehong

@JeonDaehong ideally what we want is to be able to remove the JUnit4 dependency from Flink via the diff outlined in the issue description. So I would use the diff + the changes required for TestIcebergSourceFailover. I would suggest that you first do the changes for Flink 2.0. Once everything looks good you can backport those changes to earlier Flink versions.

nastra avatar May 08 '25 15:05 nastra

@JeonDaehong ideally what we want is to be able to remove the JUnit4 dependency from Flink via the diff outlined in the issue description. So I would use the diff + the changes required for TestIcebergSourceFailover. I would suggest that you first do the changes for Flink 2.0. Once everything looks good you can backport those changes to earlier Flink versions.

Thank you. I'll modify the three classes and backport the changes from 2.0 to 1.9 in that order

JeonDaehong avatar May 08 '25 22:05 JeonDaehong

https://github.com/apache/iceberg/pull/13016

@nastra Hello,

I have removed the MiniClusterWithClientResource class, which was still dependent on JUnit4, and have also incorporated changes to the gradle and TestIcebergSink classes.

Since this is my first time doing this, could you please confirm if the approach is correct? If so, I kindly request you to approve the merge.

If this direction is correct, I will proceed with backporting to versions 1.20 and 1.19.

I will continue working hard. Thank you.

JeonDaehong avatar May 09 '25 14:05 JeonDaehong

#13016

@nastra Hello,

I have removed the MiniClusterWithClientResource class, which was still dependent on JUnit4, and have also incorporated changes to the gradle and TestIcebergSink classes.

Since this is my first time doing this, could you please confirm if the approach is correct? If so, I kindly request you to approve the merge.

If this direction is correct, I will proceed with backporting to versions 1.20 and 1.19.

I will continue working hard. Thank you.

If this is not the correct approach, I will close this PR and make the necessary changes based on your feedback

JeonDaehong avatar May 09 '25 14:05 JeonDaehong

It looks like we can't easily remove JUnit4 from Flink because InternalMiniClusterExtension still depends on having JUnit4 on the classpath. Nevertheless, we should stop using JUnit4 stuff ourselves at the very least.

nastra avatar May 12 '25 08:05 nastra

This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

github-actions[bot] avatar Nov 09 '25 00:11 github-actions[bot]

@nastra i would like to contribute to this if this is open ?

Jayesh45-master avatar Dec 24 '25 19:12 Jayesh45-master

@Jayesh45-master it is still open, so feel free to do some investigation here

nastra avatar Jan 07 '26 08:01 nastra

Hi @nastra this issue has been marked stale should i still investigate this as i am new and would love to contribute in any way i can.

A0R0P0I7T avatar Jan 28 '26 18:01 A0R0P0I7T

@A0R0P0I7T this issue is still valid, so feel free to investigate, thanks.

nastra avatar Jan 29 '26 07:01 nastra

Hi @nastra, I'd like to work on this. From my investigation, all Flink test code (v1.20, v2.0, v2.1) has already been migrated to JUnit5 — the remaining flink-test-utils-junit dependency in the three build.gradle files is vestigial and can be safely removed along with the corresponding entries in libs.versions.toml. I'll submit a PR shortly.

sachinnn99 avatar Mar 28 '26 09:03 sachinnn99

Unclaiming — the remaining JUnit4 dependency is pulled in transitively via Flink's InternalMiniClusterExtension and can't be removed from our side. Freeing this up for others.

sachinnn99 avatar Apr 07 '26 10:04 sachinnn99

https://issues.apache.org/jira/browse/FLINK-25325 SubTasks 85-107 are related to the flink-runtime package's test migration. I think we need to track them to see when they can be resolved.

lisirrx avatar Apr 14 '26 16:04 lisirrx