MCPcopy Create free account
hub / github.com/apache/impala / TEST

Function TEST

be/src/util/logging-support-test.cc:36–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36TEST(LoggingSupport, DeleteOldLogs) {
37 path dir = filesystem::unique_path();
38 filesystem::create_directories(dir);
39
40 time_t current_time;
41 time(&current_time);
42
43 // Start with one file
44 path file1 = dir / "impala1";
45 CreateFile(file1, current_time - 4);
46
47 string filename_matcher = (filesystem::canonical(dir) / "impala*").string();
48
49 // If there is only one file, it should never be deleted, regardless
50 // of the value of max_log_files.
51 LoggingSupport::DeleteOldLogs(filename_matcher, 0);
52 EXPECT_TRUE(filesystem::exists(file1));
53 LoggingSupport::DeleteOldLogs(filename_matcher, 1);
54 EXPECT_TRUE(filesystem::exists(file1));
55 LoggingSupport::DeleteOldLogs(filename_matcher, 2);
56 EXPECT_TRUE(filesystem::exists(file1));
57
58 // Add two more files.
59 path file2 = dir / "impala2";
60 CreateFile(file2, current_time - 3);
61
62 path file3 = dir / "impala3";
63 CreateFile(file3, current_time - 2);
64
65 // max_log_files < 0 shouldn't remove any files
66 LoggingSupport::DeleteOldLogs(filename_matcher, -1);
67 EXPECT_TRUE(filesystem::exists(file1));
68 EXPECT_TRUE(filesystem::exists(file2));
69 EXPECT_TRUE(filesystem::exists(file3));
70
71 // The oldest file (file1) shoujld be deleted.
72 LoggingSupport::DeleteOldLogs(filename_matcher, 2);
73 EXPECT_FALSE(filesystem::exists(file1));
74 EXPECT_TRUE(filesystem::exists(file2));
75 EXPECT_TRUE(filesystem::exists(file3));
76
77 // Add two more files.
78 path file4 = dir / "impala4";
79 CreateFile(file4, current_time - 1);
80
81 path file5 = dir / "impala5";
82 CreateFile(file5, current_time);
83
84 // The oldest 2 files (file2 and file3) should be deleted.
85 LoggingSupport::DeleteOldLogs(filename_matcher, 2);
86 EXPECT_FALSE(filesystem::exists(file1));
87 EXPECT_FALSE(filesystem::exists(file2));
88 EXPECT_FALSE(filesystem::exists(file3));
89 EXPECT_TRUE(filesystem::exists(file4));
90 EXPECT_TRUE(filesystem::exists(file5));
91
92 filesystem::remove_all(dir);
93}

Callers

nothing calls this directly

Calls 2

timeFunction · 0.85
CreateFileFunction · 0.85

Tested by

no test coverage detected