summaryrefslogtreecommitdiffstats
path: root/tests/storagetest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-20 19:07:07 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-20 19:07:07 +0100
commitbdb01c2c068df326f5a8328ed1492ab1bea388c5 (patch)
tree25c2ee1b29bc481b6914c244ed9ca194b1415d16 /tests/storagetest.cpp
parent17e7ee40c9185c0505883853345fd6024c675b1a (diff)
downloadsink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.tar.gz
sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.zip
Renamed Akonadi2 to Sink
(except for documentation).
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r--tests/storagetest.cpp120
1 files changed, 60 insertions, 60 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index d950961..b0db1ac 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -21,14 +21,14 @@ private:
21 21
22 void populate(int count) 22 void populate(int count)
23 { 23 {
24 Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 24 Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadWrite);
25 auto transaction = storage.createTransaction(Akonadi2::Storage::ReadWrite); 25 auto transaction = storage.createTransaction(Sink::Storage::ReadWrite);
26 for (int i = 0; i < count; i++) { 26 for (int i = 0; i < count; i++) {
27 //This should perhaps become an implementation detail of the db? 27 //This should perhaps become an implementation detail of the db?
28 if (i % 10000 == 0) { 28 if (i % 10000 == 0) {
29 if (i > 0) { 29 if (i > 0) {
30 transaction.commit(); 30 transaction.commit();
31 transaction = std::move(storage.createTransaction(Akonadi2::Storage::ReadWrite)); 31 transaction = std::move(storage.createTransaction(Sink::Storage::ReadWrite));
32 } 32 }
33 } 33 }
34 transaction.openDatabase().write(keyPrefix + QByteArray::number(i), keyPrefix + QByteArray::number(i)); 34 transaction.openDatabase().write(keyPrefix + QByteArray::number(i), keyPrefix + QByteArray::number(i));
@@ -36,12 +36,12 @@ private:
36 transaction.commit(); 36 transaction.commit();
37 } 37 }
38 38
39 bool verify(Akonadi2::Storage &storage, int i) 39 bool verify(Sink::Storage &storage, int i)
40 { 40 {
41 bool success = true; 41 bool success = true;
42 bool keyMatch = true; 42 bool keyMatch = true;
43 const auto reference = keyPrefix + QByteArray::number(i); 43 const auto reference = keyPrefix + QByteArray::number(i);
44 storage.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan(keyPrefix + QByteArray::number(i), 44 storage.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan(keyPrefix + QByteArray::number(i),
45 [&keyMatch, &reference](const QByteArray &key, const QByteArray &value) -> bool { 45 [&keyMatch, &reference](const QByteArray &key, const QByteArray &value) -> bool {
46 if (value != reference) { 46 if (value != reference) {
47 qDebug() << "Mismatch while reading"; 47 qDebug() << "Mismatch while reading";
@@ -49,7 +49,7 @@ private:
49 } 49 }
50 return keyMatch; 50 return keyMatch;
51 }, 51 },
52 [&success](const Akonadi2::Storage::Error &error) { 52 [&success](const Sink::Storage::Error &error) {
53 qDebug() << error.message; 53 qDebug() << error.message;
54 success = false; 54 success = false;
55 } 55 }
@@ -62,20 +62,20 @@ private Q_SLOTS:
62 { 62 {
63 testDataPath = "./testdb"; 63 testDataPath = "./testdb";
64 dbName = "test"; 64 dbName = "test";
65 Akonadi2::Storage storage(testDataPath, dbName); 65 Sink::Storage storage(testDataPath, dbName);
66 storage.removeFromDisk(); 66 storage.removeFromDisk();
67 } 67 }
68 68
69 void cleanup() 69 void cleanup()
70 { 70 {
71 Akonadi2::Storage storage(testDataPath, dbName); 71 Sink::Storage storage(testDataPath, dbName);
72 storage.removeFromDisk(); 72 storage.removeFromDisk();
73 } 73 }
74 74
75 void testCleanup() 75 void testCleanup()
76 { 76 {
77 populate(1); 77 populate(1);
78 Akonadi2::Storage storage(testDataPath, dbName); 78 Sink::Storage storage(testDataPath, dbName);
79 storage.removeFromDisk(); 79 storage.removeFromDisk();
80 QFileInfo info(testDataPath + "/" + dbName); 80 QFileInfo info(testDataPath + "/" + dbName);
81 QVERIFY(!info.exists()); 81 QVERIFY(!info.exists());
@@ -89,7 +89,7 @@ private Q_SLOTS:
89 89
90 //ensure we can read everything back correctly 90 //ensure we can read everything back correctly
91 { 91 {
92 Akonadi2::Storage storage(testDataPath, dbName); 92 Sink::Storage storage(testDataPath, dbName);
93 for (int i = 0; i < count; i++) { 93 for (int i = 0; i < count; i++) {
94 QVERIFY(verify(storage, i)); 94 QVERIFY(verify(storage, i));
95 } 95 }
@@ -104,8 +104,8 @@ private Q_SLOTS:
104 //ensure we can scan for values 104 //ensure we can scan for values
105 { 105 {
106 int hit = 0; 106 int hit = 0;
107 Akonadi2::Storage store(testDataPath, dbName); 107 Sink::Storage store(testDataPath, dbName);
108 store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 108 store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool {
109 if (key == "key50") { 109 if (key == "key50") {
110 hit++; 110 hit++;
111 } 111 }
@@ -118,8 +118,8 @@ private Q_SLOTS:
118 { 118 {
119 int hit = 0; 119 int hit = 0;
120 bool foundInvalidValue = false; 120 bool foundInvalidValue = false;
121 Akonadi2::Storage store(testDataPath, dbName); 121 Sink::Storage store(testDataPath, dbName);
122 store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool { 122 store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool {
123 if (key != "key50") { 123 if (key != "key50") {
124 foundInvalidValue = true; 124 foundInvalidValue = true;
125 } 125 }
@@ -134,10 +134,10 @@ private Q_SLOTS:
134 void testNestedOperations() 134 void testNestedOperations()
135 { 135 {
136 populate(3); 136 populate(3);
137 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 137 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
138 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 138 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
139 transaction.openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { 139 transaction.openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool {
140 transaction.openDatabase().remove(key, [](const Akonadi2::Storage::Error &) { 140 transaction.openDatabase().remove(key, [](const Sink::Storage::Error &) {
141 QVERIFY(false); 141 QVERIFY(false);
142 }); 142 });
143 return false; 143 return false;
@@ -147,9 +147,9 @@ private Q_SLOTS:
147 void testNestedTransactions() 147 void testNestedTransactions()
148 { 148 {
149 populate(3); 149 populate(3);
150 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 150 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
151 store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { 151 store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool {
152 store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase().remove(key, [](const Akonadi2::Storage::Error &) { 152 store.createTransaction(Sink::Storage::ReadWrite).openDatabase().remove(key, [](const Sink::Storage::Error &) {
153 QVERIFY(false); 153 QVERIFY(false);
154 }); 154 });
155 return false; 155 return false;
@@ -160,9 +160,9 @@ private Q_SLOTS:
160 { 160 {
161 bool gotResult = false; 161 bool gotResult = false;
162 bool gotError = false; 162 bool gotError = false;
163 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 163 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
164 auto transaction = store.createTransaction(Akonadi2::Storage::ReadOnly); 164 auto transaction = store.createTransaction(Sink::Storage::ReadOnly);
165 auto db = transaction.openDatabase("default", [&](const Akonadi2::Storage::Error &error) { 165 auto db = transaction.openDatabase("default", [&](const Sink::Storage::Error &error) {
166 qDebug() << error.message; 166 qDebug() << error.message;
167 gotError = true; 167 gotError = true;
168 }); 168 });
@@ -170,7 +170,7 @@ private Q_SLOTS:
170 gotResult = true; 170 gotResult = true;
171 return false; 171 return false;
172 }, 172 },
173 [&](const Akonadi2::Storage::Error &error) { 173 [&](const Sink::Storage::Error &error) {
174 qDebug() << error.message; 174 qDebug() << error.message;
175 gotError = true; 175 gotError = true;
176 }); 176 });
@@ -195,8 +195,8 @@ private Q_SLOTS:
195 const int concurrencyLevel = 20; 195 const int concurrencyLevel = 20;
196 for (int num = 0; num < concurrencyLevel; num++) { 196 for (int num = 0; num < concurrencyLevel; num++) {
197 futures << QtConcurrent::run([this, count, &error](){ 197 futures << QtConcurrent::run([this, count, &error](){
198 Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly); 198 Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadOnly);
199 Akonadi2::Storage storage2(testDataPath, dbName + "2", Akonadi2::Storage::ReadOnly); 199 Sink::Storage storage2(testDataPath, dbName + "2", Sink::Storage::ReadOnly);
200 for (int i = 0; i < count; i++) { 200 for (int i = 0; i < count; i++) {
201 if (!verify(storage, i)) { 201 if (!verify(storage, i)) {
202 error = true; 202 error = true;
@@ -212,9 +212,9 @@ private Q_SLOTS:
212 } 212 }
213 213
214 { 214 {
215 Akonadi2::Storage storage(testDataPath, dbName); 215 Sink::Storage storage(testDataPath, dbName);
216 storage.removeFromDisk(); 216 storage.removeFromDisk();
217 Akonadi2::Storage storage2(testDataPath, dbName + "2"); 217 Sink::Storage storage2(testDataPath, dbName + "2");
218 storage2.removeFromDisk(); 218 storage2.removeFromDisk();
219 } 219 }
220 } 220 }
@@ -223,8 +223,8 @@ private Q_SLOTS:
223 { 223 {
224 bool gotResult = false; 224 bool gotResult = false;
225 bool gotError = false; 225 bool gotError = false;
226 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 226 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
227 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 227 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
228 auto db = transaction.openDatabase("default", nullptr, false); 228 auto db = transaction.openDatabase("default", nullptr, false);
229 db.write("key","value"); 229 db.write("key","value");
230 db.write("key","value"); 230 db.write("key","value");
@@ -233,7 +233,7 @@ private Q_SLOTS:
233 gotResult = true; 233 gotResult = true;
234 return true; 234 return true;
235 }, 235 },
236 [&](const Akonadi2::Storage::Error &error) { 236 [&](const Sink::Storage::Error &error) {
237 qDebug() << error.message; 237 qDebug() << error.message;
238 gotError = true; 238 gotError = true;
239 }); 239 });
@@ -246,8 +246,8 @@ private Q_SLOTS:
246 { 246 {
247 bool gotResult = false; 247 bool gotResult = false;
248 bool gotError = false; 248 bool gotError = false;
249 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 249 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
250 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 250 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
251 auto db = transaction.openDatabase("default", nullptr, true); 251 auto db = transaction.openDatabase("default", nullptr, true);
252 db.write("key","value1"); 252 db.write("key","value1");
253 db.write("key","value2"); 253 db.write("key","value2");
@@ -255,7 +255,7 @@ private Q_SLOTS:
255 gotResult = true; 255 gotResult = true;
256 return true; 256 return true;
257 }, 257 },
258 [&](const Akonadi2::Storage::Error &error) { 258 [&](const Sink::Storage::Error &error) {
259 qDebug() << error.message; 259 qDebug() << error.message;
260 gotError = true; 260 gotError = true;
261 }); 261 });
@@ -268,12 +268,12 @@ private Q_SLOTS:
268 { 268 {
269 bool gotResult = false; 269 bool gotResult = false;
270 bool gotError = false; 270 bool gotError = false;
271 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadOnly); 271 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadOnly);
272 int numValues = store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 272 int numValues = store.createTransaction(Sink::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool {
273 gotResult = true; 273 gotResult = true;
274 return false; 274 return false;
275 }, 275 },
276 [&](const Akonadi2::Storage::Error &error) { 276 [&](const Sink::Storage::Error &error) {
277 qDebug() << error.message; 277 qDebug() << error.message;
278 gotError = true; 278 gotError = true;
279 }); 279 });
@@ -285,8 +285,8 @@ private Q_SLOTS:
285 void testWriteToNamedDb() 285 void testWriteToNamedDb()
286 { 286 {
287 bool gotError = false; 287 bool gotError = false;
288 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 288 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
289 store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { 289 store.createTransaction(Sink::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Sink::Storage::Error &error) {
290 qDebug() << error.message; 290 qDebug() << error.message;
291 gotError = true; 291 gotError = true;
292 }); 292 });
@@ -296,8 +296,8 @@ private Q_SLOTS:
296 void testWriteDuplicatesToNamedDb() 296 void testWriteDuplicatesToNamedDb()
297 { 297 {
298 bool gotError = false; 298 bool gotError = false;
299 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 299 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
300 store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test", nullptr, true).write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { 300 store.createTransaction(Sink::Storage::ReadWrite).openDatabase("test", nullptr, true).write("key1", "value1", [&](const Sink::Storage::Error &error) {
301 qDebug() << error.message; 301 qDebug() << error.message;
302 gotError = true; 302 gotError = true;
303 }); 303 });
@@ -307,8 +307,8 @@ private Q_SLOTS:
307 //By default we want only exact matches 307 //By default we want only exact matches
308 void testSubstringKeys() 308 void testSubstringKeys()
309 { 309 {
310 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 310 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
311 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 311 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
312 auto db = transaction.openDatabase("test", nullptr, true); 312 auto db = transaction.openDatabase("test", nullptr, true);
313 db.write("sub","value1"); 313 db.write("sub","value1");
314 db.write("subsub","value2"); 314 db.write("subsub","value2");
@@ -321,8 +321,8 @@ private Q_SLOTS:
321 321
322 void testFindSubstringKeys() 322 void testFindSubstringKeys()
323 { 323 {
324 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 324 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
325 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 325 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
326 auto db = transaction.openDatabase("test", nullptr, false); 326 auto db = transaction.openDatabase("test", nullptr, false);
327 db.write("sub","value1"); 327 db.write("sub","value1");
328 db.write("subsub","value2"); 328 db.write("subsub","value2");
@@ -336,8 +336,8 @@ private Q_SLOTS:
336 336
337 void testKeySorting() 337 void testKeySorting()
338 { 338 {
339 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 339 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
340 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 340 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
341 auto db = transaction.openDatabase("test", nullptr, false); 341 auto db = transaction.openDatabase("test", nullptr, false);
342 db.write("sub_2","value2"); 342 db.write("sub_2","value2");
343 db.write("sub_1","value1"); 343 db.write("sub_1","value1");
@@ -357,8 +357,8 @@ private Q_SLOTS:
357 //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. 357 //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys.
358 void testKeyRange() 358 void testKeyRange()
359 { 359 {
360 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 360 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
361 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 361 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
362 auto db = transaction.openDatabase("test", nullptr, true); 362 auto db = transaction.openDatabase("test", nullptr, true);
363 db.write("sub1","value1"); 363 db.write("sub1","value1");
364 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { 364 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool {
@@ -370,8 +370,8 @@ private Q_SLOTS:
370 370
371 void testFindLatest() 371 void testFindLatest()
372 { 372 {
373 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 373 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
374 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 374 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
375 auto db = transaction.openDatabase("test", nullptr, false); 375 auto db = transaction.openDatabase("test", nullptr, false);
376 db.write("sub1","value1"); 376 db.write("sub1","value1");
377 db.write("sub2","value2"); 377 db.write("sub2","value2");
@@ -387,8 +387,8 @@ private Q_SLOTS:
387 387
388 void testFindLatestInSingle() 388 void testFindLatestInSingle()
389 { 389 {
390 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 390 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
391 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 391 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
392 auto db = transaction.openDatabase("test", nullptr, false); 392 auto db = transaction.openDatabase("test", nullptr, false);
393 db.write("sub2","value2"); 393 db.write("sub2","value2");
394 QByteArray result; 394 QByteArray result;
@@ -401,8 +401,8 @@ private Q_SLOTS:
401 401
402 void testFindLast() 402 void testFindLast()
403 { 403 {
404 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 404 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
405 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 405 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
406 auto db = transaction.openDatabase("test", nullptr, false); 406 auto db = transaction.openDatabase("test", nullptr, false);
407 db.write("sub2","value2"); 407 db.write("sub2","value2");
408 db.write("wub3","value3"); 408 db.write("wub3","value3");
@@ -416,11 +416,11 @@ private Q_SLOTS:
416 416
417 void testRecordRevision() 417 void testRecordRevision()
418 { 418 {
419 Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); 419 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
420 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); 420 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
421 Akonadi2::Storage::recordRevision(transaction, 1, "uid", "type"); 421 Sink::Storage::recordRevision(transaction, 1, "uid", "type");
422 QCOMPARE(Akonadi2::Storage::getTypeFromRevision(transaction, 1), QByteArray("type")); 422 QCOMPARE(Sink::Storage::getTypeFromRevision(transaction, 1), QByteArray("type"));
423 QCOMPARE(Akonadi2::Storage::getUidFromRevision(transaction, 1), QByteArray("uid")); 423 QCOMPARE(Sink::Storage::getUidFromRevision(transaction, 1), QByteArray("uid"));
424 } 424 }
425}; 425};
426 426