28 using namespace folly;
34 const char* expectedPath,
35 size_t expectedMaxBufferSize) {
38 <<
"handler factory should have created an AsyncFileWriter";
39 EXPECT_EQ(expectedMaxBufferSize, asyncWriter->getMaxBufferSize());
42 struct stat expectedStatInfo;
43 checkUnixError(stat(expectedPath, &expectedStatInfo),
"stat failed");
44 struct stat actualStatInfo;
46 fstat(asyncWriter->getFile().fd(), &actualStatInfo),
"fstat failed");
47 EXPECT_EQ(expectedStatInfo.st_dev, actualStatInfo.st_dev);
48 EXPECT_EQ(expectedStatInfo.st_ino, actualStatInfo.st_ino);
54 size_t expectedMaxBufferSize) {
57 <<
"handler factory should have created an AsyncFileWriter";
58 EXPECT_EQ(expectedMaxBufferSize, asyncWriter->getMaxBufferSize());
59 EXPECT_EQ(expectedFD, asyncWriter->getFile().fd());
67 make_pair(
"path", tmpFile.path().string()),
77 <<
"handler factory should have created a GlogStyleFormatter";
80 stdHandler->getWriter().get(),
81 tmpFile.path().string().c_str(),
90 make_pair(
"stream",
"stderr"),
100 <<
"handler factory should have created a GlogStyleFormatter";
103 stdHandler->getWriter().get(),
113 make_pair(
"stream",
"stdout"),
114 make_pair(
"max_buffer_size",
"4096"),
124 <<
"handler factory should have created a GlogStyleFormatter";
134 make_pair(
"path", tmpFile.path().string()),
135 make_pair(
"max_buffer_size",
"4096000"),
145 <<
"handler factory should have created a GlogStyleFormatter";
148 stdHandler->getWriter().get(), tmpFile.path().string().c_str(), 4096000);
156 make_pair(
"stream",
"stderr"),
157 make_pair(
"async",
"no"),
167 <<
"handler factory should have created a GlogStyleFormatter";
172 EXPECT_EQ(STDERR_FILENO, writer->getFile().fd());
181 auto options = Options{};
184 std::invalid_argument,
185 "no path specified for file handler");
189 auto options = Options{
190 {
"path", tmpFile.path().string()},
191 {
"stream",
"stderr"},
195 std::invalid_argument,
196 "unknown option \"stream\"");
200 auto options = Options{
201 {
"stream",
"nonstdout"},
205 std::invalid_argument,
206 "unknown option \"stream\"");
210 auto options = Options{
211 {
"path", tmpFile.path().string()},
216 std::invalid_argument,
217 "^error processing option \"async\": Invalid value for bool: \"xyz\"$");
221 auto options = Options{
222 {
"path", tmpFile.path().string()},
224 {
"max_buffer_size",
"1234"},
228 std::invalid_argument,
229 "the \"max_buffer_size\" option is only valid for async file handlers");
233 auto options = Options{
234 {
"path", tmpFile.path().string()},
235 {
"max_buffer_size",
"hello"},
239 std::invalid_argument,
240 "^error processing option \"max_buffer_size\": " 241 "Non-digit character found: \"hello\"$");
245 auto options = Options{
246 {
"path", tmpFile.path().string()},
247 {
"max_buffer_size",
"0"},
251 std::invalid_argument,
252 "^error processing option \"max_buffer_size\": " 253 "must be a positive integer$");
257 auto options = Options{
258 {
"path", tmpFile.path().string()},
263 std::invalid_argument,
264 "^unknown option \"foo\"$");
273 auto options = Options{};
276 std::invalid_argument,
277 "no stream name specified for stream handler");
281 auto options = Options{
282 {
"path",
"/tmp/log.txt"},
283 {
"stream",
"stderr"},
287 std::invalid_argument,
288 "unknown option \"path\"");
292 auto options = Options{
293 {
"stream",
"nonstdout"},
297 std::invalid_argument,
298 "unknown stream \"nonstdout\": expected one of stdout or stderr");
302 auto options = Options{
303 {
"stream",
"stderr"},
308 std::invalid_argument,
309 "^error processing option \"async\": Invalid value for bool: \"xyz\"$");
313 auto options = Options{
314 {
"stream",
"stderr"},
316 {
"max_buffer_size",
"1234"},
320 std::invalid_argument,
321 "^the \"max_buffer_size\" option is only valid for " 322 "async file handlers$");
326 auto options = Options{
327 {
"stream",
"stderr"},
328 {
"max_buffer_size",
"hello"},
332 std::invalid_argument,
333 "^error processing option \"max_buffer_size\": " 334 "Non-digit character found: \"hello\"$");
338 auto options = Options{
339 {
"stream",
"stderr"},
340 {
"max_buffer_size",
"0"},
344 std::invalid_argument,
345 "^error processing option \"max_buffer_size\": " 346 "must be a positive integer$");
350 auto options = Options{
351 make_pair(
"stream",
"stderr"),
352 make_pair(
"foo",
"bar"),
356 std::invalid_argument,
357 "unknown option \"foo\"");
#define EXPECT_THROW_RE(statement, exceptionType, pattern)
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
std::shared_ptr< LogHandler > createHandler(const Options &options) override
void handler(int, siginfo_t *, void *)
static constexpr size_t kDefaultMaxBufferSize
std::shared_ptr< LogHandler > createHandler(const Options &options) override
void checkUnixError(ssize_t ret, Args &&...args)
#define EXPECT_TRUE(condition)
void checkAsyncWriter(const LogWriter *writer, const char *expectedPath, size_t expectedMaxBufferSize)
std::unordered_map< std::string, std::string > Options
#define ASSERT_TRUE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)