summaryrefslogtreecommitdiffstats
path: root/tests/pipelinetest.cpp
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-07-27 13:32:39 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-27 13:47:43 +0200
commitd1838e575baeb6cd08011645609516acbdabd6c8 (patch)
tree035b99a4d324231c8c44e0e97905383266bacba6 /tests/pipelinetest.cpp
parent1855b8356e4c427efdba4c932fa9f984e6ae5a43 (diff)
downloadsink-d1838e575baeb6cd08011645609516acbdabd6c8.tar.gz
sink-d1838e575baeb6cd08011645609516acbdabd6c8.zip
New Key API in storage layer
Summary: - Use object oriented paradigm for Keys / Identifiers /Revisions - "Compress" keys by using byte representation of Uuids - Still some cleaning left to do - Also run some benchmarks - I'm questioning whether files other than entitystore (tests excluded) are allowed to access this API Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D13735
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r--tests/pipelinetest.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index 45e2fbb..b41a5c2 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -20,6 +20,7 @@
20#include "domainadaptor.h" 20#include "domainadaptor.h"
21#include "definitions.h" 21#include "definitions.h"
22#include "adaptorfactoryregistry.h" 22#include "adaptorfactoryregistry.h"
23#include "storage/key.h"
23 24
24static void removeFromDisk(const QString &name) 25static void removeFromDisk(const QString &name)
25{ 26{
@@ -250,8 +251,8 @@ private slots:
250 // Get uid of written entity 251 // Get uid of written entity
251 auto keys = getKeys(instanceIdentifier(), "event.main"); 252 auto keys = getKeys(instanceIdentifier(), "event.main");
252 QCOMPARE(keys.size(), 1); 253 QCOMPARE(keys.size(), 1);
253 const auto key = keys.first(); 254 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first());
254 const auto uid = Sink::Storage::DataStore::uidFromKey(key); 255 const auto uid = key.identifier().toDisplayByteArray();
255 256
256 // Execute the modification 257 // Execute the modification
257 entityFbb.Clear(); 258 entityFbb.Clear();
@@ -260,8 +261,10 @@ private slots:
260 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 261 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
261 pipeline.commit(); 262 pipeline.commit();
262 263
264 key.setRevision(2);
265
263 // Ensure we've got the new revision with the modification 266 // Ensure we've got the new revision with the modification
264 auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 2)); 267 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray());
265 QVERIFY(!buffer.isEmpty()); 268 QVERIFY(!buffer.isEmpty());
266 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 269 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
267 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 270 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
@@ -296,7 +299,8 @@ private slots:
296 // Get uid of written entity 299 // Get uid of written entity
297 auto keys = getKeys(instanceIdentifier(), "event.main"); 300 auto keys = getKeys(instanceIdentifier(), "event.main");
298 QCOMPARE(keys.size(), 1); 301 QCOMPARE(keys.size(), 1);
299 const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); 302 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first());
303 const auto uid = key.identifier().toDisplayByteArray();
300 304
301 305
302 // Create another operation inbetween 306 // Create another operation inbetween
@@ -315,8 +319,10 @@ private slots:
315 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 319 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
316 pipeline.commit(); 320 pipeline.commit();
317 321
322 key.setRevision(3);
323
318 // Ensure we've got the new revision with the modification 324 // Ensure we've got the new revision with the modification
319 auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); 325 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray());
320 QVERIFY(!buffer.isEmpty()); 326 QVERIFY(!buffer.isEmpty());
321 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 327 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
322 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 328 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
@@ -337,7 +343,7 @@ private slots:
337 auto result = getKeys(instanceIdentifier(), "event.main"); 343 auto result = getKeys(instanceIdentifier(), "event.main");
338 QCOMPARE(result.size(), 1); 344 QCOMPARE(result.size(), 1);
339 345
340 const auto uid = Sink::Storage::DataStore::uidFromKey(result.first()); 346 const auto uid = Sink::Storage::Key::fromInternalByteArray(result.first()).identifier().toDisplayByteArray();
341 347
342 // Delete entity 348 // Delete entity
343 auto deleteCommand = deleteEntityCommand(uid, 1); 349 auto deleteCommand = deleteEntityCommand(uid, 1);
@@ -372,22 +378,22 @@ private slots:
372 pipeline.newEntity(command.constData(), command.size()); 378 pipeline.newEntity(command.constData(), command.size());
373 QCOMPARE(testProcessor->newUids.size(), 1); 379 QCOMPARE(testProcessor->newUids.size(), 1);
374 QCOMPARE(testProcessor->newRevisions.size(), 1); 380 QCOMPARE(testProcessor->newRevisions.size(), 1);
375 // Key doesn't contain revision and is just the uid 381 const auto uid = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->newUids.at(0)).toDisplayByteArray();
376 QCOMPARE(testProcessor->newUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->newUids.at(0))); 382 QCOMPARE(testProcessor->newUids.at(0), uid);
377 } 383 }
378 pipeline.commit(); 384 pipeline.commit();
379 entityFbb.Clear(); 385 entityFbb.Clear();
380 pipeline.startTransaction(); 386 pipeline.startTransaction();
381 auto keys = getKeys(instanceIdentifier(), "event.main"); 387 auto keys = getKeys(instanceIdentifier(), "event.main");
382 QCOMPARE(keys.size(), 1); 388 QCOMPARE(keys.size(), 1);
383 const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); 389 const auto uid = Sink::Storage::Key::fromInternalByteArray(keys.first()).identifier().toDisplayByteArray();
384 { 390 {
385 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); 391 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
386 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 392 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
387 QCOMPARE(testProcessor->modifiedUids.size(), 1); 393 QCOMPARE(testProcessor->modifiedUids.size(), 1);
388 QCOMPARE(testProcessor->modifiedRevisions.size(), 1); 394 QCOMPARE(testProcessor->modifiedRevisions.size(), 1);
389 // Key doesn't contain revision and is just the uid 395 const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray();
390 QCOMPARE(testProcessor->modifiedUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->modifiedUids.at(0))); 396 QCOMPARE(testProcessor->modifiedUids.at(0), uid2);
391 } 397 }
392 pipeline.commit(); 398 pipeline.commit();
393 entityFbb.Clear(); 399 entityFbb.Clear();
@@ -398,8 +404,8 @@ private slots:
398 QCOMPARE(testProcessor->deletedUids.size(), 1); 404 QCOMPARE(testProcessor->deletedUids.size(), 1);
399 QCOMPARE(testProcessor->deletedUids.size(), 1); 405 QCOMPARE(testProcessor->deletedUids.size(), 1);
400 QCOMPARE(testProcessor->deletedSummaries.size(), 1); 406 QCOMPARE(testProcessor->deletedSummaries.size(), 1);
401 // Key doesn't contain revision and is just the uid 407 const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray();
402 QCOMPARE(testProcessor->deletedUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->deletedUids.at(0))); 408 QCOMPARE(testProcessor->deletedUids.at(0), uid2);
403 QCOMPARE(testProcessor->deletedSummaries.at(0), QByteArray("summary2")); 409 QCOMPARE(testProcessor->deletedSummaries.at(0), QByteArray("summary2"));
404 } 410 }
405 } 411 }
@@ -421,8 +427,8 @@ private slots:
421 // Get uid of written entity 427 // Get uid of written entity
422 auto keys = getKeys(instanceIdentifier(), "event.main"); 428 auto keys = getKeys(instanceIdentifier(), "event.main");
423 QCOMPARE(keys.size(), 1); 429 QCOMPARE(keys.size(), 1);
424 const auto key = keys.first(); 430 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first());
425 const auto uid = Sink::Storage::DataStore::uidFromKey(key); 431 const auto uid = key.identifier().toDisplayByteArray();
426 432
427 //Simulate local modification 433 //Simulate local modification
428 { 434 {
@@ -444,8 +450,10 @@ private slots:
444 pipeline.commit(); 450 pipeline.commit();
445 } 451 }
446 452
453 key.setRevision(3);
454
447 // Ensure we've got the new revision with the modification 455 // Ensure we've got the new revision with the modification
448 auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); 456 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray());
449 QVERIFY(!buffer.isEmpty()); 457 QVERIFY(!buffer.isEmpty());
450 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 458 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
451 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 459 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());