summaryrefslogtreecommitdiffstats
path: root/tests/storagetest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-09 23:17:42 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-09 23:17:42 +0200
commita8263a28f5d3a74581e289289d0807e6b656104b (patch)
tree66d3033df141b0a73d1b89b8345dbcad7ba6eb7f /tests/storagetest.cpp
parentb6e7be78f3e13275a8f217a4e01b304d97538641 (diff)
downloadsink-a8263a28f5d3a74581e289289d0807e6b656104b.tar.gz
sink-a8263a28f5d3a74581e289289d0807e6b656104b.zip
Transaction class for storage
The beginning of a cleaner and less bare-bones API for the storage. The lifetime of transactions is now handled in (movable) transaction objects.
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r--tests/storagetest.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index b088670..b71a767 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -20,17 +20,18 @@ private:
20 void populate(int count) 20 void populate(int count)
21 { 21 {
22 Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 22 Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite);
23 auto transaction = storage.createTransaction(Akonadi2::Storage::ReadWrite);
23 for (int i = 0; i < count; i++) { 24 for (int i = 0; i < count; i++) {
24 //This should perhaps become an implementation detail of the db? 25 //This should perhaps become an implementation detail of the db?
25 if (i % 10000 == 0) { 26 if (i % 10000 == 0) {
26 if (i > 0) { 27 if (i > 0) {
27 storage.commitTransaction(); 28 transaction.commit();
29 transaction = std::move(storage.createTransaction(Akonadi2::Storage::ReadWrite));
28 } 30 }
29 storage.startTransaction();
30 } 31 }
31 storage.write(keyPrefix + QByteArray::number(i), keyPrefix + QByteArray::number(i)); 32 transaction.write(keyPrefix + QByteArray::number(i), keyPrefix + QByteArray::number(i));
32 } 33 }
33 storage.commitTransaction(); 34 transaction.commit();
34 } 35 }
35 36
36 bool verify(Akonadi2::Storage &storage, int i) 37 bool verify(Akonadi2::Storage &storage, int i)
@@ -38,8 +39,8 @@ private:
38 bool success = true; 39 bool success = true;
39 bool keyMatch = true; 40 bool keyMatch = true;
40 const auto reference = keyPrefix + QByteArray::number(i); 41 const auto reference = keyPrefix + QByteArray::number(i);
41 storage.scan(keyPrefix + QByteArray::number(i), 42 storage.createTransaction(Akonadi2::Storage::ReadOnly).scan(keyPrefix + QByteArray::number(i),
42 [&keyMatch, &reference](const QByteArray &value) -> bool { 43 [&keyMatch, &reference](const QByteArray &key, const QByteArray &value) -> bool {
43 if (value != reference) { 44 if (value != reference) {
44 qDebug() << "Mismatch while reading"; 45 qDebug() << "Mismatch while reading";
45 keyMatch = false; 46 keyMatch = false;
@@ -102,8 +103,8 @@ private Q_SLOTS:
102 { 103 {
103 int hit = 0; 104 int hit = 0;
104 Akonadi2::Storage store(testDataPath, dbName); 105 Akonadi2::Storage store(testDataPath, dbName);
105 store.scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { 106 store.createTransaction(Akonadi2::Storage::ReadOnly).scan("", [&](const QByteArray &key, const QByteArray &value) -> bool {
106 if (std::string(static_cast<char*>(keyValue), keySize) == "key50") { 107 if (key == "key50") {
107 hit++; 108 hit++;
108 } 109 }
109 return true; 110 return true;
@@ -116,8 +117,8 @@ private Q_SLOTS:
116 int hit = 0; 117 int hit = 0;
117 bool foundInvalidValue = false; 118 bool foundInvalidValue = false;
118 Akonadi2::Storage store(testDataPath, dbName); 119 Akonadi2::Storage store(testDataPath, dbName);
119 store.scan("key50", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { 120 store.createTransaction(Akonadi2::Storage::ReadOnly).scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool {
120 if (std::string(static_cast<char*>(keyValue), keySize) != "key50") { 121 if (key != "key50") {
121 foundInvalidValue = true; 122 foundInvalidValue = true;
122 } 123 }
123 hit++; 124 hit++;
@@ -128,12 +129,13 @@ private Q_SLOTS:
128 } 129 }
129 } 130 }
130 131
131 void testTurnReadToWrite() 132 void testNestedOperations()
132 { 133 {
133 populate(3); 134 populate(3);
134 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 135 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite);
135 store.scan("key1", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { 136 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite);
136 store.remove(QByteArray::fromRawData(static_cast<const char*>(keyValue), keySize), [](const Akonadi2::Storage::Error &) { 137 transaction.scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool {
138 transaction.remove(key, [](const Akonadi2::Storage::Error &) {
137 QVERIFY(false); 139 QVERIFY(false);
138 }); 140 });
139 return false; 141 return false;
@@ -145,7 +147,7 @@ private Q_SLOTS:
145 bool gotResult = false; 147 bool gotResult = false;
146 bool gotError = false; 148 bool gotError = false;
147 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 149 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite);
148 int numValues = store.scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { 150 int numValues = store.createTransaction(Akonadi2::Storage::ReadOnly).scan("", [&](const QByteArray &key, const QByteArray &value) -> bool {
149 gotResult = true; 151 gotResult = true;
150 return false; 152 return false;
151 }, 153 },