Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
test_cross_system_integration.cpp File Reference

Phase 3.3 - Cross-System Integration Tests. More...

#include <gtest/gtest.h>
#include <kcenon/monitoring/core/performance_monitor.h>
#include <kcenon/common/interfaces/logger_interface.h>
#include <kcenon/common/interfaces/monitoring_interface.h>
#include <memory>
#include <mutex>
#include <thread>
#include <chrono>
Include dependency graph for test_cross_system_integration.cpp:

Go to the source code of this file.

Classes

class  simple_mock_logger
 Simple mock logger for testing. More...
 
class  mock_monitor
 Mock IMonitor for testing cross-system integration. More...
 

Functions

 TEST (CrossSystemIntegrationTest, BothSystemsStandalone)
 Test Case 1: Both systems standalone.
 
 TEST (CrossSystemIntegrationTest, LoggerWithMonitorInjection)
 Test Case 2: Logger with monitor injection.
 
 TEST (CrossSystemIntegrationTest, MonitorInterfaceCompatibility)
 Test Case 3: Monitor with logger (interface compatibility)
 
 TEST (CrossSystemIntegrationTest, BidirectionalDependencyInjection)
 Test Case 4: Bidirectional DI (NO CIRCULAR DEPENDENCY!)
 
 TEST (CrossSystemIntegrationTest, RepeatedInjection)
 Test Case 5: Repeated injection.
 
 TEST (CrossSystemIntegrationTest, NullInjection)
 Test Case 6: NULL injection.
 
 TEST (CrossSystemIntegrationTest, IntegrationPerformanceOverhead)
 Performance test: Integration overhead.
 
 TEST (CrossSystemIntegrationTest, MonitoringSystemStandalone)
 Test monitoring_system's performance_monitor standalone.
 
int main (int argc, char **argv)
 

Detailed Description

Phase 3.3 - Cross-System Integration Tests.

Tests verify the integration matrix:

  1. Both systems standalone
  2. Logger with monitor injection
  3. Monitor with logger injection
  4. Bidirectional DI (no compile-time circular dependency!)
  5. Repeated injection
  6. NULL injection

Definition in file test_cross_system_integration.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 337 of file test_cross_system_integration.cpp.

337 {
338 ::testing::InitGoogleTest(&argc, argv);
339 return RUN_ALL_TESTS();
340}

◆ TEST() [1/8]

TEST ( CrossSystemIntegrationTest ,
BidirectionalDependencyInjection  )

Test Case 4: Bidirectional DI (NO CIRCULAR DEPENDENCY!)

This is the critical test - we can create bidirectional runtime dependencies WITHOUT compile-time circular dependency!

Definition at line 217 of file test_cross_system_integration.cpp.

217 {
218 // Create both systems
219 auto logger = std::make_shared<simple_mock_logger>();
220 auto monitor = std::make_shared<mock_monitor>();
221
222 // Bidirectional injection
223 logger->set_monitor(monitor);
224
225 // Use both systems
226 for (int i = 0; i < 10; ++i) {
227 logger->log(common_if::log_level::info, "Request " + std::to_string(i));
228 }
229
230 // Verify logger health
231 auto logger_health = logger->health_check();
232 ASSERT_TRUE(logger_health.is_ok());
233 EXPECT_TRUE(logger_health.value().is_healthy());
234
235 // Verify monitor health
236 auto monitor_health = monitor->check_health();
237 ASSERT_TRUE(monitor_health.is_ok());
238 EXPECT_TRUE(monitor_health.value().is_healthy());
239
240 // Verify metrics were recorded
241 auto monitor_metrics = monitor->get_metrics();
242 ASSERT_TRUE(monitor_metrics.is_ok());
243 EXPECT_EQ(10, monitor_metrics.value().metrics.size());
244
245 // Logger should have logged
246 EXPECT_EQ(10, logger->get_log_count());
247}

◆ TEST() [2/8]

TEST ( CrossSystemIntegrationTest ,
BothSystemsStandalone  )

Test Case 1: Both systems standalone.

Definition at line 148 of file test_cross_system_integration.cpp.

148 {
149 // Create logger without monitor
150 auto logger = std::make_shared<simple_mock_logger>();
151
152 EXPECT_NO_THROW({
153 logger->log(common_if::log_level::info, "Test message");
154 });
155 EXPECT_EQ(1, logger->get_log_count());
156
157 // Create monitor without logger
158 auto monitor = std::make_shared<mock_monitor>();
159
160 EXPECT_NO_THROW({
161 auto result = monitor->record_metric("test_metric", 1.0);
162 EXPECT_TRUE(result.is_ok());
163 });
164
165 // Both should work independently
166 auto monitor_metrics = monitor->get_metrics();
167 ASSERT_TRUE(monitor_metrics.is_ok());
168 EXPECT_EQ(1, monitor_metrics.value().metrics.size());
169}

◆ TEST() [3/8]

TEST ( CrossSystemIntegrationTest ,
IntegrationPerformanceOverhead  )

