diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.cpp b/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.cpp index 1ac776ccf..16fd88e61 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.cpp +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.cpp @@ -271,6 +271,11 @@ Parameters::Parameters(const CommandLineArguments& arguments, (!d_dataFile.path().empty() && !d_dataFile.resetIterator(ss))) { throw bsl::runtime_error(ss.str()); } + // TODO: used for testing, consider better way + if (d_journalFile.path().empty()) + d_journalFile.setIterator(nullptr); + if (d_dataFile.path().empty()) + d_dataFile.setIterator(nullptr); } void Parameters::print(bsl::ostream& ss) const @@ -370,5 +375,13 @@ ITER* Parameters::FileHandler::iterator() return &d_iter; } +// TODO: used for testing, consider better way +template +void Parameters::FileHandler::setIterator(ITER* iter) +{ + if (iterator() != nullptr && iter != nullptr) + d_iter = *iter; +} + } // close package namespace } // close enterprise namespace diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.h b/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.h index 5245d3152..6adf663dd 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.h +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_parameters.h @@ -118,6 +118,9 @@ class Parameters { // MANIPULATORS /// iterator resetter bool resetIterator(bsl::ostream& errorDescription); + + // TODO: used for testing, consider better way + void setIterator(ITER* iter); /// Mapped file iterator ITER* iterator(); diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.cpp b/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.cpp index 429aa68b1..980aaa5d0 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.cpp +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.cpp @@ -95,18 +95,6 @@ bool resetIterator(mqbs::MappedFileDescriptor* mfd, // CREATORS -SearchProcessor::SearchProcessor(const bsl::shared_ptr& params, - mqbs::JournalFileIterator* journalFileIter, - bslma::Allocator* allocator) -: CommandProcessor(params) -, d_dataFile(allocator) -, d_journalFile(allocator) -, d_journalFileIter(journalFileIter) -, d_allocator_p(bslma::Default::allocator(allocator)) -{ - // NOTHING -} - SearchProcessor::SearchProcessor(const bsl::shared_ptr& params, bslma::Allocator* allocator) : CommandProcessor(params) @@ -117,20 +105,6 @@ SearchProcessor::SearchProcessor(const bsl::shared_ptr& params, void SearchProcessor::process(bsl::ostream& ostream) { - // ostream << "SearchProcessor::process()\n"; - // d_parameters->print(ostream); - - // TODO: remove - Initialize journal file iterator from real file - if (!d_journalFileIter->isValid()) { - if (!resetIterator(&d_journalFd, - d_journalFileIter, - d_journalFile.c_str(), - ostream)) { - return; // RETURN - } - ostream << "Created Journal iterator successfully" << bsl::endl; - } - // TODO: why unique_ptr doesn't support deleter in reset() // bsl::unique_ptr searchResult_p; bsl::shared_ptr searchResult_p; @@ -176,7 +150,7 @@ void SearchProcessor::process(bsl::ostream& ostream) bool stopSearch = false; // Iterate through all Journal file records - mqbs::JournalFileIterator* iter = d_journalFileIter; + mqbs::JournalFileIterator* iter = d_parameters->journalFile()->iterator(); while (true) { if (stopSearch || !iter->hasRecordSizeRemaining()) { searchResult_p->outputResult(); diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.h b/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.h index f18f225cd..359ff5507 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.h +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.h @@ -35,54 +35,13 @@ namespace m_bmqstoragetool { class SearchProcessor : public CommandProcessor { private: - // enum SearchMode { - // k_ALL, // search all messages in journal file - // k_LIST, // search messages by given GUIDs in journal file - // k_OUTSTANDING, // search outstanding (not deleted) messages in - // journal - // // file - // k_CONFIRMED, // search confirmed by all consumers (deleted) - // messages - // // in journal file - // k_PARTIALLY_CONFIRMED // search confirmed at least by one consumer - // // messages in journal file - // }; - - // TODO: refactor to class, move to separate file for sharing. - // VST representing message details. - // struct MessageDetails { - // mqbs::MessageRecord messageRecord; - // bsl::vector confirmRecords; - // mqbs::DeletionRecordFlag::Enum deleteRecordFlag; - // bool partiallyConfirmed; // There is at least one confirmation - // message - // }; - - // typedef bsl::unordered_map - // MessagesDetails; - // DATA - bsl::string d_dataFile; - - bsl::string d_journalFile; - - mqbs::MappedFileDescriptor d_dataFd; - - mqbs::MappedFileDescriptor d_journalFd; - - mqbs::DataFileIterator* d_dataFileIter; - - mqbs::JournalFileIterator* d_journalFileIter; - bslma::Allocator* d_allocator_p; // MANIPULATORS public: // CREATORS - explicit SearchProcessor(const bsl::shared_ptr& params, - mqbs::JournalFileIterator* journalFileIter, - bslma::Allocator* allocator); explicit SearchProcessor(const bsl::shared_ptr& params, bslma::Allocator* allocator); diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.t.cpp b/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.t.cpp index caf1c6779..5e12cd4a8 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.t.cpp +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_searchprocessor.t.cpp @@ -525,10 +525,9 @@ static void test1_breathingTest() CommandLineArguments arguments; bsl::unique_ptr params = bsl::make_unique(arguments, s_allocator_p); + params->journalFile()->setIterator(&it); - auto searchProcessor = SearchProcessor(bsl::move(params), - &it, - s_allocator_p); + auto searchProcessor = SearchProcessor(bsl::move(params), s_allocator_p); bsl::ostringstream resultStream(s_allocator_p); searchProcessor.process(resultStream); @@ -625,10 +624,9 @@ static void test2_searchGuidTest() } bsl::unique_ptr params = bsl::make_unique(arguments, s_allocator_p); + params->journalFile()->setIterator(&it); - auto searchProcessor = SearchProcessor(bsl::move(params), - &it, - s_allocator_p); + auto searchProcessor = SearchProcessor(bsl::move(params), s_allocator_p); bsl::ostringstream resultStream(s_allocator_p); searchProcessor.process(resultStream); @@ -643,8 +641,6 @@ static void test2_searchGuidTest() ASSERT_EQ(resultStream.str(), expectedStream.str()); - // ASSERT(searchProcessor.getJournalFileIter().isValid()); - s_allocator_p->deallocate(p); } @@ -707,10 +703,9 @@ static void test3_searchNonExistingGuidTest() bsl::unique_ptr params = bsl::make_unique(arguments, s_allocator_p); + params->journalFile()->setIterator(&it); - auto searchProcessor = SearchProcessor(bsl::move(params), - &it, - s_allocator_p); + auto searchProcessor = SearchProcessor(bsl::move(params), s_allocator_p); bsl::ostringstream resultStream(s_allocator_p); searchProcessor.process(resultStream); @@ -773,10 +768,9 @@ static void test4_searchOutstandingMessagesTest() arguments.d_outstanding = true; bsl::unique_ptr params = bsl::make_unique(arguments, s_allocator_p); + params->journalFile()->setIterator(&it); - auto searchProcessor = SearchProcessor(bsl::move(params), - &it, - s_allocator_p); + auto searchProcessor = SearchProcessor(bsl::move(params), s_allocator_p); bsl::ostringstream resultStream(s_allocator_p); searchProcessor.process(resultStream); @@ -848,10 +842,9 @@ static void test5_searchConfirmedMessagesTest() arguments.d_confirmed = true; bsl::unique_ptr params = bsl::make_unique(arguments, s_allocator_p); + params->journalFile()->setIterator(&it); - auto searchProcessor = SearchProcessor(bsl::move(params), - &it, - s_allocator_p); + auto searchProcessor = SearchProcessor(bsl::move(params), s_allocator_p); bsl::ostringstream resultStream(s_allocator_p); searchProcessor.process(resultStream); @@ -924,10 +917,9 @@ static void test6_searchPartiallyConfirmedMessagesTest() arguments.d_partiallyConfirmed = true; bsl::unique_ptr params = bsl::make_unique(arguments, s_allocator_p); + params->journalFile()->setIterator(&it); - auto searchProcessor = SearchProcessor(bsl::move(params), - &it, - s_allocator_p); + auto searchProcessor = SearchProcessor(bsl::move(params), s_allocator_p); bsl::ostringstream resultStream(s_allocator_p); searchProcessor.process(resultStream);