uranusjr commented on code in PR #65956:
URL: https://github.com/apache/airflow/pull/65956#discussion_r3323514347


##########
airflow-e2e-tests/tests/airflow_e2e_tests/conftest.py:
##########
@@ -234,6 +240,99 @@ def _setup_xcom_object_storage_integration(dot_env_file, 
tmp_dir):
     os.environ["ENV_FILE_PATH"] = str(dot_env_file)
 
 
+def _setup_java_sdk_integration(dot_env_file, tmp_dir):
+    """Set up the java_sdk E2E test mode.
+
+    Builds the Java example bundle via the Gradle wrapper, then builds a
+    Java-capable Airflow worker image, copies the JARs into the temp directory,
+    and writes the coordinator configuration.
+    """
+    # Build the example bundle inside an ephemeral JDK container so the host
+    # does not need Java installed.
+    #
+    # --user keeps build outputs owned by the current user (not root).
+    # GRADLE_USER_HOME persists the Gradle distribution and dependency cache in
+    # java-sdk/.gradle/ (already gitignored) so the first run downloads once
+    # and subsequent runs skip straight to compilation.
+    # --no-daemon avoids a background JVM that would outlive the container.
+    console.print("[yellow]Building Java SDK example bundle 
(eclipse-temurin:17-jdk)...")
+    subprocess.run(
+        [
+            "docker",
+            "run",
+            "--rm",
+            "--user",
+            f"{os.getuid()}:{os.getgid()}",
+            "-e",
+            "GRADLE_USER_HOME=/repo/java-sdk/.gradle",
+            # Mount java-sdk/ at /java-sdk (the Gradle root project).
+            "-v",
+            f"{AIRFLOW_ROOT_PATH}:/repo",
+            "-w",
+            "/repo/java-sdk",
+            "eclipse-temurin:17-jdk",
+            "./gradlew",
+            ":example:installDist",
+            "--no-daemon",
+        ],
+        check=True,
+    )
+
+    # Copy compose override and Dockerfile into the temp directory.
+    copyfile(JAVA_COMPOSE_PATH, tmp_dir / "java.yml")
+    copyfile(JAVA_DOCKERFILE_PATH, tmp_dir / "Dockerfile.java")
+
+    # Copy all JARs from installDist output so the compose bind-mount ./jars
+    # gives the worker everything JavaCoordinator needs to build a classpath.
+    copytree(JAVA_SDK_EXAMPLE_LIBS_PATH, tmp_dir / "jars")
+
+    # Copy the Java SDK example Dag file so Airflow can discover it.
+    copyfile(JAVA_SDK_DAGS_PATH / "java_examples.py", tmp_dir / "dags" / 
"java_examples.py")
+
+    # Build a local Docker image that extends DOCKER_IMAGE with a JRE.
+    # We do this explicitly so testcontainers' DockerCompose.start() does not
+    # need to handle the build itself (which avoids --no-build vs --build flag
+    # uncertainty across testcontainers versions).
+    console.print(f"[yellow]Building airflow-java-worker image on top of 
{DOCKER_IMAGE}...")
+    subprocess.run(
+        [
+            "docker",
+            "build",
+            "--build-arg",
+            f"DOCKER_IMAGE={DOCKER_IMAGE}",
+            "-t",
+            "airflow-java-worker",
+            "-f",
+            str(tmp_dir / "Dockerfile.java"),
+            str(tmp_dir),
+        ],
+        check=True,
+    )
+
+    # Coordinator registry: maps the logical name "java-jdk" to 
JavaCoordinator.
+    # Queue mapping: routes tasks on the "java" Celery queue to "java-jdk".
+    coordinator_config = json.dumps(
+        {
+            "java-jdk": {
+                "classpath": "airflow.sdk.coordinators.java.JavaCoordinator",
+                "kwargs": {"jars_root": ["/opt/airflow/jars"]},
+            }
+        }
+    )
+    queue_to_coordinator = json.dumps({"java": "java-jdk"})

Review Comment:
   In the current test I simply `apt-get install` the default JRE; it’ll be a 
bit more complicated if we want more than one Java installation, even more so 
if we want to pin the version. Probably a good idea, but better as a todo later 
on.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to