summaryrefslogtreecommitdiffstats
path: root/tests/pipelinetest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-10-28 16:39:16 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-10-28 16:39:16 +0100
commit129333371d28c06d85f75ca579ce17798e615e84 (patch)
tree2ae01db9d26f6f72a74fa77e6937e03304e81a2c /tests/pipelinetest.cpp
parent20f049b65c4bd8c3d0c16bbf398641675648a93f (diff)
downloadsink-129333371d28c06d85f75ca579ce17798e615e84.tar.gz
sink-129333371d28c06d85f75ca579ce17798e615e84.zip
Made pipeline preprocessing synchronous.
Instead of having the asynchronous preprocessor concept with different pipelines for new/modify/delete we have a single pipeline with synchronous preprocessors that act upon new/modify/delete. This keeps the code simpler due to lack of asynchronity and keeps the new/modify/delete operations together (which at least for the indexing makes a lot of sense). Not supporting asynchronity is ok because the tasks done in preprocessing are not cpu intensive (if they were we had a problem since they are directly involved in the round-trip time), and the main cost comes from i/o, meaning we don't gain much by doing multithreading. Costly tasks (such as full-text indexing) should rather be implemented as post-processing, since that doesn't increase the round-trip time directly, and eventually consistent is typically good enough for that.
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r--tests/pipelinetest.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index 7efba13..0b4c13e 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -139,6 +139,34 @@ QByteArray deleteEntityCommand(const QByteArray &uid, qint64 revision)
139 return command; 139 return command;
140} 140}
141 141
142class TestProcessor : public Akonadi2::Preprocessor {
143public:
144 void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE
145 {
146 newUids << uid;
147 newRevisions << revision;
148 }
149
150 void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE
151 {
152 modifiedUids << uid;
153 modifiedRevisions << revision;
154 }
155
156 void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE
157 {
158 deletedUids << uid;
159 deletedRevisions << revision;
160 }
161
162 QList<QByteArray> newUids;
163 QList<qint64> newRevisions;
164 QList<QByteArray> modifiedUids;
165 QList<qint64> modifiedRevisions;
166 QList<QByteArray> deletedUids;
167 QList<qint64> deletedRevisions;
168};
169
142/** 170/**
143 * Test of the pipeline implementation to ensure new revisions are created correctly in the database. 171 * Test of the pipeline implementation to ensure new revisions are created correctly in the database.
144 */ 172 */
@@ -251,6 +279,53 @@ private Q_SLOTS:
251 //And all revisions are gone 279 //And all revisions are gone
252 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0); 280 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0);
253 } 281 }
282
283 void testPreprocessor()
284 {
285 flatbuffers::FlatBufferBuilder entityFbb;
286
287 TestProcessor testProcessor;
288
289 Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1");
290 pipeline.setPreprocessors("event", QVector<Akonadi2::Preprocessor*>() << &testProcessor);
291 pipeline.startTransaction();
292 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
293
294 //Actual test
295 {
296 auto command = createEntityCommand(createEvent(entityFbb));
297 pipeline.newEntity(command.constData(), command.size());
298 QCOMPARE(testProcessor.newUids.size(), 1);
299 QCOMPARE(testProcessor.newRevisions.size(), 1);
300 //Key doesn't contain revision and is just the uid
301 QCOMPARE(testProcessor.newUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.newUids.at(0)));
302 }
303 pipeline.commit();
304 entityFbb.Clear();
305 pipeline.startTransaction();
306 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
307 QCOMPARE(keys.size(), 1);
308 const auto uid = Akonadi2::Storage::uidFromKey(keys.first());
309 {
310 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
311 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
312 QCOMPARE(testProcessor.modifiedUids.size(), 1);
313 QCOMPARE(testProcessor.modifiedRevisions.size(), 1);
314 //Key doesn't contain revision and is just the uid
315 QCOMPARE(testProcessor.modifiedUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.modifiedUids.at(0)));
316 }
317 pipeline.commit();
318 entityFbb.Clear();
319 pipeline.startTransaction();
320 {
321 auto deleteCommand = deleteEntityCommand(uid, 1);
322 pipeline.deletedEntity(deleteCommand.constData(), deleteCommand.size());
323 QCOMPARE(testProcessor.deletedUids.size(), 1);
324 QCOMPARE(testProcessor.deletedUids.size(), 1);
325 //Key doesn't contain revision and is just the uid
326 QCOMPARE(testProcessor.deletedUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.deletedUids.at(0)));
327 }
328 }
254}; 329};
255 330
256QTEST_MAIN(PipelineTest) 331QTEST_MAIN(PipelineTest)