or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/maven-org-apache-flink--flink-end-to-end-tests-2-11

End-to-end testing framework for Apache Flink stream processing with classloader behavior validation.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.flink/flink-end-to-end-tests_2.11@1.4.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-flink--flink-end-to-end-tests-2-11@1.4.0

index.mddocs/

Flink End-to-End Tests

The Flink End-to-End Tests module provides specialized testing utilities for validating Apache Flink's classloader behavior and resolution order settings. This package is designed for end-to-end integration testing scenarios, specifically focusing on verifying that Flink's classloader isolation and resolution mechanisms work correctly across different deployment environments.

Package Information

  • Package Name: flink-end-to-end-tests_2.11
  • Package Type: maven
  • Language: Java
  • Installation: Maven dependency:
    <dependency>
      <groupId>org.apache.flink</groupId>
      <artifactId>flink-end-to-end-tests_2.11</artifactId>
      <version>1.4.2</version>
    </dependency>

Core Imports

// Main test classes
import org.apache.flink.streaming.tests.ClassLoaderTestProgram;
import org.apache.flink.runtime.taskmanager.TaskManager;

// Required Flink API imports for streaming execution
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.core.fs.FileSystem;

// Standard Java imports for resource handling
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;

Basic Usage

// Run as a command-line application with required parameters
java -cp ClassLoaderTestProgram.jar org.apache.flink.streaming.tests.ClassLoaderTestProgram \
  --resolve-order parent-first \
  --output /path/to/output/file

// Or programmatically execute the main method
String[] args = {"--resolve-order", "child-first", "--output", "/tmp/test-results.txt"};
ClassLoaderTestProgram.main(args);

Architecture

The testing framework is built around a clever classloader validation mechanism:

  • ClassLoaderTestProgram: Main test program that creates a Flink streaming job to validate classloader behavior
  • Fake TaskManager: A substitute class sharing the same package name as Flink's real TaskManager
  • Classloader Resolution Testing: Uses method availability to verify parent-first vs child-first loading behavior
  • Resource Loading Validation: Tests classpath resource loading order through .version.properties files

The test works by attempting to call a method (getMessage()) that exists only in the fake TaskManager class. With parent-first classloading, Flink's real TaskManager is loaded (which lacks this method, causing NoSuchMethodError). With child-first classloading, the fake TaskManager is loaded (allowing the method call to succeed).

Capabilities

Classloader Test Program

Main test program that validates Flink's classloader resolution order settings through a streaming job execution.

public class ClassLoaderTestProgram {
    /**
     * Entry point for the classloader test program.
     * Creates and executes a Flink streaming job that validates classloader behavior.
     * 
     * @param args String array of command line arguments containing:
     *             --resolve-order: "parent-first" or "child-first" (required)
     *             --output: Output file path for test results (required)
     * 
     * @throws Exception If execution fails, invalid parameters provided, or streaming job execution fails
     * @throws RuntimeException If resolve-order is invalid or unexpected classloader behavior occurs
     */
    public static void main(String[] args) throws Exception;
}

Usage Example:

// Test parent-first classloader behavior
String[] parentFirstArgs = {
    "--resolve-order", "parent-first",
    "--output", "/tmp/parent-first-results.txt"
};
ClassLoaderTestProgram.main(parentFirstArgs);

// Test child-first classloader behavior  
String[] childFirstArgs = {
    "--resolve-order", "child-first", 
    "--output", "/tmp/child-first-results.txt"
};
ClassLoaderTestProgram.main(childFirstArgs);

Test TaskManager Utility

Fake TaskManager class used for classloader behavior validation, providing a method that doesn't exist in Flink's real TaskManager.

public class TaskManager {
    /**
     * Test method used to validate child-first classloader behavior.
     * This method only exists in the test TaskManager, not in Flink's real TaskManager.
     * 
     * @return String Always returns "Hello, World!" when child-first classloading is active
     * @throws NoSuchMethodError When parent-first classloading is active (expected behavior)
     */
    public static String getMessage();
}

Usage Example:

// This will work only with child-first classloading
try {
    String message = TaskManager.getMessage();
    System.out.println("Child-first loading successful: " + message);
} catch (NoSuchMethodError e) {
    System.out.println("Parent-first loading detected");
}

Test Execution Flow

  1. Parameter Processing: Parses command-line arguments for resolve-order and output path
  2. Stream Creation: Creates a simple Flink streaming environment processing a single "Hello" element
  3. Classloader Testing: Within the map function:
    • Loads .version.properties from classpath
    • Attempts to call TaskManager.getMessage() method
    • Validates behavior based on configured resolve-order
  4. Result Generation: Outputs formatted test results including:
    • Resolution behavior indicator ("NoSuchMethodError" or "Hello, World!")
    • Git URL from properties file
    • Complete classpath resource information
  5. File Output: Writes results to specified output file

Error Handling

The test program handles several error conditions:

  • Missing Parameters: Throws exception if required --resolve-order or --output parameters are missing
  • Invalid Resolve Order: Throws RuntimeException for resolve-order values other than "parent-first" or "child-first"
  • Unexpected Behavior: Throws RuntimeException if parent-first loading doesn't produce expected NoSuchMethodError
  • Wrong Message: Throws RuntimeException if child-first loading returns incorrect message from fake TaskManager

Output Format

Test execution produces structured output in the format:

[BEHAVIOR_INDICATOR]:[GIT_URL]:[ORDERED_PROPERTIES]

Where:

  • BEHAVIOR_INDICATOR: Either "NoSuchMethodError" (parent-first) or "Hello, World!" (child-first)
  • GIT_URL: Git repository URL from .version.properties
  • ORDERED_PROPERTIES: Concatenated git URLs from all classpath .version.properties resources

Maven Integration

The package provides specialized Maven configuration for creating executable JARs:

  • ClassLoaderTestProgram.jar: Self-contained executable JAR with manifest entry pointing to main class
  • Includes: Compiled test classes and .version.properties resource file
  • Build Integration: Automated JAR renaming for easier reference in test scripts

This module is essential for maintaining the reliability and consistency of Flink applications across different deployment environments and ensuring proper isolation of user code from Flink's internal dependencies.