From da89ac85482997cabd48a2c996c619529f256283 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 11 Feb 2016 16:30:21 +0100 Subject: Maildirsyncbechmark --- tests/maildirsyncbenchmark.cpp | 110 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/maildirsyncbenchmark.cpp (limited to 'tests/maildirsyncbenchmark.cpp') diff --git a/tests/maildirsyncbenchmark.cpp b/tests/maildirsyncbenchmark.cpp new file mode 100644 index 0000000..4f23524 --- /dev/null +++ b/tests/maildirsyncbenchmark.cpp @@ -0,0 +1,110 @@ +#include +#include +#include + +#include "hawd/dataset.h" +#include "hawd/formatter.h" + +#include "maildirresource/maildirresource.h" +#include "store.h" +#include "resourcecontrol.h" +#include "commands.h" +#include "entitybuffer.h" +#include "resourceconfig.h" +#include "modelresult.h" +#include "pipeline.h" +#include "log.h" + + +static bool copyRecursively(const QString &srcFilePath, + const QString &tgtFilePath) +{ + QFileInfo srcFileInfo(srcFilePath); + if (srcFileInfo.isDir()) { + QDir targetDir(tgtFilePath); + targetDir.cdUp(); + if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) { + qWarning() << "Failed to create directory " << tgtFilePath; + return false; + } + QDir sourceDir(srcFilePath); + QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); + foreach (const QString &fileName, fileNames) { + const QString newSrcFilePath + = srcFilePath + QLatin1Char('/') + fileName; + const QString newTgtFilePath + = tgtFilePath + QLatin1Char('/') + fileName; + if (!copyRecursively(newSrcFilePath, newTgtFilePath)) + return false; + } + } else { + if (!QFile::copy(srcFilePath, tgtFilePath)) { + qWarning() << "Failed to copy file " << srcFilePath << tgtFilePath; + return false; + } + } + return true; +} + +/** + * Test of complete system using the maildir resource. + * + * This test requires the maildir resource installed. + */ +class MaildirSyncBenchmark : public QObject +{ + Q_OBJECT + + QTemporaryDir tempDir; + QString targetPath; + HAWD::State mHawdState; + +private Q_SLOTS: + void initTestCase() + { + targetPath = tempDir.path() + "/maildir1"; + + Sink::Log::setDebugOutputLevel(Sink::Log::Log); + MaildirResource::removeFromDisk("org.kde.maildir.test1"); + Sink::ApplicationDomain::SinkResource resource; + resource.setProperty("identifier", "org.kde.maildir.test1"); + resource.setProperty("type", "org.kde.maildir"); + resource.setProperty("path", targetPath); + Sink::Store::create(resource).exec().waitForFinished(); + } + + void cleanup() + { + MaildirResource::removeFromDisk("org.kde.maildir.test1"); + QDir dir(targetPath); + dir.removeRecursively(); + } + + void init() + { + copyRecursively(TESTDATAPATH "/maildir1", targetPath); + } + + void testbench() + { + auto pipeline = QSharedPointer::create("org.kde.maildir.test1"); + MaildirResource resource("org.kde.maildir.test1", pipeline); + QTime time; + time.start(); + resource.Sink::GenericResource::synchronizeWithSource().exec().waitForFinished(); + std::cout << "Sync took " << time.elapsed() << std::endl; + resource.processAllMessages().exec().waitForFinished(); + const auto allProcessedTime = time.elapsed(); + std::cout << "All done " << allProcessedTime << std::endl; + + // HAWD::Dataset dataset("maildir_sync", mHawdState); + // HAWD::Dataset::Row row = dataset.row(); + // row.setValue("totalTime", allProcessedTime); + // dataset.insertRow(row); + // HAWD::Formatter::print(dataset); + + } +}; + +QTEST_MAIN(MaildirSyncBenchmark) +#include "maildirsyncbenchmark.moc" -- cgit v1.2.3