Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
test_monitoring_adapter.cpp File Reference

Unit tests for monitoring_adapter (Phase 3) More...

#include "../../database/integrated/adapters/monitoring_adapter.h"
#include <chrono>
#include <iostream>
#include <cassert>
Include dependency graph for test_monitoring_adapter.cpp:

Go to the source code of this file.

Macros

#define TEST(name)
 
#define RUN_TEST(name)
 
#define ASSERT_TRUE(condition)
 
#define ASSERT_FALSE(condition)
 

Functions

void test_configuration_construction ()
 
void test_adapter_construction ()
 
void test_api_availability_basic ()
 
void test_api_availability_metrics ()
 
void test_api_availability_health ()
 
void test_api_availability_prometheus ()
 
void test_api_availability_reset ()
 
void test_multiple_instances ()
 
void test_move_semantics ()
 
void test_destructor_safety ()
 
int main ()
 

Variables

int tests_passed = 0
 
int tests_failed = 0
 

Detailed Description

Unit tests for monitoring_adapter (Phase 3)

These are lightweight API tests that verify the adapter interface without requiring the actual monitoring_system to be available.

For full integration testing with monitoring_system, run the integration test suite instead.

Definition in file test_monitoring_adapter.cpp.

Macro Definition Documentation

◆ ASSERT_FALSE

#define ASSERT_FALSE ( condition)
Value:
ASSERT_TRUE(!(condition))
#define ASSERT_TRUE(condition)

Definition at line 47 of file test_monitoring_adapter.cpp.

◆ ASSERT_TRUE

