srchilukoori commented on code in PR #65982: URL: https://github.com/apache/airflow/pull/65982#discussion_r3188931886
########## providers/google/tests/system/google/cloud/dataproc/example_dataproc_cancel_on_kill.py: ########## @@ -0,0 +1,201 @@ +# +# 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. +""" +Example Airflow DAG that tests cancel_on_kill behavior for Dataproc triggers. + +Test A (happy path): Submits a Spark job in deferrable mode with cancel_on_kill=True +and verifies it completes successfully. + +Test B (cancel path): Submits a long-running Spark job asynchronously, cancels it +via DataprocHook.cancel_job() — the same call that trigger.on_kill() delegates to — +and verifies the job reaches CANCELLED state. +""" + +from __future__ import annotations + +import os +import time +from datetime import datetime + +import pytest +from google.api_core.retry import Retry +from google.cloud.dataproc_v1 import JobStatus + +from airflow.models.dag import DAG +from airflow.providers.google.cloud.hooks.dataproc import DataprocHook +from airflow.providers.google.cloud.operators.dataproc import ( + DataprocCreateClusterOperator, + DataprocDeleteClusterOperator, + DataprocSubmitJobOperator, +) + +from system.google import DEFAULT_GCP_SYSTEM_TEST_PROJECT_ID +from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS + +if AIRFLOW_V_3_0_PLUS: + from airflow.sdk import TriggerRule, task +else: + from airflow.decorators import task # type: ignore[attr-defined,no-redef] + from airflow.utils.trigger_rule import TriggerRule # type: ignore[no-redef,attr-defined] + +pytestmark = pytest.mark.skipif( + not os.environ.get("RUN_MANUAL_DATAPROC_CANCEL_ON_KILL_TEST"), + reason="Manual-only system test: set RUN_MANUAL_DATAPROC_CANCEL_ON_KILL_TEST=1 to run.", Review Comment: done -- 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]
