proxygen
LoggerDBTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (LoggerDB, lookupNameCanonicalization)
 
 TEST (LoggerDB, getCategory)
 
 TEST (LoggerDB, flushAllHandlers)
 

Function Documentation

TEST ( LoggerDB  ,
lookupNameCanonicalization   
)

Definition at line 24 of file LoggerDBTest.cpp.

References EXPECT_EQ, foo2(), and folly::LoggerDB::TESTING.

24  {
25  LoggerDB db{LoggerDB::TESTING};
26  Logger foo{&db, "foo"};
27  Logger foo2{&db, "..foo.."};
28  EXPECT_EQ(foo.getCategory(), foo2.getCategory());
29 
30  Logger fooBar{&db, "foo.bar"};
31  Logger fooBar2{&db, ".foo..bar"};
32  EXPECT_EQ(fooBar.getCategory(), fooBar2.getCategory());
33 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
FOLLY_NOINLINE void foo2()
TEST ( LoggerDB  ,
getCategory   
)

Definition at line 35 of file LoggerDBTest.cpp.

References folly::LoggerDB::TESTING.

35  {
36  LoggerDB db{LoggerDB::TESTING};
37 }
TEST ( LoggerDB  ,
flushAllHandlers   
)

Definition at line 39 of file LoggerDBTest.cpp.

References EXPECT_EQ, and folly::LoggerDB::TESTING.

39  {
40  LoggerDB db{LoggerDB::TESTING};
41  auto* cat1 = db.getCategory("foo");
42  auto* cat2 = db.getCategory("foo.bar.test");
43  auto* cat3 = db.getCategory("hello.world");
44  auto* cat4 = db.getCategory("other.category");
45 
46  auto h1 = std::make_shared<TestLogHandler>();
47  auto h2 = std::make_shared<TestLogHandler>();
48  auto h3 = std::make_shared<TestLogHandler>();
49 
50  cat1->addHandler(h1);
51 
52  cat2->addHandler(h2);
53  cat2->addHandler(h3);
54 
55  cat3->addHandler(h1);
56  cat3->addHandler(h2);
57  cat3->addHandler(h3);
58 
59  cat4->addHandler(h1);
60 
61  EXPECT_EQ(0, h1->getFlushCount());
62  EXPECT_EQ(0, h2->getFlushCount());
63  EXPECT_EQ(0, h3->getFlushCount());
64 
65  // Calling flushAllHandlers() should only flush each handler once,
66  // even when they are attached to multiple categories.
67  db.flushAllHandlers();
68  EXPECT_EQ(1, h1->getFlushCount());
69  EXPECT_EQ(1, h2->getFlushCount());
70  EXPECT_EQ(1, h3->getFlushCount());
71 
72  db.flushAllHandlers();
73  EXPECT_EQ(2, h1->getFlushCount());
74  EXPECT_EQ(2, h2->getFlushCount());
75  EXPECT_EQ(2, h3->getFlushCount());
76 }
LogCategory * getCategory(folly::StringPiece name)
Definition: LoggerDB.cpp:133
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void addHandler(std::shared_ptr< LogHandler > handler)