LCOV - code coverage report
Current view: top level - src/config/parsers - dead_letters_config_parser.cpp (source / functions) Coverage Total Hit
Test: HPActor Coverage Lines: 77.8 % 27 21
Test Date: 2026-05-20 02:24:49 Functions: 50.0 % 4 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright 2026 HPActor Contributors
       2                 :             : //
       3                 :             : // Licensed under the Apache License, Version 2.0 (the "License");
       4                 :             : // you may not use this file except in compliance with the License.
       5                 :             : // You may obtain a copy of the License at
       6                 :             : //
       7                 :             : //     http://www.apache.org/licenses/LICENSE-2.0
       8                 :             : //
       9                 :             : // Unless required by applicable law or agreed to in writing, software
      10                 :             : // distributed under the License is distributed on an "AS IS" BASIS,
      11                 :             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :             : // See the License for the specific language governing permissions and
      13                 :             : // limitations under the License.
      14                 :             : 
      15                 :             : #include <hpactor/config/toml_config_parser.hpp>
      16                 :             : #include <hpactor/config/toml_parser_registry.hpp>
      17                 :             : #include <hpactor/mailbox/dead_letter_queue.hpp>
      18                 :             : 
      19                 :             : #include <string>
      20                 :             : 
      21                 :             : namespace hpactor::config {
      22                 :             : namespace {
      23                 :             : 
      24                 :             : static hpactor::mailbox::DeadLetterOverflowPolicy
      25                 :           4 : parse_dl_overflow_policy(const std::string& s) {
      26                 :           4 :     if (s == "drop_newest_record")
      27                 :           0 :         return hpactor::mailbox::DeadLetterOverflowPolicy::DropNewestRecord;
      28                 :           4 :     if (s == "metadata_only")
      29                 :           4 :         return hpactor::mailbox::DeadLetterOverflowPolicy::MetadataOnly;
      30                 :           0 :     return hpactor::mailbox::DeadLetterOverflowPolicy::DropOldestRecord;
      31                 :             : }
      32                 :             : 
      33                 :             : class DeadLettersConfigParser final : public ITomlSystemConfigParser {
      34                 :             :   public:
      35                 :             :     static constexpr std::string_view kName = "system.dead_letters";
      36                 :             :     static constexpr int kOrder = 95;
      37                 :             : 
      38                 :           0 :     std::string_view name() const noexcept override {
      39                 :           0 :         return kName;
      40                 :             :     }
      41                 :           0 :     int order() const noexcept override {
      42                 :           0 :         return kOrder;
      43                 :             :     }
      44                 :             : 
      45                 :          35 :     result<void> parse(const TomlTableView& system, SystemDef& out,
      46                 :             :                        TomlParseContext& /*ctx*/) const override {
      47                 :          35 :         auto dt = system.table("dead_letters");
      48                 :          35 :         if (!dt.valid())
      49                 :          31 :             return result<void>::make();
      50                 :             : 
      51                 :           4 :         out.dead_letters.enabled = dt.read_bool("enabled", true);
      52                 :           4 :         out.dead_letters.capacity = dt.read_uint32("capacity", 4096);
      53                 :           4 :         out.dead_letters.byte_capacity = dt.read_uint32("byte_capacity", 0);
      54                 :           4 :         out.dead_letters.max_payload_sample_bytes =
      55                 :           4 :             dt.read_uint32("max_payload_sample_bytes", 512);
      56                 :           4 :         out.dead_letters.overflow_policy =
      57                 :           4 :             parse_dl_overflow_policy(dt.read_string("overflow_policy", "drop_"
      58                 :             :                                                                        "oldest_"
      59                 :             :                                                                        "recor"
      60                 :             :                                                                        "d"));
      61                 :           4 :         out.dead_letters.store_payload = dt.read_bool("store_payload", true);
      62                 :           4 :         out.dead_letters.alert_on_first_failure =
      63                 :           4 :             dt.read_bool("alert_on_first_failure", false);
      64                 :           4 :         out.dead_letters.alert_threshold_per_minute =
      65                 :           4 :             dt.read_uint32("alert_threshold_per_minute", 100);
      66                 :             : 
      67                 :           4 :         return result<void>::make();
      68                 :             :     }
      69                 :             : };
      70                 :             : 
      71                 :             : const TomlSystemParserRegistration<DeadLettersConfigParser> kRegisterDeadLettersConfigParser;
      72                 :             : 
      73                 :             : } // anonymous namespace
      74                 :             : } // namespace hpactor::config
        

Generated by: LCOV version 2.0-1