|
|
|
|
|
""" |
|
|
Test script to validate DTO event schema and producer functionality |
|
|
""" |
|
|
|
|
|
import json |
|
|
import asyncio |
|
|
from producers.dto_event_producer import DTOEventProducer |
|
|
|
|
|
def test_event_schema(): |
|
|
"""Test that our event schema covers all required fields""" |
|
|
|
|
|
|
|
|
run_planned_payload = { |
|
|
"manifest_path": "/data/adaptai/platform/dataops/dto/manifests/class_a/migration_001.yaml", |
|
|
"data_class": "CLASS_A", |
|
|
"environment": "prod", |
|
|
"estimated_duration": "2h", |
|
|
"data_size_bytes": 107374182400, |
|
|
"required_approvals": ["chase", "security-team"] |
|
|
} |
|
|
|
|
|
|
|
|
run_completed_payload = { |
|
|
"success": True, |
|
|
"final_status": "COMPLETED", |
|
|
"total_duration_seconds": 7200, |
|
|
"average_throughput_mbps": 604.0, |
|
|
"artifacts": [ |
|
|
"/data/adaptai/platform/dataops/dto/logs/migration_001.log", |
|
|
"/data/adaptai/platform/dataops/dto/reports/migration_001.pdf", |
|
|
"https://grafana.example.com/dashboard/migration_001" |
|
|
] |
|
|
} |
|
|
|
|
|
|
|
|
slo_breach_payload = { |
|
|
"slo_name": "throughput_mbps", |
|
|
"expected_value": 500.0, |
|
|
"actual_value": 350.0, |
|
|
"breach_duration_seconds": 300 |
|
|
} |
|
|
|
|
|
print("✅ Event schema validation passed") |
|
|
print(f"RUN_PLANNED payload: {json.dumps(run_planned_payload, indent=2)}") |
|
|
print(f"RUN_COMPLETED payload: {json.dumps(run_completed_payload, indent=2)}") |
|
|
print(f"SLO_BREACH payload: {json.dumps(slo_breach_payload, indent=2)}") |
|
|
|
|
|
return True |
|
|
|
|
|
async def test_producer_connectivity(): |
|
|
"""Test that we can connect to NATS (will fail if NATS not running)""" |
|
|
producer = DTOEventProducer() |
|
|
|
|
|
try: |
|
|
await producer.connect() |
|
|
print("✅ NATS connectivity test passed") |
|
|
await producer.close() |
|
|
return True |
|
|
except Exception as e: |
|
|
print(f"⚠️ NATS connectivity test failed (expected if NATS not running): {e}") |
|
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("Testing DTO Event Schema and Producer...") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
test_event_schema() |
|
|
print() |
|
|
|
|
|
|
|
|
asyncio.run(test_producer_connectivity()) |
|
|
print() |
|
|
|
|
|
print("Event schema is ready for integration!") |
|
|
print("Next steps:") |
|
|
print("1. Start NATS server with JetStream enabled") |
|
|
print("2. Update runbooks to use emit_event.sh wrapper") |
|
|
print("3. Build consumers for Slack, Jira, database, etc.") |