Add async/resilience/reflection primitives + FSM v2 rewrite
A round of new universal capabilities (all generic — templated/reflection based, no app coupling), verified by the test suite (1103 passing): Data reflection: - Reflect.hpp now (de)serializes chrono::duration, chrono::time_point, std::variant (tagged), std::array, and non-string-keyed std::map; Meta.hpp gains is_time_point_v et al. Async: - EventBus gains Mode::Async (worker-thread dispatch + flush()). - ThreadPool gains a bounded queue, try_submit(), and rejection stats. New modules / containers: - Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker, ResourceMonitor. - Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V> (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats). - System: process/CPU/memory metrics (Metrics.hpp) and a streaming Process API. Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions, history states, deferred events), Configuration/Logging reflection helpers, and the accompanying test suites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
43b5a81504
commit
80293ee56f
93 files changed
+8500
-3312
No files matched your search
@@ -0,0 +1,61 @@
|
||||
#include <Void/Data/Reflect.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace J = Void::Json;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Address {
|
||||
std::string city = "?";
|
||||
int zip = 0;
|
||||
};
|
||||
struct User {
|
||||
[[= J::Rename{"user_id"}]] int id = 0;
|
||||
[[= J::Skip{}]] int cache = 99;
|
||||
[[= J::Required{}]] std::string name = "";
|
||||
[[= J::Flatten{}]] Address addr{};
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// @tag reflection
|
||||
Void::Testing::Test json_annotations_to_json()
|
||||
{
|
||||
User u{7, 99, "neo", Address{"zion", 100}};
|
||||
const auto j = J::to_json(u);
|
||||
Void::Testing::expect(j.find("user_id") != nullptr); // Rename
|
||||
Void::Testing::expect_eq(j.find("user_id")->as_int(), std::int64_t{7});
|
||||
Void::Testing::expect(j.find("cache") == nullptr); // Skip
|
||||
Void::Testing::expect(j.find("name") != nullptr);
|
||||
// Flatten: Address keys appear at top level, "addr" does not.
|
||||
Void::Testing::expect(j.find("city") != nullptr);
|
||||
Void::Testing::expect_eq(j.find("city")->as_string(), std::string{"zion"});
|
||||
Void::Testing::expect(j.find("zip") != nullptr);
|
||||
Void::Testing::expect(j.find("addr") == nullptr);
|
||||
}
|
||||
|
||||
// @tag reflection
|
||||
Void::Testing::Test json_annotations_round_trip()
|
||||
{
|
||||
User u{7, 99, "neo", Address{"zion", 100}};
|
||||
const auto j = J::to_json(u);
|
||||
const auto back = J::from_json<User>(j);
|
||||
Void::Testing::expect(back.has_value());
|
||||
Void::Testing::expect_eq(back->id, 7);
|
||||
Void::Testing::expect_eq(back->name, std::string{"neo"});
|
||||
Void::Testing::expect_eq(back->addr.city, std::string{"zion"});
|
||||
Void::Testing::expect_eq(back->addr.zip, 100);
|
||||
Void::Testing::expect_eq(back->cache, 99); // Skip keeps default
|
||||
}
|
||||
|
||||
// @tag reflection
|
||||
Void::Testing::Test json_required_missing_is_error()
|
||||
{
|
||||
const auto j = J::parse(R"({"user_id":1,"city":"x","zip":2})");
|
||||
Void::Testing::expect(j.has_value());
|
||||
const auto r = J::from_json<User>(*j);
|
||||
Void::Testing::expect(!r.has_value());
|
||||
Void::Testing::expect_eq(r.error().field, std::string{"name"});
|
||||
}
|
||||
Reference in new issue
Block a user