Test utilities for validating user classloader functionality in Apache Flink client components
npx @tessl/cli install tessl/maven-org-apache-flink--flink-clients-test-utils@2.1.0A specialized test utility module within the Apache Flink ecosystem that provides test classes for validating user classloader functionality in Flink client components. This module creates test JAR files with different configurations to ensure robust classloading behavior across various deployment scenarios.
<scope>test</scope><dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients-test-utils</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>import org.apache.flink.client.testjar.TestUserClassLoaderJob;
import org.apache.flink.client.testjar.TestUserClassLoaderAdditionalArtifact;Note: TestUserClassLoaderJobLib is package-private and used internally.
The primary usage is through the generated test JAR artifacts rather than direct class instantiation:
// Example of running the test job JAR
// java -cp test-user-classloader-job-jar.jar org.apache.flink.client.testjar.TestUserClassLoaderJob --arg testValue
// The job creates a simple data stream and executes it
public static void main(String[] args) throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
final DataStreamSource<Integer> source =
env.fromData(new TestUserClassLoaderJobLib().getValue(), 1, 2, 3, 4);
final SingleOutputStreamOperator<Integer> mapper = source.map(element -> 2 * element);
mapper.sinkTo(new DiscardingSink<>());
ParameterTool parameterTool = ParameterTool.fromArgs(args);
env.execute(
TestUserClassLoaderJob.class.getCanonicalName()
+ "-"
+ parameterTool.getRequired("arg"));
}The module uses Maven Shade Plugin to create three separate test JAR artifacts:
Each JAR is designed to test different aspects of Flink's user classloader functionality when jobs are submitted that are not in the system classpath.
The primary test job class that creates and executes a simple Flink streaming job for classloader validation.
public class TestUserClassLoaderJob {
/**
* Main entry point for the test job.
* Creates a simple streaming pipeline with data transformation and discarding sink.
*
* @param args Command line arguments, must include "arg" parameter
* @throws Exception If job execution fails or "arg" parameter is missing
*/
public static void main(String[] args) throws Exception;
}A test class for validating classloading from additional user artifacts, providing simple functionality for testing purposes.
public class TestUserClassLoaderAdditionalArtifact {
/**
* Returns a constant integer value for testing purposes.
* Package-private method for internal testing use.
*
* @return Always returns 1
*/
int getNum(); // package-private
}Internal support class used by the main test job, not intended for direct external usage.
class TestUserClassLoaderJobLib {
/**
* Returns a constant integer value used by TestUserClassLoaderJob.
*
* @return Always returns 0
*/
int getValue();
/**
* Empty main method for testing purposes.
*
* @param args Command line arguments (unused)
*/
public static void main(String[] args);
}The module generates three test JAR artifacts through Maven Shade Plugin configuration:
Testing Example:
# Submit job to Flink cluster to test user classloader isolation
./bin/flink run \
--class org.apache.flink.client.testjar.TestUserClassLoaderJob \
test-user-classloader-job-jar.jar \
--arg myTestValueThis module has minimal dependencies:
The provided scope ensures these dependencies are available at runtime through the Flink cluster environment but not bundled in the test JAR artifacts.
The main test job will throw exceptions in the following scenarios:
ParameterTool.getRequired("arg") will throw if the required argument is not providedThese exceptions are intentional for testing Flink's error handling and job submission mechanisms.
This module is specifically designed for testing Flink's user classloader functionality in various scenarios:
test-user-classloader-job-lib-jar to test intra-JAR dependency resolutiontest-user-classloader-additional-artifact-jar to test multi-JAR scenariosThese utilities are typically used in: