File size: 2,614 Bytes
fd357f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
"""
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"""
    
    # Test RUN_PLANNED event
    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,  # 100GB
        "required_approvals": ["chase", "security-team"]
    }
    
    # Test RUN_COMPLETED event  
    run_completed_payload = {
        "success": True,
        "final_status": "COMPLETED",
        "total_duration_seconds": 7200,  # 2 hours
        "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"
        ]
    }
    
    # Test SLO_BREACH event
    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 schema validation
    test_event_schema()
    print()
    
    # Test NATS connectivity
    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.")