summaryrefslogtreecommitdiffstats
path: root/tests/pipelinetest.cpp
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-08-21 12:03:40 +0200
committerMinijackson <minijackson@riseup.net>2018-08-21 14:04:56 +0200
commit23e13c91e44e9d1fcbe2215f16d10117de4d0e84 (patch)
tree6e341ca4bcb94499a9b9631b7b3499a691d30b79 /tests/pipelinetest.cpp
parent40fbc56ba745322ed75ac12c5551ce6b9bcb1cc4 (diff)
downloadsink-23e13c91e44e9d1fcbe2215f16d10117de4d0e84.tar.gz
sink-23e13c91e44e9d1fcbe2215f16d10117de4d0e84.zip
Separate UIDs and revisions
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r--tests/pipelinetest.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index b41a5c2..47d443f 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -28,26 +28,29 @@ static void removeFromDisk(const QString &name)
28 store.removeFromDisk(); 28 store.removeFromDisk();
29} 29}
30 30
31static QList<QByteArray> getKeys(const QByteArray &dbEnv, const QByteArray &name) 31static QList<Sink::Storage::Key> getKeys(const QByteArray &dbEnv, const QByteArray &name)
32{ 32{
33 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly); 33 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly);
34 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); 34 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
35 auto db = transaction.openDatabase(name, nullptr, false); 35 auto db = transaction.openDatabase(name, nullptr, false);
36 QList<QByteArray> result; 36 QList<Sink::Storage::Key> result;
37 db.scan("", [&](const QByteArray &key, const QByteArray &value) { 37 db.scan("", [&](const QByteArray &key, const QByteArray &value) {
38 result << key; 38 size_t revision = *reinterpret_cast<const char *>(key.constData());
39 result << Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(
40 Sink::Storage::DataStore::getUidFromRevision(transaction, revision)),
41 revision);
39 return true; 42 return true;
40 }); 43 });
41 return result; 44 return result;
42} 45}
43 46
44static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, const QByteArray &uid) 47static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, const Sink::Storage::Key &key)
45{ 48{
46 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly); 49 Sink::Storage::DataStore store(Sink::storageLocation(), dbEnv, Sink::Storage::DataStore::ReadOnly);
47 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly); 50 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
48 auto db = transaction.openDatabase(name, nullptr, false); 51 auto db = transaction.openDatabase(name, nullptr, false);
49 QByteArray result; 52 QByteArray result;
50 db.scan(uid, [&](const QByteArray &key, const QByteArray &value) { 53 db.scan(key.revision().toSizeT(), [&](size_t rev, const QByteArray &value) {
51 result = value; 54 result = value;
52 return true; 55 return true;
53 }); 56 });
@@ -251,7 +254,7 @@ private slots:
251 // Get uid of written entity 254 // Get uid of written entity
252 auto keys = getKeys(instanceIdentifier(), "event.main"); 255 auto keys = getKeys(instanceIdentifier(), "event.main");
253 QCOMPARE(keys.size(), 1); 256 QCOMPARE(keys.size(), 1);
254 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); 257 auto key = keys.first();
255 const auto uid = key.identifier().toDisplayByteArray(); 258 const auto uid = key.identifier().toDisplayByteArray();
256 259
257 // Execute the modification 260 // Execute the modification
@@ -264,7 +267,7 @@ private slots:
264 key.setRevision(2); 267 key.setRevision(2);
265 268
266 // Ensure we've got the new revision with the modification 269 // Ensure we've got the new revision with the modification
267 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); 270 auto buffer = getEntity(instanceIdentifier(), "event.main", key);
268 QVERIFY(!buffer.isEmpty()); 271 QVERIFY(!buffer.isEmpty());
269 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 272 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
270 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 273 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
@@ -299,7 +302,7 @@ private slots:
299 // Get uid of written entity 302 // Get uid of written entity
300 auto keys = getKeys(instanceIdentifier(), "event.main"); 303 auto keys = getKeys(instanceIdentifier(), "event.main");
301 QCOMPARE(keys.size(), 1); 304 QCOMPARE(keys.size(), 1);
302 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); 305 auto key = keys.first();
303 const auto uid = key.identifier().toDisplayByteArray(); 306 const auto uid = key.identifier().toDisplayByteArray();
304 307
305 308
@@ -322,7 +325,7 @@ private slots:
322 key.setRevision(3); 325 key.setRevision(3);
323 326
324 // Ensure we've got the new revision with the modification 327 // Ensure we've got the new revision with the modification
325 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); 328 auto buffer = getEntity(instanceIdentifier(), "event.main", key);
326 QVERIFY(!buffer.isEmpty()); 329 QVERIFY(!buffer.isEmpty());
327 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 330 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
328 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 331 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
@@ -343,7 +346,7 @@ private slots:
343 auto result = getKeys(instanceIdentifier(), "event.main"); 346 auto result = getKeys(instanceIdentifier(), "event.main");
344 QCOMPARE(result.size(), 1); 347 QCOMPARE(result.size(), 1);
345 348
346 const auto uid = Sink::Storage::Key::fromInternalByteArray(result.first()).identifier().toDisplayByteArray(); 349 const auto uid = result.first().identifier().toDisplayByteArray();
347 350
348 // Delete entity 351 // Delete entity
349 auto deleteCommand = deleteEntityCommand(uid, 1); 352 auto deleteCommand = deleteEntityCommand(uid, 1);
@@ -386,7 +389,7 @@ private slots:
386 pipeline.startTransaction(); 389 pipeline.startTransaction();
387 auto keys = getKeys(instanceIdentifier(), "event.main"); 390 auto keys = getKeys(instanceIdentifier(), "event.main");
388 QCOMPARE(keys.size(), 1); 391 QCOMPARE(keys.size(), 1);
389 const auto uid = Sink::Storage::Key::fromInternalByteArray(keys.first()).identifier().toDisplayByteArray(); 392 const auto uid = keys.first().identifier().toDisplayByteArray();
390 { 393 {
391 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); 394 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
392 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 395 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
@@ -427,7 +430,7 @@ private slots:
427 // Get uid of written entity 430 // Get uid of written entity
428 auto keys = getKeys(instanceIdentifier(), "event.main"); 431 auto keys = getKeys(instanceIdentifier(), "event.main");
429 QCOMPARE(keys.size(), 1); 432 QCOMPARE(keys.size(), 1);
430 auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); 433 auto key = keys.first();
431 const auto uid = key.identifier().toDisplayByteArray(); 434 const auto uid = key.identifier().toDisplayByteArray();
432 435
433 //Simulate local modification 436 //Simulate local modification
@@ -453,7 +456,7 @@ private slots:
453 key.setRevision(3); 456 key.setRevision(3);
454 457
455 // Ensure we've got the new revision with the modification 458 // Ensure we've got the new revision with the modification
456 auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); 459 auto buffer = getEntity(instanceIdentifier(), "event.main", key);
457 QVERIFY(!buffer.isEmpty()); 460 QVERIFY(!buffer.isEmpty());
458 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 461 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
459 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 462 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());