summaryrefslogtreecommitdiffstats
path: root/tests/storagetest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r--tests/storagetest.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index bca91b1..f4cf400 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -275,8 +275,56 @@ private slots:
275 { 275 {
276 bool gotResult = false; 276 bool gotResult = false;
277 bool gotError = false; 277 bool gotError = false;
278 Sink::Storage::DataStore store(testDataPath, {dbName, {{"test", 0}}}, Sink::Storage::DataStore::ReadOnly);
279 QVERIFY(!store.exists());
280 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
281 Sink::Storage::DataStore::getUids("test", transaction, [&](const QByteArray &uid) {});
282 int numValues = transaction
283 .openDatabase("test")
284 .scan("",
285 [&](const QByteArray &key, const QByteArray &value) -> bool {
286 gotResult = true;
287 return false;
288 },
289 [&](const Sink::Storage::DataStore::Error &error) {
290 qDebug() << error.message;
291 gotError = true;
292 });
293 QCOMPARE(numValues, 0);
294 QVERIFY(!gotResult);
295 QVERIFY(!gotError);
296 }
297
298 /*
299 * This scenario tests a very specific pattern that can appear with new named databases.
300 * * A read-only transaction is opened
301 * * A write-transaction creates a new named db.
302 * * We try to access that named-db from the already open transaction.
303 */
304 void testNewDbInOpenTransaction()
305 {
306 //Create env, otherwise we don't even get a transaction
307 {
308 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite);
309 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite);
310 }
311 //Open a longlived transaction
278 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly); 312 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadOnly);
279 int numValues = store.createTransaction(Sink::Storage::DataStore::ReadOnly) 313 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadOnly);
314
315 //Create the named database
316 {
317 Sink::Storage::DataStore store(testDataPath, dbName, Sink::Storage::DataStore::ReadWrite);
318 auto transaction = store.createTransaction(Sink::Storage::DataStore::ReadWrite);
319 transaction.openDatabase("test");
320 transaction.commit();
321 }
322
323
324 //Try to access the named database in the existing transaction. Opening should fail.
325 bool gotResult = false;
326 bool gotError = false;
327 int numValues = transaction
280 .openDatabase("test") 328 .openDatabase("test")
281 .scan("", 329 .scan("",
282 [&](const QByteArray &key, const QByteArray &value) -> bool { 330 [&](const QByteArray &key, const QByteArray &value) -> bool {