askrobots / dbbasic-object-primitive
Public
Python functions as REST objects, with clustering, load balancing and state replication; no containers or orchestration.
test_log_replication_live.py · 1.3 KB · 41 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Test log replication in live cluster |
| 4 | """ |
| 5 | from dbbasic_object_core.core.self_logger import SelfLogger |
| 6 | from cluster_config import get_config |
| 7 | import time |
| 8 | |
| 9 | # Create logger with replication enabled |
| 10 | logger = SelfLogger('test_replication', base_dir='data', enable_replication=True) |
| 11 | |
| 12 | print("Creating log entries with replication enabled...") |
| 13 | logger.info("First log entry from station1", test_number=1) |
| 14 | time.sleep(1) |
| 15 | |
| 16 | logger.info("Second log entry from station1", test_number=2) |
| 17 | time.sleep(1) |
| 18 | |
| 19 | logger.warning("Third entry - warning level", test_number=3) |
| 20 | time.sleep(1) |
| 21 | |
| 22 | logger.error("Fourth entry - error level", test_number=4, extra_data="testing") |
| 23 | time.sleep(1) |
| 24 | |
| 25 | logger.info("Fifth and final entry", test_number=5) |
| 26 | |
| 27 | print("✓ Created 5 log entries with replication") |
| 28 | print("Waiting 3 seconds for replication to complete...") |
| 29 | time.sleep(3) |
| 30 | |
| 31 | # Show local logs |
| 32 | logs = logger.get_logs() |
| 33 | print(f"\n✓ Local logs on station1: {len(logs)} entries") |
| 34 | for log in logs: |
| 35 | print(f" - {log['timestamp'][:19]} [{log['level']}] {log['message']} (entry_id: {log['entry_id'][:8]}...)") |
| 36 | |
| 37 | print("\nNow check logs on worker stations:") |
| 38 | config = get_config() |
| 39 | for worker in config.get_workers(): |
| 40 | url = config.get_url(worker['station_id'], '/objects/test_replication?logs=true') |
| 41 | print(f" curl -s {url}") |