aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/failure_injector/failure_injector.h
blob: 6db79fc8c0e0e79f545da84ea394e2978158f7cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <util/generic/hash.h>
#include <util/generic/string.h>
#include <util/system/mutex.h>

#include <string_view>

namespace NYql {

class TFailureInjector {
public:
    struct TFailureSpec {
        ui64 Skip;
        ui64 CountOfFails;
    };

    static void Activate();

    static void Set(std::string_view name, ui64 skip, ui64 countOfFails);
    static void Reach(std::string_view name, std::function<void()> action);
    static THashMap<TString, TFailureSpec> GetCurrentState();

private:
    void ActivateImpl();

    void SetImpl(std::string_view name, ui64 skip, ui64 countOfFails);
    void ReachImpl(std::string_view name, std::function<void()> action);
    THashMap<TString, TFailureSpec> GetCurrentStateImpl();

    std::atomic<bool> Enabled_ = false;
    THashMap<TString, TFailureSpec> FailureSpecs;
    TMutex Lock;
};

} // NYql