diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-13 14:22:11 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-09-13 14:24:56 +0200 |
commit | e44295ca2005c81e17fcdfa1b9da44275f0a3e45 (patch) | |
tree | adf2ba5163506688e1f78710ab93c08428c3ffdb /tests | |
parent | b15fcfdef6f45da7229334c5452d4696896e9c29 (diff) | |
download | sink-e44295ca2005c81e17fcdfa1b9da44275f0a3e45.tar.gz sink-e44295ca2005c81e17fcdfa1b9da44275f0a3e45.zip |
Benchmark incremental queries
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mailquerybenchmark.cpp | 59 | ||||
-rw-r--r-- | tests/testimplementations.h | 5 |
2 files changed, 60 insertions, 4 deletions
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index 00c156d..ca1e026 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp | |||
@@ -51,16 +51,18 @@ class MailQueryBenchmark : public QObject | |||
51 | QByteArray resourceIdentifier; | 51 | QByteArray resourceIdentifier; |
52 | HAWD::State mHawdState; | 52 | HAWD::State mHawdState; |
53 | 53 | ||
54 | void populateDatabase(int count, int folderSpreadFactor = 0) | 54 | void populateDatabase(int count, int folderSpreadFactor = 0, bool clear = true, int offset = 0) |
55 | { | 55 | { |
56 | TestResource::removeFromDisk(resourceIdentifier); | 56 | if (clear) { |
57 | TestResource::removeFromDisk(resourceIdentifier); | ||
58 | } | ||
57 | 59 | ||
58 | Sink::ResourceContext resourceContext{resourceIdentifier, "test", {{"mail", QSharedPointer<TestMailAdaptorFactory>::create()}}}; | 60 | Sink::ResourceContext resourceContext{resourceIdentifier, "test", {{"mail", QSharedPointer<TestMailAdaptorFactory>::create()}}}; |
59 | Sink::Storage::EntityStore entityStore{resourceContext, {}}; | 61 | Sink::Storage::EntityStore entityStore{resourceContext, {}}; |
60 | entityStore.startTransaction(Sink::Storage::DataStore::ReadWrite); | 62 | entityStore.startTransaction(Sink::Storage::DataStore::ReadWrite); |
61 | 63 | ||
62 | const auto date = QDateTime::currentDateTimeUtc(); | 64 | const auto date = QDateTime::currentDateTimeUtc(); |
63 | for (int i = 0; i < count; i++) { | 65 | for (int i = offset; i < offset + count; i++) { |
64 | auto domainObject = Mail::createEntity<Mail>(resourceIdentifier); | 66 | auto domainObject = Mail::createEntity<Mail>(resourceIdentifier); |
65 | domainObject.setExtractedMessageId("uid"); | 67 | domainObject.setExtractedMessageId("uid"); |
66 | domainObject.setExtractedParentMessageId("parentuid"); | 68 | domainObject.setExtractedParentMessageId("parentuid"); |
@@ -85,7 +87,6 @@ class MailQueryBenchmark : public QObject | |||
85 | // Benchmark | 87 | // Benchmark |
86 | QTime time; | 88 | QTime time; |
87 | time.start(); | 89 | time.start(); |
88 | auto resultSet = QSharedPointer<Sink::ResultProvider<Mail::Ptr>>::create(); | ||
89 | 90 | ||
90 | //FIXME why do we need this here? | 91 | //FIXME why do we need this here? |
91 | auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); | 92 | auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); |
@@ -178,6 +179,56 @@ private slots: | |||
178 | populateDatabase(count, mailsPerFolder); | 179 | populateDatabase(count, mailsPerFolder); |
179 | testLoad("_threadleader", query, count, query.limit()); | 180 | testLoad("_threadleader", query, count, query.limit()); |
180 | } | 181 | } |
182 | |||
183 | void testIncremental() | ||
184 | { | ||
185 | Sink::Query query{Sink::Query::LiveQuery}; | ||
186 | query.request<Mail::MessageId>() | ||
187 | .request<Mail::Subject>() | ||
188 | .request<Mail::Date>(); | ||
189 | query.sort<ApplicationDomain::Mail::Date>(); | ||
190 | query.reduce<ApplicationDomain::Mail::Folder>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); | ||
191 | query.limit(1000); | ||
192 | |||
193 | int count = 1000; | ||
194 | populateDatabase(count, 10); | ||
195 | auto expectedSize = 100; | ||
196 | QTime time; | ||
197 | time.start(); | ||
198 | auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); | ||
199 | Sink::ResourceContext context{resourceIdentifier, "test", {{"mail", domainTypeAdaptorFactory}}}; | ||
200 | context.mResourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
201 | TestMailResourceFacade facade(context); | ||
202 | |||
203 | auto ret = facade.load(query, Sink::Log::Context{"benchmark"}); | ||
204 | ret.first.exec().waitForFinished(); | ||
205 | auto emitter = ret.second; | ||
206 | QList<Mail::Ptr> added; | ||
207 | QList<Mail::Ptr> removed; | ||
208 | QList<Mail::Ptr> modified; | ||
209 | emitter->onAdded([&](const Mail::Ptr &mail) { added << mail; /*qWarning() << "Added";*/ }); | ||
210 | emitter->onRemoved([&](const Mail::Ptr &mail) { removed << mail; /*qWarning() << "Removed";*/ }); | ||
211 | emitter->onModified([&](const Mail::Ptr &mail) { modified << mail; /*qWarning() << "Modified";*/ }); | ||
212 | bool done = false; | ||
213 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); | ||
214 | emitter->fetch(Mail::Ptr()); | ||
215 | QTRY_VERIFY(done); | ||
216 | QCOMPARE(added.size(), expectedSize); | ||
217 | |||
218 | std::cout << "Initial query took: " << time.elapsed() << std::endl; | ||
219 | |||
220 | populateDatabase(count, 10, false, count); | ||
221 | time.restart(); | ||
222 | context.mResourceAccess->revisionChanged(2000); | ||
223 | //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails | ||
224 | QTRY_COMPARE(added.count(), 200); | ||
225 | //For every email we have to redo the reduction and increase the count, which is a modification. | ||
226 | QTRY_COMPARE(modified.count(), 900); | ||
227 | std::cout << "Incremental query took " << time.elapsed() << std::endl; | ||
228 | std::cout << "added " << added.count() << std::endl; | ||
229 | std::cout << "modified " << modified.count() << std::endl; | ||
230 | std::cout << "removed " << removed.count() << std::endl; | ||
231 | } | ||
181 | }; | 232 | }; |
182 | 233 | ||
183 | QTEST_MAIN(MailQueryBenchmark) | 234 | QTEST_MAIN(MailQueryBenchmark) |
diff --git a/tests/testimplementations.h b/tests/testimplementations.h index ff9d9b8..c7f4ce0 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h | |||
@@ -71,6 +71,11 @@ public: | |||
71 | return KAsync::null<void>(); | 71 | return KAsync::null<void>(); |
72 | } | 72 | } |
73 | 73 | ||
74 | void revisionUpdate(qint64 rev) | ||
75 | { | ||
76 | emit revisionChanged(rev); | ||
77 | } | ||
78 | |||
74 | public slots: | 79 | public slots: |
75 | void open() Q_DECL_OVERRIDE | 80 | void open() Q_DECL_OVERRIDE |
76 | { | 81 | { |