32#define TEST(name) void test_##name()
33#define RUN_TEST(name) \
35 std::cout << "Running test: " << #name << " ... "; \
38 std::cout << "PASSED\n"; \
40 } catch (const std::exception &e) { \
41 std::cout << "FAILED: " << e.what() << "\n"; \
46#define ASSERT_TRUE(condition) \
48 throw std::runtime_error("Assertion failed: " #condition); \
51#define ASSERT_FALSE(condition) ASSERT_TRUE(!(condition))
54TEST(basic_initialization_and_shutdown) {
73 auto shutdown_result = coordinator.
shutdown();
118 logger->log(db_log_level::debug,
"Debug message from coordinator test");
119 logger->log(db_log_level::info,
"Info message from coordinator test");
120 logger->log(db_log_level::warning,
"Warning message from coordinator test");
126TEST(monitoring_functionality) {
139 monitor->record_connection_acquired();
140 monitor->record_query_execution(std::chrono::microseconds(100),
true);
141 monitor->update_pool_stats(1, 5, 10);
144 auto metrics_result = monitor->get_database_metrics();
146 ASSERT_TRUE(metrics_result.value().active_connections == 1);
152TEST(thread_pool_functionality) {
164 std::atomic<bool> task_executed{
false};
165 auto future = thread_pool->submit([&task_executed]() {
166 task_executed =
true;
170 auto value = future.get();
209 auto stats_before = coordinator.
get_stats();
212 ASSERT_TRUE(stats_before.value().uptime.count() == 0);
217 std::this_thread::sleep_for(std::chrono::milliseconds(10));
220 auto stats_after = coordinator.
get_stats();
224 ASSERT_TRUE(stats_after.value().monitoring_healthy);
225 ASSERT_TRUE(stats_after.value().thread_pool_healthy);
226 ASSERT_TRUE(stats_after.value().uptime.count() > 0);
250TEST(shutdown_without_initialization) {
255 auto result = coordinator.
shutdown();
260TEST(automatic_shutdown_in_destructor) {
296 logger->log(db_log_level::info,
"Starting database operations");
299 auto query_future = thread_pool->submit([&]() {
301 std::this_thread::yield();
304 monitor->record_query_execution(std::chrono::microseconds(100),
true);
306 logger->log(db_log_level::debug,
"Query executed successfully");
319 auto metrics = monitor->get_database_metrics();
322 ASSERT_TRUE(metrics.value().successful_queries == 1);
324 logger->log(db_log_level::info,
"All operations completed");
331 std::cout <<
"=== Database Coordinator Tests (Phase 5) ===\n\n";
333 RUN_TEST(basic_initialization_and_shutdown);
337 RUN_TEST(thread_pool_functionality);
341 RUN_TEST(shutdown_without_initialization);
342 RUN_TEST(automatic_shutdown_in_destructor);
345 std::cout <<
"\n=== Test Summary ===\n";
350 std::cout <<
"=== All tests passed! ✓ ===\n";
353 std::cout <<
"=== Some tests failed! ✗ ===\n";
Manages lifecycle and coordination of all database system adapters.
common::Result< bool > check_health()
Perform aggregate health check of all adapters.
adapters::logger_adapter * get_logger()
Get logger adapter.
adapters::thread_adapter * get_thread_pool()
Get thread adapter.
common::Result< coordinator_stats > get_stats() const
common::VoidResult shutdown()
Shutdown all adapters in reverse order.
bool is_initialized() const
Check if coordinator is initialized.
common::VoidResult initialize()
Initialize all adapters in correct order.
adapters::monitoring_adapter * get_monitor()
Get monitoring adapter.
Lifecycle manager for all database system adapters (Phase 5)
Database logging adapter with runtime backend selection.
Database monitoring adapter with runtime backend selection.
bool enable_file_logging
Enable logging to file (in addition to console)
db_log_level min_log_level
Minimum log level to output.
bool enable_profiling
Enable performance profiling.
bool enable_metrics
Enable metrics collection.
bool enable_health_checks
Enable health check endpoints.
std::size_t thread_count
Number of worker threads (0 = auto-detect from hardware)
db_logger_config logger
Logger configuration.
db_monitoring_config monitoring
Monitoring configuration.
db_thread_config thread
Thread pool configuration.
#define ASSERT_FALSE(condition)
#define ASSERT_TRUE(condition)
Thread pool adapter with runtime backend selection.