Performance test: Integration overhead.

Definition at line 298 of file test_cross_system_integration.cpp.

298 {
299 auto logger = std::make_shared<simple_mock_logger>();
300 auto monitor = std::make_shared<mock_monitor>();
301
302 logger->set_monitor(monitor);
303
304 // Measure time for integrated operations
305 auto start = std::chrono::high_resolution_clock::now();
306
307 for (int i = 0; i < 1000; ++i) {
308 logger->log(common_if::log_level::info, "Performance test");
309 }
310
311 auto end = std::chrono::high_resolution_clock::now();
312 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
313
314 // Integration should be fast (< 100ms for 1000 operations)
315 EXPECT_LT(duration.count(), 100);
316 EXPECT_EQ(1000, monitor->get_metric_count());
317}

◆ TEST() [4/8]

TEST ( CrossSystemIntegrationTest ,
LoggerWithMonitorInjection  )

Test Case 2: Logger with monitor injection.

Definition at line 174 of file test_cross_system_integration.cpp.

174 {
175 auto monitor = std::make_shared<mock_monitor>();
176 auto logger = std::make_shared<simple_mock_logger>();
177
178 // Inject monitor into logger
179 logger->set_monitor(monitor);
180
181 // Log messages - each log should record a metric
182 logger->log(common_if::log_level::info, "Test 1");
183 logger->log(common_if::log_level::info, "Test 2");
184
185 // Monitor should have received metrics from logger
186 auto metrics_result = monitor->get_metrics();
187 ASSERT_TRUE(metrics_result.is_ok());
188
189 auto& snapshot = metrics_result.value();
190 EXPECT_EQ(2, snapshot.metrics.size());
191}

◆ TEST() [5/8]

TEST ( CrossSystemIntegrationTest ,
MonitoringSystemStandalone  )

Test monitoring_system's performance_monitor standalone.

Definition at line 322 of file test_cross_system_integration.cpp.

322 {
323 auto monitor = std::make_shared<mon::performance_monitor>();
324
325 // Test monitoring_system's native interface
326 EXPECT_NO_THROW({
327 auto timer = monitor->time_operation("test_op");
328 // Simulate work
329 std::this_thread::sleep_for(std::chrono::milliseconds(1));
330 });
331
332 // Collect metrics using native interface
333 auto result = monitor->collect();
334 ASSERT_TRUE(result.is_ok());
335}
@ timer
StatsD-specific timer metric.

◆ TEST() [6/8]

TEST ( CrossSystemIntegrationTest ,
MonitorInterfaceCompatibility  )

Test Case 3: Monitor with logger (interface compatibility)

Definition at line 196 of file test_cross_system_integration.cpp.

196 {
197 auto monitor = std::make_shared<mock_monitor>();
198
199 // Test IMonitor interface methods
200 EXPECT_NO_THROW({
201 auto result = monitor->record_metric("test_metric", 42.0);
202 EXPECT_TRUE(result.is_ok());
203 });
204
205 // Monitor health check should work
206 auto health = monitor->check_health();
207 ASSERT_TRUE(health.is_ok());
208 EXPECT_EQ(common_if::health_status::healthy, health.value().status);
209}

◆ TEST() [7/8]

TEST ( CrossSystemIntegrationTest ,
NullInjection  )

Test Case 6: NULL injection.

Definition at line 277 of file test_cross_system_integration.cpp.

277 {
278 auto logger = std::make_shared<simple_mock_logger>();
279 auto monitor = std::make_shared<mock_monitor>();
280
281 // Inject then remove
282 logger->set_monitor(monitor);
283 logger->set_monitor(nullptr);
284
285 // Should not crash
286 EXPECT_NO_THROW({
287 logger->log(common_if::log_level::info, "After null injection");
288 });
289
290 EXPECT_EQ(1, logger->get_log_count());
291 // Monitor should not have received the last log (null injection)
292 EXPECT_EQ(0, monitor->get_metric_count());
293}

◆ TEST() [8/8]

TEST ( CrossSystemIntegrationTest ,
RepeatedInjection  )

Test Case 5: Repeated injection.

Definition at line 252 of file test_cross_system_integration.cpp.

252 {
253 auto logger = std::make_shared<simple_mock_logger>();
254 auto monitor1 = std::make_shared<mock_monitor>();
255 auto monitor2 = std::make_shared<mock_monitor>();
256
257 // First injection
258 logger->set_monitor(monitor1);
259 logger->log(common_if::log_level::info, "With monitor1");
260
261 // monitor1 should have received the metric
262 EXPECT_EQ(1, monitor1->get_metric_count());
263
264 // Replace with second monitor
265 logger->set_monitor(monitor2);
266 logger->log(common_if::log_level::info, "With monitor2");
267
268 // monitor2 should now receive metrics, monitor1 stays at 1
269 EXPECT_EQ(1, monitor1->get_metric_count());
270 EXPECT_EQ(1, monitor2->get_metric_count());
271 EXPECT_EQ(2, logger->get_log_count());
272}