Changeset View
Changeset View
Standalone View
Standalone View
tests/pipelinetest.cpp
Context not available. | |||||
28 | store.removeFromDisk(); | 28 | store.removeFromDisk(); | ||
---|---|---|---|---|---|
29 | } | 29 | } | ||
30 | 30 | | |||
31 | static QList<QByteArray> getKeys(const QByteArray &dbEnv, const QByteArray &name) | 31 | static 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, Sink::Storage::IntegerKeys); | ||
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 = Sink::byteArrayToSizeT(key); | ||
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 | | |||
44 | static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, const QByteArray &uid) | 47 | static 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, Sink::Storage::IntegerKeys); | ||
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 | }); | ||
Context not available. | |||||
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 | ||
Context not available. | |||||
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()); | ||
Context not available. | |||||
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 | | |||
Context not available. | |||||
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()); | ||
Context not available. | |||||
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); | ||
Context not available. | |||||
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()); | ||
Context not available. | |||||
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 | ||
Context not available. | |||||
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()); | ||
Context not available. |