GroveEngine/tests/modules/ConfigWatcherModule.cpp
StillHammer ddbed30ed7 feat: Add Scenario 11 IO System test & fix IntraIO routing architecture
Implémentation complète du scénario 11 (IO System Stress Test) avec correction majeure de l'architecture de routing IntraIO.

## Nouveaux Modules de Test (Scenario 11)
- ProducerModule: Publie messages pour tests IO
- ConsumerModule: Consomme et valide messages reçus
- BroadcastModule: Test multi-subscriber broadcasting
- BatchModule: Test low-frequency batching
- IOStressModule: Tests de charge concurrents

## Test d'Intégration
- test_11_io_system.cpp: 6 tests validant:
  * Basic Publish-Subscribe
  * Pattern Matching avec wildcards
  * Multi-Module Routing (1-to-many)
  * Low-Frequency Subscriptions (batching)
  * Backpressure & Queue Overflow
  * Thread Safety (concurrent pub/pull)

## Fix Architecture Critique: IntraIO Routing
**Problème**: IntraIO::publish() et subscribe() n'utilisaient PAS IntraIOManager pour router entre modules.

**Solution**: Utilisation de JSON comme format de transport intermédiaire
- IntraIO::publish() → extrait JSON → IntraIOManager::routeMessage()
- IntraIO::subscribe() → enregistre au IntraIOManager::registerSubscription()
- IntraIOManager::routeMessage() → copie JSON pour chaque subscriber → deliverMessage()

**Bénéfices**:
-  Routing centralisé fonctionnel
-  Support 1-to-many (copie JSON au lieu de move unique_ptr)
-  Pas besoin d'implémenter IDataNode::clone()
-  Compatible futur NetworkIO (JSON sérialisable)

## Modules Scenario 13 (Cross-System)
- ConfigWatcherModule, PlayerModule, EconomyModule, MetricsModule
- test_13_cross_system.cpp (stub)

## Documentation
- CLAUDE_NEXT_SESSION.md: Instructions détaillées pour build/test

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 11:43:08 +08:00

92 lines
2.6 KiB
C++

#include "ConfigWatcherModule.h"
#include <iostream>
namespace grove {
ConfigWatcherModule::ConfigWatcherModule() {
std::cout << "[ConfigWatcherModule] Constructor" << std::endl;
}
ConfigWatcherModule::~ConfigWatcherModule() {
std::cout << "[ConfigWatcherModule] Destructor" << std::endl;
}
void ConfigWatcherModule::process(const IDataNode& input) {
// Check for config changes if tree is available
if (tree && tree->checkForChanges()) {
configChangesDetected++;
onConfigReloaded();
}
}
void ConfigWatcherModule::setConfiguration(const IDataNode& configNode, IIO* ioPtr, ITaskScheduler* schedulerPtr) {
std::cout << "[ConfigWatcherModule] setConfiguration called" << std::endl;
this->io = ioPtr;
this->scheduler = schedulerPtr;
// Store config
config = std::make_unique<JsonDataNode>("config", nlohmann::json::object());
}
const IDataNode& ConfigWatcherModule::getConfiguration() {
if (!config) {
config = std::make_unique<JsonDataNode>("config", nlohmann::json::object());
}
return *config;
}
std::unique_ptr<IDataNode> ConfigWatcherModule::getHealthStatus() {
nlohmann::json health = {
{"status", "healthy"},
{"configChangesDetected", configChangesDetected}
};
return std::make_unique<JsonDataNode>("health", health);
}
void ConfigWatcherModule::shutdown() {
std::cout << "[ConfigWatcherModule] Shutdown - Detected " << configChangesDetected << " config changes" << std::endl;
}
std::unique_ptr<IDataNode> ConfigWatcherModule::getState() {
nlohmann::json state = {
{"configChangesDetected", configChangesDetected}
};
return std::make_unique<JsonDataNode>("state", state);
}
void ConfigWatcherModule::setState(const IDataNode& state) {
configChangesDetected = state.getInt("configChangesDetected", 0);
std::cout << "[ConfigWatcherModule] State restored" << std::endl;
}
void ConfigWatcherModule::setDataTree(IDataTree* treePtr) {
this->tree = treePtr;
}
void ConfigWatcherModule::onConfigReloaded() {
std::cout << "[ConfigWatcherModule] Config reloaded, publishing event" << std::endl;
publishConfigChange("gameplay");
}
void ConfigWatcherModule::publishConfigChange(const std::string& configName) {
if (!io) return;
nlohmann::json data = {
{"config", configName},
{"timestamp", configChangesDetected}
};
auto dataNode = std::make_unique<JsonDataNode>("configChange", data);
io->publish("config:" + configName + ":changed", std::move(dataNode));
}
} // namespace grove
// Export C API
extern "C" {
grove::IModule* createModule() {
return new grove::ConfigWatcherModule();
}
}