// Test a run of the controller and the data it logs to log file TEST(FTDCControllerTest, TestFull) { unittest::TempDir tempdir("metrics_testpath"); boost::filesystem::path dir(tempdir.path()); createDirectoryClean(dir); FTDCConfig config; config.enabled = true; config.period = Milliseconds(1); config.maxFileSizeBytes = FTDCConfig::kMaxFileSizeBytesDefault; config.maxDirectorySizeBytes = FTDCConfig::kMaxDirectorySizeBytesDefault; FTDCController c(dir, config); auto c1 = std::unique_ptr<FTDCMetricsCollectorMock2>(new FTDCMetricsCollectorMock2()); auto c2 = std::unique_ptr<FTDCMetricsCollectorMockRotate>(new FTDCMetricsCollectorMockRotate()); auto c1Ptr = c1.get(); auto c2Ptr = c2.get(); c1Ptr->setSignalOnCount(100); c.addPeriodicCollector(std::move(c1)); c.addOnRotateCollector(std::move(c2)); c.start(); // Wait for 100 samples to have occured c1Ptr->wait(); c.stop(); auto docsPeriodic = c1Ptr->getDocs(); ASSERT_GREATER_THAN_OR_EQUALS(docsPeriodic.size(), 100UL); auto docsRotate = c2Ptr->getDocs(); ASSERT_EQUALS(docsRotate.size(), 1UL); std::vector<BSONObj> allDocs; allDocs.insert(allDocs.end(), docsRotate.begin(), docsRotate.end()); allDocs.insert(allDocs.end(), docsPeriodic.begin(), docsPeriodic.end()); auto files = scanDirectory(dir); ASSERT_EQUALS(files.size(), 2UL); auto alog = files[0]; ValidateDocumentList(alog, allDocs); }
list<int> *Searcher::search(list<string> &terms, list<int> &res) { int ndocs = getDocs(); vector<double> A(ndocs + 1); list<int> numhits; BOOST_FOREACH(string &term, terms) { Hits hits = getHits(term); int ft = hits.size(); if(hits.size() == 0) continue; Hits::iterator ai; for(ai = hits.begin(); ai != hits.end(); ++ai) { Node &anode = *ai; int doc = anode.doc; double wdt = getWdt(anode.freq, getWd()[doc]); double wqt = getWqt(ndocs, ft); A[doc] += wdt * wqt; } hits.free(); }