16 #include <aws/core/utils/logging/AWSLogging.h> 17 #include <aws/core/utils/logging/ConsoleLogSystem.h> 19 #include <gmock/gmock.h> 20 #include <gtest/gtest.h> 33 return !logs.empty() && !data_tokens.empty();
37 return options_.delete_stale_data;
41 if(isDataAvailable()){
44 return data_tokens[it-1];
50 void write(
const std::string &data){
52 data_tokens.push_back(data_token);
58 for(
int i = 0; i < (int)data_tokens.size(); i++){
59 if(data_tokens[i] == token){
60 data_tokens.erase(data_tokens.begin()+i);
61 logs.erase(logs.begin()+i);
69 std::vector<std::string>
logs;
71 uint64_t data_token = 1;
79 test_strategy = std::make_shared<TestStrategy>(options);
80 file_manager = std::make_unique<LogFileManager>(test_strategy);
89 for (
auto ts : timestamps){
90 input_event.SetTimestamp(ts);
91 input_event.SetMessage(
"Testing readBatch");
92 log_data.push_back(input_event);
97 while(test_strategy->isDataAvailable()){
98 test_strategy->it = 0;
99 batch = file_manager->readBatch(test_strategy->logs.size());
101 file_manager->deleteStaleData();
102 ASSERT_TRUE(validateBatch());
107 for (
auto dt : batch.data_tokens){
108 test_strategy->resolve(dt,
true);
114 for(
auto bd : batch.batch_data){
115 if(expectedTimeStamps.empty())
118 long expectedTimestamp = expectedTimeStamps.front().back();
119 expectedTimeStamps.front().pop_back();
121 if(expectedTimeStamps.front().empty())
122 expectedTimeStamps.erase(expectedTimeStamps.begin());
124 if(bd.GetTimestamp() != expectedTimestamp){
155 createLogs(timestamps);
156 file_manager->write(log_data);
165 expectedTimeStamps = {{ONE_DAY_IN_MILLISEC+2, ONE_DAY_IN_MILLISEC+1, ONE_DAY_IN_MILLISEC}, {2, 1, 0}};
166 createLogs(timestamps);
167 file_manager->write(log_data);
176 expectedTimeStamps = {{ONE_DAY_IN_MILLISEC*2+10}, {ONE_DAY_IN_MILLISEC+5},{4, 2, 1, 0}};
177 createLogs(timestamps);
178 file_manager->write(log_data);
190 createLogs(timestamps);
191 file_manager->write(log_data);
203 createLogs(timestamps);
204 file_manager->write(log_data);
216 createLogs(timestamps);
217 file_manager->write(log_data);
227 test_strategy->options_.delete_stale_data =
false;
230 createLogs(timestamps);
231 file_manager->write(log_data);
238 TEST(DeleteOptionTest, file_manager_delete_true) {
240 std::shared_ptr<FileManagerStrategy> file_manager_strategy = std::make_shared<FileManagerStrategy>(options);
242 ASSERT_TRUE(file_manager_strategy->isDeleteStaleData());
248 TEST(DeleteOptionTest, file_manager_delete_false) {
250 std::shared_ptr<FileManagerStrategy> file_manager_strategy = std::make_shared<FileManagerStrategy>(options);
252 ASSERT_FALSE(file_manager_strategy->isDeleteStaleData());
255 int main(
int argc,
char** argv)
257 Aws::Utils::Logging::InitializeAWSLogging(
258 Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>(
259 "RunUnitTests", Aws::Utils::Logging::LogLevel::Trace));
260 ::testing::InitGoogleMock(&argc, argv);
261 int exitCode = RUN_ALL_TESTS();
262 Aws::Utils::Logging::ShutdownAWSLogging();
std::vector< std::vector< long > > expectedTimeStamps
const long TWO_WEEK_IN_MILLISEC
Aws::CloudWatchLogs::Model::InputLogEvent input_event
void createLogs(const std::vector< long > ×tamps)
TestStrategy(const FileManagerStrategyOptions &options)
std::vector< uint64_t > data_tokens
FileObject< LogCollection > batch
FileManagerStrategyOptions options_
TEST(DeleteOptionTest, file_manager_delete_true)
std::vector< std::string > logs
TEST_F(LogBatchTest, test_readBatch_1_batch)
std::list< LogType > LogCollection
DataToken read(std::string &data) override
int main(int argc, char **argv)
std::shared_ptr< TestStrategy > test_strategy
void write(const std::string &data)
const long ONE_DAY_IN_MILLISEC
std::unique_ptr< LogFileManager > file_manager
std::vector< long > timestamps
void resolve(const DataToken &token, bool is_success)