summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/dummyresourcebenchmark.cpp3
-rw-r--r--tests/dummyresourcewritebenchmark.cpp9
-rw-r--r--tests/maildirsyncbenchmark.cpp105
3 files changed, 5 insertions, 112 deletions
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp
index a2de316..79c0c96 100644
--- a/tests/dummyresourcebenchmark.cpp
+++ b/tests/dummyresourcebenchmark.cpp
@@ -14,6 +14,7 @@
14#include "notification_generated.h" 14#include "notification_generated.h"
15#include "test.h" 15#include "test.h"
16#include "testutils.h" 16#include "testutils.h"
17#include "adaptorfactoryregistry.h"
17 18
18#include "hawd/dataset.h" 19#include "hawd/dataset.h"
19#include "hawd/formatter.h" 20#include "hawd/formatter.h"
@@ -150,7 +151,7 @@ private slots:
150 QTime time; 151 QTime time;
151 time.start(); 152 time.start();
152 153
153 DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "test"}); 154 DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")});
154 155
155 flatbuffers::FlatBufferBuilder eventFbb; 156 flatbuffers::FlatBufferBuilder eventFbb;
156 eventFbb.Clear(); 157 eventFbb.Clear();
diff --git a/tests/dummyresourcewritebenchmark.cpp b/tests/dummyresourcewritebenchmark.cpp
index 397e5de..c350b1a 100644
--- a/tests/dummyresourcewritebenchmark.cpp
+++ b/tests/dummyresourcewritebenchmark.cpp
@@ -113,12 +113,7 @@ class DummyResourceWriteBenchmark : public QObject
113 113
114 QTime time; 114 QTime time;
115 time.start(); 115 time.start();
116 116 DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")});
117 auto factory = new ::DummyResourceFactory;
118 factory->registerFacades("dummy", Sink::FacadeFactory::instance());
119 factory->registerAdaptorFactories("dummy", Sink::AdaptorFactoryRegistry::instance());
120
121 ::DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("dummy")});
122 117
123 int bufferSize = 0; 118 int bufferSize = 0;
124 auto command = createEntityBuffer(bufferSize); 119 auto command = createEntityBuffer(bufferSize);
@@ -184,6 +179,8 @@ private slots:
184 void initTestCase() 179 void initTestCase()
185 { 180 {
186 Sink::Log::setDebugOutputLevel(Sink::Log::Warning); 181 Sink::Log::setDebugOutputLevel(Sink::Log::Warning);
182 auto factory = Sink::ResourceFactory::load("sink.dummy");
183 QVERIFY(factory);
187 } 184 }
188 185
189 void cleanup() 186 void cleanup()
diff --git a/tests/maildirsyncbenchmark.cpp b/tests/maildirsyncbenchmark.cpp
deleted file mode 100644
index ab09395..0000000
--- a/tests/maildirsyncbenchmark.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
1#include <QtTest>
2#include <QString>
3#include <iostream>
4
5#include "hawd/dataset.h"
6#include "hawd/formatter.h"
7
8#include "maildirresource/maildirresource.h"
9#include "store.h"
10#include "resourcecontrol.h"
11#include "commands.h"
12#include "entitybuffer.h"
13#include "resourceconfig.h"
14#include "modelresult.h"
15#include "pipeline.h"
16#include "log.h"
17
18
19static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
20{
21 QFileInfo srcFileInfo(srcFilePath);
22 if (srcFileInfo.isDir()) {
23 QDir targetDir(tgtFilePath);
24 targetDir.cdUp();
25 if (!targetDir.mkdir(QFileInfo(srcFilePath).fileName())) {
26 qWarning() << "Failed to create directory " << tgtFilePath;
27 return false;
28 }
29 QDir sourceDir(srcFilePath);
30 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
31 foreach (const QString &fileName, fileNames) {
32 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
33 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
34 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
35 return false;
36 }
37 } else {
38 if (!QFile::copy(srcFilePath, tgtFilePath)) {
39 qWarning() << "Failed to copy file " << srcFilePath << tgtFilePath;
40 return false;
41 }
42 }
43 return true;
44}
45
46/**
47 * Test of complete system using the maildir resource.
48 *
49 * This test requires the maildir resource installed.
50 */
51class MaildirSyncBenchmark : public QObject
52{
53 Q_OBJECT
54
55 QTemporaryDir tempDir;
56 QString targetPath;
57 HAWD::State mHawdState;
58
59private slots:
60 void initTestCase()
61 {
62 targetPath = tempDir.path() + "/maildir1";
63
64 MaildirResource::removeFromDisk("sink.maildir.test1");
65 Sink::ApplicationDomain::SinkResource resource;
66 resource.setProperty("identifier", "sink.maildir.test1");
67 resource.setProperty("type", "sink.maildir");
68 resource.setProperty("path", targetPath);
69 Sink::Store::create(resource).exec().waitForFinished();
70 }
71
72 void cleanup()
73 {
74 MaildirResource::removeFromDisk("sink.maildir.test1");
75 QDir dir(targetPath);
76 dir.removeRecursively();
77 }
78
79 void init()
80 {
81 copyRecursively(TESTDATAPATH "/maildir1", targetPath);
82 }
83
84 void testbench()
85 {
86 auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.maildir.test1");
87 MaildirResource resource("sink.maildir.test1", pipeline);
88 QTime time;
89 time.start();
90 resource.Sink::GenericResource::synchronizeWithSource(Sink::QueryBase()).exec().waitForFinished();
91 std::cout << "Sync took " << time.elapsed() << std::endl;
92 resource.processAllMessages().exec().waitForFinished();
93 const auto allProcessedTime = time.elapsed();
94 std::cout << "All done " << allProcessedTime << std::endl;
95
96 // HAWD::Dataset dataset("maildir_sync", mHawdState);
97 // HAWD::Dataset::Row row = dataset.row();
98 // row.setValue("totalTime", allProcessedTime);
99 // dataset.insertRow(row);
100 // HAWD::Formatter::print(dataset);
101 }
102};
103
104QTEST_MAIN(MaildirSyncBenchmark)
105#include "maildirsyncbenchmark.moc"