|
| 1 | +import time |
| 2 | +from functools import partial |
| 3 | + |
| 4 | +import boto3 |
| 5 | +import pytest |
| 6 | +from event.aws.client import dynamodb_client |
| 7 | + |
| 8 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 9 | + database_isnt_empty as _database_isnt_empty, |
| 10 | +) |
| 11 | +from etl.sds.tests.etl_test_utils.ask_s3 import extract_is_empty as _extract_is_empty |
| 12 | +from etl.sds.tests.etl_test_utils.ask_s3 import load_is_empty as _load_is_empty |
| 13 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 14 | + transform_is_empty as _transform_is_empty, |
| 15 | +) |
| 16 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 17 | + was_changelog_number_updated as _was_changelog_number_updated, |
| 18 | +) |
| 19 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 20 | + was_etl_state_lock_removed as _was_etl_state_lock_removed, |
| 21 | +) |
| 22 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 23 | + was_queue_history_created as _was_queue_history_created, |
| 24 | +) |
| 25 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 26 | + was_state_machine_history_created as _was_state_machine_history_created, |
| 27 | +) |
| 28 | +from etl.sds.tests.etl_test_utils.ask_s3 import ( |
| 29 | + was_trigger_key_deleted as _was_trigger_key_deleted, |
| 30 | +) |
| 31 | +from etl.sds.tests.etl_test_utils.etl_state import clear_etl_state, get_etl_config |
| 32 | +from etl.sds.worker.bulk.tests.test_bulk_e2e import PATH_TO_STAGE_DATA |
| 33 | + |
| 34 | +EXPECTED_CHANGELOG_NUMBER = 123 |
| 35 | + |
| 36 | + |
| 37 | +def message(x): |
| 38 | + print(x) # noqa |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.timeout(20) |
| 42 | +@pytest.mark.integration |
| 43 | +def test_bulk_trigger(): |
| 44 | + # Prerequisites |
| 45 | + with open(PATH_TO_STAGE_DATA / "0.extract_input.ldif") as f: |
| 46 | + input_data = f.read().encode() |
| 47 | + |
| 48 | + etl_config = get_etl_config(f"{EXPECTED_CHANGELOG_NUMBER}.ldif", etl_type="bulk") |
| 49 | + db_client = dynamodb_client() |
| 50 | + s3_client = boto3.client("s3") |
| 51 | + clear_etl_state(s3_client=s3_client, etl_config=etl_config) |
| 52 | + |
| 53 | + # Define questions |
| 54 | + was_trigger_key_deleted = partial( |
| 55 | + _was_trigger_key_deleted, s3_client=s3_client, etl_config=etl_config |
| 56 | + ) |
| 57 | + was_queue_history_created = partial( |
| 58 | + _was_queue_history_created, |
| 59 | + s3_client=s3_client, |
| 60 | + etl_config=etl_config, |
| 61 | + expected_content=input_data, |
| 62 | + ) |
| 63 | + was_state_machine_history_created = partial( |
| 64 | + _was_state_machine_history_created, |
| 65 | + s3_client=s3_client, |
| 66 | + etl_config=etl_config, |
| 67 | + expected_content=input_data, |
| 68 | + ) |
| 69 | + was_changelog_number_updated = partial( |
| 70 | + _was_changelog_number_updated, s3_client=s3_client, bucket=etl_config.bucket |
| 71 | + ) |
| 72 | + extract_is_empty = partial( |
| 73 | + _extract_is_empty, s3_client=s3_client, bucket=etl_config.bucket |
| 74 | + ) |
| 75 | + transform_is_empty = partial( |
| 76 | + _transform_is_empty, s3_client=s3_client, bucket=etl_config.bucket |
| 77 | + ) |
| 78 | + load_is_empty = partial( |
| 79 | + _load_is_empty, s3_client=s3_client, bucket=etl_config.bucket |
| 80 | + ) |
| 81 | + was_state_lock_removed = partial( |
| 82 | + _was_etl_state_lock_removed, s3_client=s3_client, bucket=etl_config.bucket |
| 83 | + ) |
| 84 | + database_isnt_empty = partial( |
| 85 | + _database_isnt_empty, db_client=db_client, table_name=etl_config.table_name |
| 86 | + ) |
| 87 | + |
| 88 | + # Trigger the bulk load |
| 89 | + s3_client.put_object( |
| 90 | + Bucket=etl_config.bucket, Key=etl_config.initial_trigger_key, Body=input_data |
| 91 | + ) |
| 92 | + |
| 93 | + # Sign-off through the expected lifecycle of the bulk ETL |
| 94 | + while not was_trigger_key_deleted(): |
| 95 | + time.sleep(5) |
| 96 | + message("Trigger key deleted") |
| 97 | + |
| 98 | + while not was_queue_history_created(): |
| 99 | + time.sleep(5) |
| 100 | + message("Queue history created") |
| 101 | + |
| 102 | + while not was_state_machine_history_created(): |
| 103 | + time.sleep(5) |
| 104 | + message("State machine history created") |
| 105 | + |
| 106 | + while not was_changelog_number_updated(): |
| 107 | + time.sleep(5) |
| 108 | + message("Changelog number updated") |
| 109 | + |
| 110 | + while not extract_is_empty(): |
| 111 | + time.sleep(5) |
| 112 | + message("Extract's input data is now in empty state") |
| 113 | + |
| 114 | + while not transform_is_empty(): |
| 115 | + time.sleep(5) |
| 116 | + message("Transform's input data is now in empty state") |
| 117 | + |
| 118 | + while not load_is_empty(): |
| 119 | + time.sleep(5) |
| 120 | + message("Load's input data is now in empty state") |
| 121 | + |
| 122 | + assert database_isnt_empty() |
| 123 | + message("Database isn't empty") |
| 124 | + |
| 125 | + while not was_state_lock_removed(): |
| 126 | + message("State lock has been removed") |
| 127 | + time.sleep(5) |
0 commit comments