def test_all_listen_events(self): event = self.client.send_event(Event(key="key", value="value1")) event = self.client.send_event(Event(key="key", value="value2")) start_time = event.create_time event = self.client.send_event(Event(key="key", value="value3")) events = self.client.list_all_events(start_time) self.assertEqual(2, len(events))
def test_listen_all_events(self): event_list = [] class TestWatch(EventWatcher): def __init__(self, event_list) -> None: super().__init__() self.event_list = event_list def process(self, events: List[Event]): self.event_list.extend(events) try: self.client.start_listen_events(watcher=TestWatch(event_list)) event = self.client.send_event(Event(key="key1", value="value1")) event = self.client.send_event(Event(key="key2", value="value2")) event = self.client.send_event(Event(key="key3", value="value3")) finally: self.client.stop_listen_events() self.assertEqual(3, len(event_list))
def test_listen_events(self): event_list = [] class TestWatch(EventWatcher): def __init__(self, event_list) -> None: super().__init__() self.event_list = event_list def process(self, events: List[Event]): self.event_list.extend(events) event = self.client.send_event(Event(key="key", value="value1")) self.client.start_listen_event(key="key", watcher=TestWatch(event_list), version=1) event = self.client.send_event(Event(key="key", value="value2")) event = self.client.send_event(Event(key="key", value="value3")) self.client.stop_listen_event("key") events = self.client.list_events("key", version=1) self.assertEqual(2, len(events)) self.assertEqual(2, len(event_list))
from airflow.operators.bash_operator import BashOperator dag = DAG(dag_id='workflow_1', start_date=timezone.utcnow(), schedule_interval="@once") op_0 = BashOperator(task_id='0_job', dag=dag, bash_command='echo "0 hello word!"') op_1 = BashOperator(task_id='1_job', dag=dag, bash_command='echo "1 hello word!"') op_2 = SendEventOperator(task_id='2_job', dag=dag, uri='localhost:50051', event=Event(key='key_1', value='value_1', event_type='UNDEFINED')) op_3 = SendEventOperator(task_id='3_job', dag=dag, uri='localhost:50051', event=Event(key='key_2', value='value_2', event_type='UNDEFINED')) op_4 = BashOperator(task_id='4_job', dag=dag, bash_command='echo "4 hello word!"', env={"a": "a"}) op_5 = SendEventOperator(task_id='5_job', dag=dag, uri='localhost:50051', event=Event(key='key_2',
dag_id='test_stop_job', start_date=timezone.utcnow(), schedule_interval="@once") dag1_task1 = BashOperator( bash_command="sleep 1000", task_id='task_1', dag=dag1, owner='airflow') dag1_task2 = SendEventOperator( task_id='task_2', dag=dag1, owner='airflow', uri="localhost:{0}".format(port), event=Event(key="key_1", value="value_1")) dag1_task3 = BashOperator( bash_command="sleep 5", task_id='task_3', dag=dag1, owner='airflow') dag1_task4 = SendEventOperator( task_id='task_4', dag=dag1, owner='airflow', uri="localhost:{0}".format(port), event=Event(key="stop", value="value_1"))
port = conf.getint('scheduler', 'notification_port') dag1 = DAG(dag_id='test_restart_job', start_date=timezone.utcnow(), schedule_interval="@once") dag1_task1 = BashOperator(bash_command="sleep 15", task_id='task_1', dag=dag1, owner='airflow') dag1_task2 = SendEventOperator(task_id='task_2', dag=dag1, owner='airflow', uri="localhost:{0}".format(port), event=Event(key="key_1", value="value_1")) dag1_task3 = BashOperator(bash_command="sleep 5", task_id='task_3', dag=dag1, owner='airflow') dag1_task4 = SendEventOperator(task_id='task_4', dag=dag1, owner='airflow', uri="localhost:{0}".format(port), event=Event(key="restart", value="value_1")) dag1_task1.add_event_dependency("key_1", "UNDEFINED") dag1_task1.add_event_dependency("restart", "UNDEFINED") dag1_task1.set_event_met_handler(StopRestartEventMetHandler())
from airflow.utils import timezone from airflow.models import DAG from airflow.operators.dummy_operator import DummyOperator from airflow.settings import conf from tests.dags.event_met_handlers import RestartEventMetHandler port = conf.getint('scheduler', 'notification_port') dag1 = DAG(dag_id='test_start_scheduling', start_date=timezone.utcnow(), schedule_interval="@once") dag1_task1 = SendEventOperator(task_id='event_1', dag=dag1, owner='airflow', uri="localhost:{0}".format(port), event=Event(key="key_1", value="value_1")) dag1_task2 = DummyOperator(task_id='dummy_2', dag=dag1, owner='airflow') dag1_task3 = SendEventOperator(task_id='event_3', dag=dag1, owner='airflow', uri="localhost:{0}".format(port), event=Event(key="key_1", value="value_2")) dag1_task4 = DummyOperator(task_id='dummy_4', dag=dag1, owner='airflow') dag1_task5 = DummyOperator(task_id='dummy_5', dag=dag1, owner='airflow') dag1_stop_task = SendEventOperator(task_id='event_5', dag=dag1,
def test_list_events(self): event = self.client.send_event(Event(key="key", value="value1")) event = self.client.send_event(Event(key="key", value="value2")) event = self.client.send_event(Event(key="key", value="value3")) events = self.client.list_events("key", version=1) self.assertEqual(2, len(events))
def test_send_event(self): event = self.client.send_event(Event(key="key", value="value1")) self.assertEqual(1, event.version)
def test_send_event(self): event = self.client.send_event(Event(key="key", value="value1")) self.assertTrue(event.version > 0)