ManagerImp ( Stoppable& parent, beast::File const& pathToDbFileOrDirectory, beast::Journal journal) : Stoppable ("Validators::Manager", parent) , Thread ("Validators") , m_journal (journal) , m_databaseFile (pathToDbFileOrDirectory) , m_store (m_journal) , m_logic (m_store, m_journal) , m_checkTimer (this) , m_checkSources (false) { m_journal.trace << "Validators constructed"; m_journal.debug << "Validators constructed (debug)"; m_journal.info << "Validators constructed (info)"; if (m_databaseFile.isDirectory ()) m_databaseFile = m_databaseFile.getChildFile("validators.sqlite"); }
void testBackend (beast::String type, std::int64_t const seedValue, int numObjectsToTest = 2000) { std::unique_ptr <Manager> manager (make_Manager ()); DummyScheduler scheduler; testcase ((beast::String ("Backend type=") + type).toStdString()); beast::StringPairArray params; beast::File const path (beast::File::createTempFile ("node_db")); params.set ("type", type); params.set ("path", path.getFullPathName ()); // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); beast::Journal j; { // Open the backend std::unique_ptr <Backend> backend (manager->make_Backend ( params, scheduler, j)); // Write the batch storeBatch (*backend, batch); { // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } { // Reorder and read the copy again Batch copy; beast::UnitTestUtilities::repeatableShuffle (batch.size (), batch, seedValue); fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } } { // Re-open the backend std::unique_ptr <Backend> backend (manager->make_Backend ( params, scheduler, j)); // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } }
ManagerImp ( Stoppable& stoppable, boost::asio::io_service& io_service, beast::File const& pathToDbFileOrDirectory, clock_type& clock, beast::Journal journal) : Manager (stoppable) , io_service_(io_service) , work_(boost::in_place(std::ref(io_service_))) , m_databaseFile (pathToDbFileOrDirectory) , m_clock (clock) , m_journal (journal) , m_store (journal) , checker_ (io_service_) , m_logic (clock, m_store, checker_, journal) { if (m_databaseFile.isDirectory ()) m_databaseFile = m_databaseFile.getChildFile("peerfinder.sqlite"); }
void onPrepare () { beast::Error error (m_store.open (m_databaseFile)); if (error) m_journal.fatal << "Failed to open '" << m_databaseFile.getFullPathName() << "'"; if (! error) m_logic.load (); }