|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +#include <fluent-bit/flb_config.h> |
| 4 | +#include <fluent-bit/flb_engine.h> |
| 5 | +#include "flb_tests_internal.h" |
| 6 | + |
| 7 | +static void test_target_level_thresholds() |
| 8 | +{ |
| 9 | + struct flb_config *config; |
| 10 | + |
| 11 | + config = flb_config_init(); |
| 12 | + TEST_CHECK(config != NULL); |
| 13 | + |
| 14 | + config->flush_adaptive_low_pressure = 25.0; |
| 15 | + config->flush_adaptive_medium_pressure = 50.0; |
| 16 | + config->flush_adaptive_high_pressure = 75.0; |
| 17 | + |
| 18 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 0.0) == 0); |
| 19 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 25.0) == 0); |
| 20 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 25.1) == 1); |
| 21 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 49.9) == 1); |
| 22 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 50.0) == 2); |
| 23 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 74.9) == 2); |
| 24 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 75.0) == 3); |
| 25 | + TEST_CHECK(flb_engine_adaptive_flush_target_level(config, 100.0) == 3); |
| 26 | + |
| 27 | + flb_config_exit(config); |
| 28 | +} |
| 29 | + |
| 30 | +static void test_interval_levels_and_bounds() |
| 31 | +{ |
| 32 | + struct flb_config *config; |
| 33 | + |
| 34 | + config = flb_config_init(); |
| 35 | + TEST_CHECK(config != NULL); |
| 36 | + |
| 37 | + config->flush = 1.0; |
| 38 | + config->flush_adaptive_min_interval = 0.5; |
| 39 | + config->flush_adaptive_max_interval = 2.0; |
| 40 | + |
| 41 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 0) == 2.0); |
| 42 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 1) == 1.0); |
| 43 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 2) == 0.75); |
| 44 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 3) == 0.5); |
| 45 | + |
| 46 | + /* clamp low/high out-of-range levels */ |
| 47 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, -1) == 2.0); |
| 48 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 9) == 0.5); |
| 49 | + |
| 50 | + /* clamp by min/max bounds */ |
| 51 | + config->flush = 10.0; |
| 52 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 3) == 2.0); |
| 53 | + |
| 54 | + config->flush = 0.1; |
| 55 | + TEST_CHECK(flb_engine_adaptive_flush_interval(config, 3) == 0.5); |
| 56 | + |
| 57 | + flb_config_exit(config); |
| 58 | +} |
| 59 | + |
| 60 | +TEST_LIST = { |
| 61 | + { "target_level_thresholds", test_target_level_thresholds }, |
| 62 | + { "interval_levels_and_bounds", test_interval_levels_and_bounds }, |
| 63 | + { 0 } |
| 64 | +}; |
0 commit comments