| |
| """ |
| Test script to verify all DataOps database connections for Elizabeth |
| """ |
|
|
| import os |
| import sys |
| import redis |
| import chromadb |
| import psycopg2 |
| import pymongo |
| import qdrant_client |
| from datetime import datetime |
|
|
| def test_redis(): |
| """Test Redis connection""" |
| try: |
| client = redis.Redis(host='localhost', port=6379, decode_responses=True) |
| client.ping() |
| print("β
Redis: Connected successfully") |
| return True |
| except Exception as e: |
| print(f"β Redis: Connection failed - {e}") |
| return False |
|
|
| def test_postgresql(): |
| """Test PostgreSQL connection""" |
| try: |
| conn = psycopg2.connect( |
| host="localhost", |
| database="novadb", |
| user="postgres", |
| password="nova_db_pass" |
| ) |
| cursor = conn.cursor() |
| cursor.execute("SELECT version();") |
| version = cursor.fetchone() |
| print(f"β
PostgreSQL: Connected successfully - {version[0]}") |
| conn.close() |
| return True |
| except Exception as e: |
| print(f"β PostgreSQL: Connection failed - {e}") |
| return False |
|
|
| def test_mongodb(): |
| """Test MongoDB connection""" |
| try: |
| client = pymongo.MongoClient("mongodb://localhost:27017/") |
| db = client["nova_documents"] |
| |
| collections = db.list_collection_names() |
| print(f"β
MongoDB: Connected successfully - Collections: {len(collections)}") |
| return True |
| except Exception as e: |
| print(f"β MongoDB: Connection failed - {e}") |
| return False |
|
|
| def test_chromadb(): |
| """Test ChromaDB connection""" |
| try: |
| client = chromadb.PersistentClient(path="/data/chromadb") |
| collections = client.list_collections() |
| print(f"β
ChromaDB: Connected successfully - Collections: {len(collections)}") |
| return True |
| except Exception as e: |
| print(f"β ChromaDB: Connection failed - {e}") |
| return False |
|
|
| def test_qdrant(): |
| """Test Qdrant connection""" |
| try: |
| client = qdrant_client.QdrantClient( |
| host="localhost", |
| port=17000, |
| prefer_grpc=False |
| ) |
| collections = client.get_collections() |
| print(f"β
Qdrant: Connected successfully - Collections: {len(collections.collections)}") |
| return True |
| except Exception as e: |
| print(f"β Qdrant: Connection failed - {e}") |
| return False |
|
|
| def test_dragonfly(): |
| """Test DragonFly connection""" |
| try: |
| client = redis.Redis(host='localhost', port=18000, decode_responses=True) |
| client.ping() |
| print("β
DragonFly: Connected successfully") |
| return True |
| except Exception as e: |
| print(f"β DragonFly: Connection failed - {e}") |
| return False |
|
|
| def main(): |
| """Main test function""" |
| print("π Testing Elizabeth DataOps Database Connections") |
| print("=" * 60) |
| |
| results = {} |
| |
| |
| results["redis"] = test_redis() |
| results["postgresql"] = test_postgresql() |
| results["mongodb"] = test_mongodb() |
| results["chromadb"] = test_chromadb() |
| results["qdrant"] = test_qdrant() |
| results["dragonfly"] = test_dragonfly() |
| |
| print("=" * 60) |
| |
| |
| successful = sum(results.values()) |
| total = len(results) |
| |
| print(f"π Connection Summary: {successful}/{total} successful") |
| |
| if successful == total: |
| print("π All DataOps databases connected successfully!") |
| print("Elizabeth can now utilize the complete infrastructure.") |
| else: |
| print("β οΈ Some connections failed. Elizabeth will use available databases.") |
| |
| return all(results.values()) |
|
|
| if __name__ == "__main__": |
| success = main() |
| sys.exit(0 if success else 1) |