GroveEngine/tests/modules/IndependentModule.cpp
StillHammer 9105610b29 feat: Add integration tests 8-10 & fix CTest configuration
Added three new integration test scenarios:
- Test 08: Config Hot-Reload (dynamic configuration updates)
- Test 09: Module Dependencies (dependency injection & cascade reload)
- Test 10: Multi-Version Coexistence (canary deployment & progressive migration)

Fixes:
- Fixed CTest working directory for all tests (add WORKING_DIRECTORY)
- Fixed module paths to use relative paths (./ prefix)
- Fixed IModule.h comments for clarity

New test modules:
- ConfigurableModule (for config reload testing)
- BaseModule, DependentModule, IndependentModule (for dependency testing)
- GameLogicModuleV1/V2/V3 (for multi-version testing)

Test coverage now includes 10 comprehensive integration scenarios covering
hot-reload, chaos testing, stress testing, race conditions, memory leaks,
error recovery, limits, config reload, dependencies, and multi-versioning.

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

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

104 lines
3.2 KiB
C++

#include "IndependentModule.h"
#include "grove/JsonDataNode.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace grove {
void IndependentModule::process(const IDataNode& input) {
processCount_++;
// Simple processing - just increment counter
}
void IndependentModule::setConfiguration(const IDataNode& configNode, IIO* io, ITaskScheduler* scheduler) {
logger_ = spdlog::get("grove");
if (!logger_) {
logger_ = spdlog::default_logger();
}
// Store configuration
const auto* jsonConfigNode = dynamic_cast<const JsonDataNode*>(&configNode);
if (jsonConfigNode) {
configNode_ = std::make_unique<JsonDataNode>("config", jsonConfigNode->getJsonData());
// Parse configuration to determine version
const auto& jsonData = jsonConfigNode->getJsonData();
if (jsonData.contains("version")) {
version_ = jsonData["version"];
}
} else {
configNode_ = std::make_unique<JsonDataNode>("config", nlohmann::json::object());
}
logger_->info("IndependentModule v{} initialized (isolated witness)", version_);
}
const IDataNode& IndependentModule::getConfiguration() {
if (!configNode_) {
configNode_ = std::make_unique<JsonDataNode>("config", nlohmann::json::object());
}
return *configNode_;
}
std::unique_ptr<IDataNode> IndependentModule::getHealthStatus() {
json status;
status["status"] = "healthy";
status["processCount"] = processCount_.load();
status["reloadCount"] = reloadCount_.load();
status["version"] = version_;
return std::make_unique<JsonDataNode>("health", status);
}
void IndependentModule::shutdown() {
if (logger_) {
logger_->info("IndependentModule v{} shutting down", version_);
}
}
std::unique_ptr<IDataNode> IndependentModule::getState() {
json state;
state["processCount"] = processCount_.load();
state["reloadCount"] = reloadCount_.load();
state["version"] = version_;
return std::make_unique<JsonDataNode>("state", state);
}
void IndependentModule::setState(const IDataNode& state) {
reloadCount_++; // Track reload attempts
const auto* jsonStateNode = dynamic_cast<const JsonDataNode*>(&state);
if (jsonStateNode) {
const auto& jsonData = jsonStateNode->getJsonData();
if (jsonData.contains("processCount")) {
processCount_ = jsonData["processCount"];
}
if (jsonData.contains("reloadCount")) {
reloadCount_ = jsonData["reloadCount"];
}
if (jsonData.contains("version")) {
version_ = jsonData["version"];
}
if (logger_) {
logger_->info("IndependentModule state restored: v{}, reloadCount={}", version_, reloadCount_.load());
}
} else {
if (logger_) {
logger_->error("IndependentModule: Failed to restore state: not a JsonDataNode");
}
}
}
} // namespace grove
// Export symbols
extern "C" {
grove::IModule* createModule() {
return new grove::IndependentModule();
}
void destroyModule(grove::IModule* module) {
delete module;
}
}