#define ASSERT_TRUE ( condition)
Value:
if (!(condition)) { \
throw std::runtime_error("Assertion failed: " #condition); \
}

Definition at line 42 of file test_monitoring_adapter.cpp.

42#define ASSERT_TRUE(condition) \
43 if (!(condition)) { \
44 throw std::runtime_error("Assertion failed: " #condition); \
45 }

Referenced by test_configuration_construction().

◆ RUN_TEST

#define RUN_TEST ( name)
Value:
do { \
std::cout << "Running test: " << #name << " ... "; \
try { \
test_##name(); \
std::cout << "PASSED\n"; \
} catch (const std::exception& e) { \
std::cout << "FAILED: " << e.what() << "\n"; \
} \
} while(0)

Definition at line 29 of file test_monitoring_adapter.cpp.

29#define RUN_TEST(name) \
30 do { \
31 std::cout << "Running test: " << #name << " ... "; \
32 try { \
33 test_##name(); \
34 std::cout << "PASSED\n"; \
35 tests_passed++; \
36 } catch (const std::exception& e) { \
37 std::cout << "FAILED: " << e.what() << "\n"; \
38 tests_failed++; \
39 } \
40 } while(0)

Referenced by main().

◆ TEST

#define TEST ( name)
Value:
void test_##name()

Definition at line 28 of file test_monitoring_adapter.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 199 of file test_monitoring_adapter.cpp.

199 {
200 std::cout << "=== Monitoring Adapter API Tests (Phase 3) ===\n";
201 std::cout << "Note: These tests verify API availability only.\n";
202 std::cout << "For full integration testing, run integration test suite.\n\n";
203
204 RUN_TEST(configuration_construction);
205 RUN_TEST(adapter_construction);
206 RUN_TEST(api_availability_basic);
207 RUN_TEST(api_availability_metrics);
208 RUN_TEST(api_availability_health);
209 RUN_TEST(api_availability_prometheus);
210 RUN_TEST(api_availability_reset);
211 RUN_TEST(multiple_instances);
212 RUN_TEST(move_semantics);
213 RUN_TEST(destructor_safety);
214
215 std::cout << "\n=== Test Summary ===\n";
216 std::cout << "Passed: " << tests_passed << "\n";
217 std::cout << "Failed: " << tests_failed << "\n";
218
219 if (tests_failed == 0) {
220 std::cout << "=== All tests passed! ✓ ===\n";
221 return 0;
222 } else {
223 std::cout << "=== Some tests failed! ✗ ===\n";
224 return 1;
225 }
226}
#define RUN_TEST(name)

References RUN_TEST, tests_failed, and tests_passed.

◆ test_adapter_construction()

void test_adapter_construction ( )

Definition at line 68 of file test_monitoring_adapter.cpp.

68 {
70 config.enable_metrics = true;
71
72 // Should be able to construct adapter
73 monitoring_adapter monitor(config);
74
75 // Construction should succeed
76 // Note: Actual initialization may require monitoring_system
77}
Monitoring adapter for database operations.
Monitoring and metrics configuration.
bool enable_metrics
Enable metrics collection.

References database::integrated::db_monitoring_config::enable_metrics.

◆ test_api_availability_basic()

void test_api_availability_basic ( )

Definition at line 80 of file test_monitoring_adapter.cpp.

80 {
82 config.enable_metrics = false; // Disable to avoid external dependencies
83
84 monitoring_adapter monitor(config);
85
86 // These methods should be available (may no-op if monitoring disabled)
87 monitor.record_connection_acquired();
88 monitor.record_connection_released();
89 monitor.record_query_execution(std::chrono::microseconds(100), true);
90 monitor.record_transaction_begin();
91 monitor.record_transaction_commit();
92 monitor.record_transaction_rollback();
93 monitor.update_pool_stats(1, 5, 10);
94
95 // If we get here without crash, API is available
96}

References database::integrated::db_monitoring_config::enable_metrics, database::integrated::adapters::monitoring_adapter::record_connection_acquired(), database::integrated::adapters::monitoring_adapter::record_connection_released(), database::integrated::adapters::monitoring_adapter::record_query_execution(), database::integrated::adapters::monitoring_adapter::record_transaction_begin(), database::integrated::adapters::monitoring_adapter::record_transaction_commit(), database::integrated::adapters::monitoring_adapter::record_transaction_rollback(), and database::integrated::adapters::monitoring_adapter::update_pool_stats().

Here is the call graph for this function:

◆ test_api_availability_health()

void test_api_availability_health ( )

Definition at line 114 of file test_monitoring_adapter.cpp.

114 {
116 config.enable_health_checks = false;
117
118 monitoring_adapter monitor(config);
119
120 // Should be able to call health check (may return unhealthy if not init)
121 auto health_result = monitor.check_health();
122 // Result structure should be valid even if health check failed
123}
bool enable_health_checks
Enable health check endpoints.

References database::integrated::adapters::monitoring_adapter::check_health(), and database::integrated::db_monitoring_config::enable_health_checks.

Here is the call graph for this function:

◆ test_api_availability_metrics()

void test_api_availability_metrics ( )

Definition at line 99 of file test_monitoring_adapter.cpp.

99 {
101 config.enable_metrics = false;
102
103 monitoring_adapter monitor(config);
104
105 // Should be able to call these methods (may return default/empty values)
106 auto metrics_result = monitor.get_database_metrics();
107 // Result may be ok or error depending on initialization state
108
109 auto metrics_snapshot_result = monitor.get_metrics();
110 // Result may be ok or error depending on initialization state
111}

References database::integrated::db_monitoring_config::enable_metrics, database::integrated::adapters::monitoring_adapter::get_database_metrics(), and database::integrated::adapters::monitoring_adapter::get_metrics().

Here is the call graph for this function:

◆ test_api_availability_prometheus()

void test_api_availability_prometheus ( )

Definition at line 126 of file test_monitoring_adapter.cpp.

126 {
128 config.enable_prometheus_export = false;
129
130 monitoring_adapter monitor(config);
131
132 // Should be able to call prometheus export (may return empty string)
133 auto prometheus_text = monitor.export_prometheus_metrics();
134 // Should return a string (may be empty)
135}
bool enable_prometheus_export
Enable Prometheus metrics export.

References database::integrated::db_monitoring_config::enable_prometheus_export, and database::integrated::adapters::monitoring_adapter::export_prometheus_metrics().

Here is the call graph for this function:

◆ test_api_availability_reset()

void test_api_availability_reset ( )

Definition at line 138 of file test_monitoring_adapter.cpp.

138 {
140 config.enable_metrics = false;
141
142 monitoring_adapter monitor(config);
143
144 // Should be able to call reset without crash
145 monitor.reset();
146}

References database::integrated::db_monitoring_config::enable_metrics, and database::integrated::adapters::monitoring_adapter::reset().

Here is the call graph for this function:

◆ test_configuration_construction()

void test_configuration_construction ( )

◆ test_destructor_safety()

void test_destructor_safety ( )

Definition at line 180 of file test_monitoring_adapter.cpp.

180 {
181 // Test that adapter can be constructed and destroyed safely
182 {
184 config.enable_metrics = false;
185
186 monitoring_adapter monitor(config);
187 monitor.record_connection_acquired();
188
189 // Destructor will be called here
190 }
191
192 // Should not crash
193}

References database::integrated::db_monitoring_config::enable_metrics, and database::integrated::adapters::monitoring_adapter::record_connection_acquired().

Here is the call graph for this function:

◆ test_move_semantics()

void test_move_semantics ( )

Definition at line 166 of file test_monitoring_adapter.cpp.

166 {
168 config.enable_metrics = false;
169
170 monitoring_adapter monitor1(config);
171
172 // Should support move construction
173 monitoring_adapter monitor2(std::move(monitor1));
174
175 // Moved-to instance should be usable
176 monitor2.record_connection_acquired();
177}

References database::integrated::db_monitoring_config::enable_metrics, and database::integrated::adapters::monitoring_adapter::record_connection_acquired().

Here is the call graph for this function:

◆ test_multiple_instances()

void test_multiple_instances ( )

Definition at line 149 of file test_monitoring_adapter.cpp.

149 {
150 db_monitoring_config config1;
151 config1.enable_metrics = false;
152
153 db_monitoring_config config2;
154 config2.enable_metrics = false;
155
156 // Should be able to create multiple adapters
157 monitoring_adapter monitor1(config1);
158 monitoring_adapter monitor2(config2);
159
160 // Both should be usable
161 monitor1.record_connection_acquired();
162 monitor2.record_connection_acquired();
163}

References database::integrated::db_monitoring_config::enable_metrics, and database::integrated::adapters::monitoring_adapter::record_connection_acquired().

Here is the call graph for this function:

Variable Documentation

◆ tests_failed

int tests_failed = 0

Definition at line 26 of file test_monitoring_adapter.cpp.

Referenced by main().

◆ tests_passed

int tests_passed = 0

Definition at line 25 of file test_monitoring_adapter.cpp.

Referenced by main().