aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/log_ut.cpp
diff options
context:
space:
mode:
authormsherbakov <msherbakov@yandex-team.ru>2022-02-10 16:49:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:17 +0300
commita0ffafe83b7d6229709a32fa942c71d672ac989c (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/actors/core/log_ut.cpp
parentc224a621661ddd69699f9476922eb316607ef57e (diff)
downloadydb-a0ffafe83b7d6229709a32fa942c71d672ac989c.tar.gz
Restoring authorship annotation for <msherbakov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/actors/core/log_ut.cpp')
-rw-r--r--library/cpp/actors/core/log_ut.cpp250
1 files changed, 125 insertions, 125 deletions
diff --git a/library/cpp/actors/core/log_ut.cpp b/library/cpp/actors/core/log_ut.cpp
index f5396cc8b1..09b5f88ea2 100644
--- a/library/cpp/actors/core/log_ut.cpp
+++ b/library/cpp/actors/core/log_ut.cpp
@@ -1,27 +1,27 @@
-#include "log.h"
-
+#include "log.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <library/cpp/actors/testlib/test_runtime.h>
-
-using namespace NMonitoring;
-using namespace NActors;
-using namespace NActors::NLog;
-
-namespace {
- const TString& ServiceToString(int) {
- static const TString FAKE{"FAKE"};
- return FAKE;
- }
-
- TIntrusivePtr<TSettings> DefaultSettings() {
+
+using namespace NMonitoring;
+using namespace NActors;
+using namespace NActors::NLog;
+
+namespace {
+ const TString& ServiceToString(int) {
+ static const TString FAKE{"FAKE"};
+ return FAKE;
+ }
+
+ TIntrusivePtr<TSettings> DefaultSettings() {
auto loggerId = TActorId{0, "Logger"};
- auto s = MakeIntrusive<TSettings>(loggerId, 0, EPriority::PRI_TRACE);
- s->SetAllowDrop(false);
- s->Append(0, 1, ServiceToString);
- return s;
- }
-
+ auto s = MakeIntrusive<TSettings>(loggerId, 0, EPriority::PRI_TRACE);
+ s->SetAllowDrop(false);
+ s->Append(0, 1, ServiceToString);
+ return s;
+ }
+
TIntrusivePtr<TSettings> DroppingSettings(ui64 timeThresholdMs) {
auto loggerId = TActorId{0, "Logger"};
auto s = MakeIntrusive<TSettings>(
@@ -35,123 +35,123 @@ namespace {
return s;
}
- class TMockBackend: public TLogBackend {
- public:
- using TWriteImpl = std::function<void(const TLogRecord&)>;
- using TReopenImpl = std::function<void()>;
-
- static void REOPEN_NOP() { }
-
- TMockBackend(TWriteImpl writeImpl, TReopenImpl reopenImpl = REOPEN_NOP)
- : WriteImpl_{writeImpl}
- , ReopenImpl_{reopenImpl}
- {
- }
-
- void WriteData(const TLogRecord& r) override {
- WriteImpl_(r);
- }
-
- void ReopenLog() override { }
-
- void SetWriteImpl(TWriteImpl writeImpl) {
- WriteImpl_ = writeImpl;
- }
-
- private:
- TWriteImpl WriteImpl_;
- TReopenImpl ReopenImpl_;
- };
-
- void ThrowAlways(const TLogRecord&) {
- ythrow yexception();
- };
-
- struct TFixture {
+ class TMockBackend: public TLogBackend {
+ public:
+ using TWriteImpl = std::function<void(const TLogRecord&)>;
+ using TReopenImpl = std::function<void()>;
+
+ static void REOPEN_NOP() { }
+
+ TMockBackend(TWriteImpl writeImpl, TReopenImpl reopenImpl = REOPEN_NOP)
+ : WriteImpl_{writeImpl}
+ , ReopenImpl_{reopenImpl}
+ {
+ }
+
+ void WriteData(const TLogRecord& r) override {
+ WriteImpl_(r);
+ }
+
+ void ReopenLog() override { }
+
+ void SetWriteImpl(TWriteImpl writeImpl) {
+ WriteImpl_ = writeImpl;
+ }
+
+ private:
+ TWriteImpl WriteImpl_;
+ TReopenImpl ReopenImpl_;
+ };
+
+ void ThrowAlways(const TLogRecord&) {
+ ythrow yexception();
+ };
+
+ struct TFixture {
TFixture(
TIntrusivePtr<TSettings> settings,
TMockBackend::TWriteImpl writeImpl = ThrowAlways)
{
- Runtime.Initialize();
- LogBackend.reset(new TMockBackend{writeImpl});
+ Runtime.Initialize();
+ LogBackend.reset(new TMockBackend{writeImpl});
LoggerActor = Runtime.Register(new TLoggerActor{settings, LogBackend, Counters});
- Runtime.SetScheduledEventFilter([] (auto&&, auto&&, auto&&, auto) {
- return false;
- });
- }
-
+ Runtime.SetScheduledEventFilter([] (auto&&, auto&&, auto&&, auto) {
+ return false;
+ });
+ }
+
TFixture(TMockBackend::TWriteImpl writeImpl = ThrowAlways)
: TFixture(DefaultSettings(), writeImpl)
{}
- void WriteLog() {
- Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(TInstant::Zero(), TLevel{EPrio::Emerg}, 0, "foo")});
- }
-
+ void WriteLog() {
+ Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(TInstant::Zero(), TLevel{EPrio::Emerg}, 0, "foo")});
+ }
+
void WriteLog(TInstant ts) {
Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{EPrio::Emerg}, 0, "foo")});
}
- void Wakeup() {
- Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvents::TEvWakeup});
- }
-
- TIntrusivePtr<TDynamicCounters> Counters{MakeIntrusive<TDynamicCounters>()};
- std::shared_ptr<TMockBackend> LogBackend;
+ void Wakeup() {
+ Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvents::TEvWakeup});
+ }
+
+ TIntrusivePtr<TDynamicCounters> Counters{MakeIntrusive<TDynamicCounters>()};
+ std::shared_ptr<TMockBackend> LogBackend;
TActorId LoggerActor;
- TTestActorRuntimeBase Runtime;
- };
-}
-
-
-Y_UNIT_TEST_SUITE(TLoggerActorTest) {
- Y_UNIT_TEST(NoCrashOnWriteFailure) {
- TFixture test;
- test.WriteLog();
- // everything is okay as long as we get here
- }
-
- Y_UNIT_TEST(SubsequentWritesAreIgnored) {
- size_t count{0};
- auto countWrites = [&count] (auto&& r) {
- count++;
- ThrowAlways(r);
- };
-
- TFixture test{countWrites};
- test.WriteLog();
- UNIT_ASSERT_VALUES_EQUAL(count, 1);
-
- // at this point we should have started dropping messages
- for (auto i = 0; i < 5; ++i) {
- test.WriteLog();
- }
-
- UNIT_ASSERT_VALUES_EQUAL(count, 1);
- }
-
- Y_UNIT_TEST(LoggerCanRecover) {
- TFixture test;
- test.WriteLog();
-
- TVector<TString> messages;
- auto acceptWrites = [&] (const TLogRecord& r) {
- messages.emplace_back(r.Data, r.Len);
- };
-
- auto scheduled = test.Runtime.CaptureScheduledEvents();
- UNIT_ASSERT_VALUES_EQUAL(scheduled.size(), 1);
-
- test.LogBackend->SetWriteImpl(acceptWrites);
- test.Wakeup();
-
- const auto COUNT = 10;
- for (auto i = 0; i < COUNT; ++i) {
- test.WriteLog();
- }
-
- UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT);
- }
+ TTestActorRuntimeBase Runtime;
+ };
+}
+
+
+Y_UNIT_TEST_SUITE(TLoggerActorTest) {
+ Y_UNIT_TEST(NoCrashOnWriteFailure) {
+ TFixture test;
+ test.WriteLog();
+ // everything is okay as long as we get here
+ }
+
+ Y_UNIT_TEST(SubsequentWritesAreIgnored) {
+ size_t count{0};
+ auto countWrites = [&count] (auto&& r) {
+ count++;
+ ThrowAlways(r);
+ };
+
+ TFixture test{countWrites};
+ test.WriteLog();
+ UNIT_ASSERT_VALUES_EQUAL(count, 1);
+
+ // at this point we should have started dropping messages
+ for (auto i = 0; i < 5; ++i) {
+ test.WriteLog();
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(count, 1);
+ }
+
+ Y_UNIT_TEST(LoggerCanRecover) {
+ TFixture test;
+ test.WriteLog();
+
+ TVector<TString> messages;
+ auto acceptWrites = [&] (const TLogRecord& r) {
+ messages.emplace_back(r.Data, r.Len);
+ };
+
+ auto scheduled = test.Runtime.CaptureScheduledEvents();
+ UNIT_ASSERT_VALUES_EQUAL(scheduled.size(), 1);
+
+ test.LogBackend->SetWriteImpl(acceptWrites);
+ test.Wakeup();
+
+ const auto COUNT = 10;
+ for (auto i = 0; i < COUNT; ++i) {
+ test.WriteLog();
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT);
+ }
Y_UNIT_TEST(ShouldObeyTimeThresholdMsWhenOverloaded) {
TFixture test{DroppingSettings(5000)};
@@ -182,4 +182,4 @@ Y_UNIT_TEST_SUITE(TLoggerActorTest) {
UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1);
}
-}
+}