summaryrefslogtreecommitdiffstats
path: root/tests/pipelinetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r--tests/pipelinetest.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index 92b7554..cdd260d 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -143,7 +143,8 @@ QByteArray deleteEntityCommand(const QByteArray &uid, qint64 revision)
143 return command; 143 return command;
144} 144}
145 145
146class TestProcessor : public Sink::Preprocessor { 146class TestProcessor : public Sink::Preprocessor
147{
147public: 148public:
148 void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 149 void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
149 { 150 {
@@ -151,7 +152,8 @@ public:
151 newRevisions << revision; 152 newRevisions << revision;
152 } 153 }
153 154
154 void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 155 void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity,
156 Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
155 { 157 {
156 modifiedUids << uid; 158 modifiedUids << uid;
157 modifiedRevisions << revision; 159 modifiedRevisions << revision;
@@ -214,42 +216,42 @@ private slots:
214 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); 216 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
215 pipeline.setAdaptorFactory("event", adaptorFactory); 217 pipeline.setAdaptorFactory("event", adaptorFactory);
216 218
217 //Create the initial revision 219 // Create the initial revision
218 pipeline.startTransaction(); 220 pipeline.startTransaction();
219 pipeline.newEntity(command.constData(), command.size()); 221 pipeline.newEntity(command.constData(), command.size());
220 pipeline.commit(); 222 pipeline.commit();
221 223
222 //Get uid of written entity 224 // Get uid of written entity
223 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); 225 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
224 QCOMPARE(keys.size(), 1); 226 QCOMPARE(keys.size(), 1);
225 const auto key = keys.first(); 227 const auto key = keys.first();
226 const auto uid = Sink::Storage::uidFromKey(key); 228 const auto uid = Sink::Storage::uidFromKey(key);
227 229
228 //Execute the modification 230 // Execute the modification
229 entityFbb.Clear(); 231 entityFbb.Clear();
230 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); 232 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
231 pipeline.startTransaction(); 233 pipeline.startTransaction();
232 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 234 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
233 pipeline.commit(); 235 pipeline.commit();
234 236
235 //Ensure we've got the new revision with the modification 237 // Ensure we've got the new revision with the modification
236 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 2)); 238 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 2));
237 QVERIFY(!buffer.isEmpty()); 239 QVERIFY(!buffer.isEmpty());
238 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 240 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
239 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 241 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
240 QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary2"), "The modification isn't applied."); 242 QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary2"), "The modification isn't applied.");
241 //Ensure we didn't modify anything else 243 // Ensure we didn't modify anything else
242 QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects."); 244 QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects.");
243 245
244 //Both revisions are in the store at this point 246 // Both revisions are in the store at this point
245 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); 247 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2);
246 248
247 //Cleanup old revisions 249 // Cleanup old revisions
248 pipeline.startTransaction(); 250 pipeline.startTransaction();
249 pipeline.cleanupRevision(2); 251 pipeline.cleanupRevision(2);
250 pipeline.commit(); 252 pipeline.commit();
251 253
252 //And now only the latest revision is left 254 // And now only the latest revision is left
253 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 1); 255 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 1);
254 } 256 }
255 257
@@ -263,18 +265,18 @@ private slots:
263 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); 265 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
264 pipeline.setAdaptorFactory("event", adaptorFactory); 266 pipeline.setAdaptorFactory("event", adaptorFactory);
265 267
266 //Create the initial revision 268 // Create the initial revision
267 pipeline.startTransaction(); 269 pipeline.startTransaction();
268 pipeline.newEntity(command.constData(), command.size()); 270 pipeline.newEntity(command.constData(), command.size());
269 pipeline.commit(); 271 pipeline.commit();
270 272
271 //Get uid of written entity 273 // Get uid of written entity
272 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); 274 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
273 QCOMPARE(keys.size(), 1); 275 QCOMPARE(keys.size(), 1);
274 const auto uid = Sink::Storage::uidFromKey(keys.first()); 276 const auto uid = Sink::Storage::uidFromKey(keys.first());
275 277
276 278
277 //Create another operation inbetween 279 // Create another operation inbetween
278 { 280 {
279 entityFbb.Clear(); 281 entityFbb.Clear();
280 auto command = createEntityCommand(createEvent(entityFbb)); 282 auto command = createEntityCommand(createEvent(entityFbb));
@@ -283,14 +285,14 @@ private slots:
283 pipeline.commit(); 285 pipeline.commit();
284 } 286 }
285 287
286 //Execute the modification on revision 2 288 // Execute the modification on revision 2
287 entityFbb.Clear(); 289 entityFbb.Clear();
288 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 2); 290 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 2);
289 pipeline.startTransaction(); 291 pipeline.startTransaction();
290 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 292 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
291 pipeline.commit(); 293 pipeline.commit();
292 294
293 //Ensure we've got the new revision with the modification 295 // Ensure we've got the new revision with the modification
294 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 3)); 296 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 3));
295 QVERIFY(!buffer.isEmpty()); 297 QVERIFY(!buffer.isEmpty());
296 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 298 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
@@ -305,7 +307,7 @@ private slots:
305 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); 307 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1");
306 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create()); 308 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
307 309
308 //Create the initial revision 310 // Create the initial revision
309 pipeline.startTransaction(); 311 pipeline.startTransaction();
310 pipeline.newEntity(command.constData(), command.size()); 312 pipeline.newEntity(command.constData(), command.size());
311 pipeline.commit(); 313 pipeline.commit();
@@ -315,21 +317,21 @@ private slots:
315 317
316 const auto uid = Sink::Storage::uidFromKey(result.first()); 318 const auto uid = Sink::Storage::uidFromKey(result.first());
317 319
318 //Delete entity 320 // Delete entity
319 auto deleteCommand = deleteEntityCommand(uid, 1); 321 auto deleteCommand = deleteEntityCommand(uid, 1);
320 pipeline.startTransaction(); 322 pipeline.startTransaction();
321 pipeline.deletedEntity(deleteCommand.constData(), deleteCommand.size()); 323 pipeline.deletedEntity(deleteCommand.constData(), deleteCommand.size());
322 pipeline.commit(); 324 pipeline.commit();
323 325
324 //We have a new revision that indicates the deletion 326 // We have a new revision that indicates the deletion
325 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); 327 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2);
326 328
327 //Cleanup old revisions 329 // Cleanup old revisions
328 pipeline.startTransaction(); 330 pipeline.startTransaction();
329 pipeline.cleanupRevision(2); 331 pipeline.cleanupRevision(2);
330 pipeline.commit(); 332 pipeline.commit();
331 333
332 //And all revisions are gone 334 // And all revisions are gone
333 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0); 335 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0);
334 } 336 }
335 337
@@ -340,17 +342,17 @@ private slots:
340 TestProcessor testProcessor; 342 TestProcessor testProcessor;
341 343
342 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); 344 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1");
343 pipeline.setPreprocessors("event", QVector<Sink::Preprocessor*>() << &testProcessor); 345 pipeline.setPreprocessors("event", QVector<Sink::Preprocessor *>() << &testProcessor);
344 pipeline.startTransaction(); 346 pipeline.startTransaction();
345 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create()); 347 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
346 348
347 //Actual test 349 // Actual test
348 { 350 {
349 auto command = createEntityCommand(createEvent(entityFbb)); 351 auto command = createEntityCommand(createEvent(entityFbb));
350 pipeline.newEntity(command.constData(), command.size()); 352 pipeline.newEntity(command.constData(), command.size());
351 QCOMPARE(testProcessor.newUids.size(), 1); 353 QCOMPARE(testProcessor.newUids.size(), 1);
352 QCOMPARE(testProcessor.newRevisions.size(), 1); 354 QCOMPARE(testProcessor.newRevisions.size(), 1);
353 //Key doesn't contain revision and is just the uid 355 // Key doesn't contain revision and is just the uid
354 QCOMPARE(testProcessor.newUids.at(0), Sink::Storage::uidFromKey(testProcessor.newUids.at(0))); 356 QCOMPARE(testProcessor.newUids.at(0), Sink::Storage::uidFromKey(testProcessor.newUids.at(0)));
355 } 357 }
356 pipeline.commit(); 358 pipeline.commit();
@@ -364,7 +366,7 @@ private slots:
364 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 366 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
365 QCOMPARE(testProcessor.modifiedUids.size(), 1); 367 QCOMPARE(testProcessor.modifiedUids.size(), 1);
366 QCOMPARE(testProcessor.modifiedRevisions.size(), 1); 368 QCOMPARE(testProcessor.modifiedRevisions.size(), 1);
367 //Key doesn't contain revision and is just the uid 369 // Key doesn't contain revision and is just the uid
368 QCOMPARE(testProcessor.modifiedUids.at(0), Sink::Storage::uidFromKey(testProcessor.modifiedUids.at(0))); 370 QCOMPARE(testProcessor.modifiedUids.at(0), Sink::Storage::uidFromKey(testProcessor.modifiedUids.at(0)));
369 } 371 }
370 pipeline.commit(); 372 pipeline.commit();
@@ -376,7 +378,7 @@ private slots:
376 QCOMPARE(testProcessor.deletedUids.size(), 1); 378 QCOMPARE(testProcessor.deletedUids.size(), 1);
377 QCOMPARE(testProcessor.deletedUids.size(), 1); 379 QCOMPARE(testProcessor.deletedUids.size(), 1);
378 QCOMPARE(testProcessor.deletedSummaries.size(), 1); 380 QCOMPARE(testProcessor.deletedSummaries.size(), 1);
379 //Key doesn't contain revision and is just the uid 381 // Key doesn't contain revision and is just the uid
380 QCOMPARE(testProcessor.deletedUids.at(0), Sink::Storage::uidFromKey(testProcessor.deletedUids.at(0))); 382 QCOMPARE(testProcessor.deletedUids.at(0), Sink::Storage::uidFromKey(testProcessor.deletedUids.at(0)));
381 QCOMPARE(testProcessor.deletedSummaries.at(0), QByteArray("summary2")); 383 QCOMPARE(testProcessor.deletedSummaries.at(0), QByteArray("summary2"));
382 } 384 }