summaryrefslogtreecommitdiffstats
path: root/tests/pipelinetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r--tests/pipelinetest.cpp128
1 files changed, 126 insertions, 2 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index 7efba13..47090a8 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -139,6 +139,36 @@ 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 deletedSummaries << oldEntity.getProperty("summary").toByteArray();
161 }
162
163 QList<QByteArray> newUids;
164 QList<qint64> newRevisions;
165 QList<QByteArray> modifiedUids;
166 QList<qint64> modifiedRevisions;
167 QList<QByteArray> deletedUids;
168 QList<qint64> deletedRevisions;
169 QList<QByteArray> deletedSummaries;
170};
171
142/** 172/**
143 * Test of the pipeline implementation to ensure new revisions are created correctly in the database. 173 * Test of the pipeline implementation to ensure new revisions are created correctly in the database.
144 */ 174 */
@@ -217,18 +247,63 @@ private Q_SLOTS:
217 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 1); 247 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 1);
218 } 248 }
219 249
220 void testDelete() 250 void testModifyWithUnrelatedOperationInbetween()
221 { 251 {
222 flatbuffers::FlatBufferBuilder entityFbb; 252 flatbuffers::FlatBufferBuilder entityFbb;
223 auto command = createEntityCommand(createEvent(entityFbb)); 253 auto command = createEntityCommand(createEvent(entityFbb));
224 254
255 Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1");
256
257 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
258 pipeline.setAdaptorFactory("event", adaptorFactory);
259
225 //Create the initial revision 260 //Create the initial revision
261 pipeline.startTransaction();
262 pipeline.newEntity(command.constData(), command.size());
263 pipeline.commit();
264
265 //Get uid of written entity
266 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
267 QCOMPARE(keys.size(), 1);
268 const auto uid = Akonadi2::Storage::uidFromKey(keys.first());
269
270
271 //Create another operation inbetween
272 {
273 entityFbb.Clear();
274 auto command = createEntityCommand(createEvent(entityFbb));
275 pipeline.startTransaction();
276 pipeline.newEntity(command.constData(), command.size());
277 pipeline.commit();
278 }
279
280 //Execute the modification on revision 2
281 entityFbb.Clear();
282 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 2);
283 pipeline.startTransaction();
284 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
285 pipeline.commit();
286
287 //Ensure we've got the new revision with the modification
288 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Akonadi2::Storage::assembleKey(uid, 3));
289 QVERIFY(!buffer.isEmpty());
290 Akonadi2::EntityBuffer entityBuffer(buffer.data(), buffer.size());
291 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
292 QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary2"));
293 }
294
295 void testDelete()
296 {
297 flatbuffers::FlatBufferBuilder entityFbb;
298 auto command = createEntityCommand(createEvent(entityFbb));
226 Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1"); 299 Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1");
300 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
301
302 //Create the initial revision
227 pipeline.startTransaction(); 303 pipeline.startTransaction();
228 pipeline.newEntity(command.constData(), command.size()); 304 pipeline.newEntity(command.constData(), command.size());
229 pipeline.commit(); 305 pipeline.commit();
230 306
231 // const auto uid = Akonadi2::Storage::uidFromKey(key);
232 auto result = getKeys("org.kde.pipelinetest.instance1", "event.main"); 307 auto result = getKeys("org.kde.pipelinetest.instance1", "event.main");
233 QCOMPARE(result.size(), 1); 308 QCOMPARE(result.size(), 1);
234 309
@@ -251,6 +326,55 @@ private Q_SLOTS:
251 //And all revisions are gone 326 //And all revisions are gone
252 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0); 327 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0);
253 } 328 }
329
330 void testPreprocessor()
331 {
332 flatbuffers::FlatBufferBuilder entityFbb;
333
334 TestProcessor testProcessor;
335
336 Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1");
337 pipeline.setPreprocessors("event", QVector<Akonadi2::Preprocessor*>() << &testProcessor);
338 pipeline.startTransaction();
339 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
340
341 //Actual test
342 {
343 auto command = createEntityCommand(createEvent(entityFbb));
344 pipeline.newEntity(command.constData(), command.size());
345 QCOMPARE(testProcessor.newUids.size(), 1);
346 QCOMPARE(testProcessor.newRevisions.size(), 1);
347 //Key doesn't contain revision and is just the uid
348 QCOMPARE(testProcessor.newUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.newUids.at(0)));
349 }
350 pipeline.commit();
351 entityFbb.Clear();
352 pipeline.startTransaction();
353 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
354 QCOMPARE(keys.size(), 1);
355 const auto uid = Akonadi2::Storage::uidFromKey(keys.first());
356 {
357 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
358 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
359 QCOMPARE(testProcessor.modifiedUids.size(), 1);
360 QCOMPARE(testProcessor.modifiedRevisions.size(), 1);
361 //Key doesn't contain revision and is just the uid
362 QCOMPARE(testProcessor.modifiedUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.modifiedUids.at(0)));
363 }
364 pipeline.commit();
365 entityFbb.Clear();
366 pipeline.startTransaction();
367 {
368 auto deleteCommand = deleteEntityCommand(uid, 1);
369 pipeline.deletedEntity(deleteCommand.constData(), deleteCommand.size());
370 QCOMPARE(testProcessor.deletedUids.size(), 1);
371 QCOMPARE(testProcessor.deletedUids.size(), 1);
372 QCOMPARE(testProcessor.deletedSummaries.size(), 1);
373 //Key doesn't contain revision and is just the uid
374 QCOMPARE(testProcessor.deletedUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.deletedUids.at(0)));
375 QCOMPARE(testProcessor.deletedSummaries.at(0), QByteArray("summary2"));
376 }
377 }
254}; 378};
255 379
256QTEST_MAIN(PipelineTest) 380QTEST_MAIN(PipelineTest)