proxygen
LoggerDBTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <folly/logging/LoggerDB.h>
17 
18 #include <folly/logging/Logger.h>
21 
22 using namespace folly;
23 
24 TEST(LoggerDB, lookupNameCanonicalization) {
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 }
34 
35 TEST(LoggerDB, getCategory) {
37 }
38 
39 TEST(LoggerDB, flushAllHandlers) {
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 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
FOLLY_NOINLINE void foo2()
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
TEST(SequencedExecutor, CPUThreadPoolExecutor)