diff options
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r-- | tests/storagetest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 5a517c7..7202628 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -451,6 +451,42 @@ private slots: | |||
451 | db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); | 451 | db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); |
452 | QCOMPARE(result, QByteArray("value2")); | 452 | QCOMPARE(result, QByteArray("value2")); |
453 | } | 453 | } |
454 | |||
455 | void testTransactionVisibility() | ||
456 | { | ||
457 | auto readValue = [](const Sink::Storage::DataStore::NamedDatabase &db, const QByteArray) { | ||
458 | QByteArray result; | ||
459 | db.scan("key1", [&](const QByteArray &, const QByteArray &value) { | ||
460 | result = value; | ||
461 | return true; | ||
462 | }); | ||
463 | return result; | ||
464 | }; | ||
465 | { | ||
466 | Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite); | ||
467 | auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite); | ||
468 | |||
469 | auto db = transaction.openDatabase("testTransactionVisibility", nullptr, false); | ||
470 | db.write("key1", "foo"); | ||
471 | QCOMPARE(readValue(db, "key1"), QByteArray("foo")); | ||
472 | |||
473 | { | ||
474 | auto transaction2 = store.createTransaction(Sink::Storage::DataStore::ReadOnly); | ||
475 | auto db2 = transaction2 | ||
476 | .openDatabase("testTransactionVisibility", nullptr, false); | ||
477 | QCOMPARE(readValue(db2, "key1"), QByteArray()); | ||
478 | } | ||
479 | transaction.commit(); | ||
480 | { | ||
481 | auto transaction2 = store.createTransaction(Sink::Storage::DataStore::ReadOnly); | ||
482 | auto db2 = transaction2 | ||
483 | .openDatabase("testTransactionVisibility", nullptr, false); | ||
484 | QCOMPARE(readValue(db2, "key1"), QByteArray("foo")); | ||
485 | } | ||
486 | |||
487 | } | ||
488 | } | ||
489 | |||
454 | }; | 490 | }; |
455 | 491 | ||
456 | QTEST_MAIN(StorageTest) | 492 | QTEST_MAIN(StorageTest) |