diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-22 11:25:26 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-22 11:25:26 +0200 |
commit | 6746247a49f09287ae4924c5c3df791f9bf61cbc (patch) | |
tree | b9df15f1e6413a8995704cf9f0c5f425c9bb9558 /tests | |
parent | fc3a5df884b25d5e624027b1fb017f42986980b2 (diff) | |
download | sink-6746247a49f09287ae4924c5c3df791f9bf61cbc.tar.gz sink-6746247a49f09287ae4924c5c3df791f9bf61cbc.zip |
Use named databases in storage.
This will allow us to create indexes in the same store.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/indextest.cpp | 21 | ||||
-rw-r--r-- | tests/storagebenchmark.cpp | 8 | ||||
-rw-r--r-- | tests/storagetest.cpp | 114 |
3 files changed, 131 insertions, 12 deletions
diff --git a/tests/indextest.cpp b/tests/indextest.cpp index 24f90c8..e3eabcc 100644 --- a/tests/indextest.cpp +++ b/tests/indextest.cpp | |||
@@ -13,38 +13,39 @@ class IndexTest : public QObject | |||
13 | private Q_SLOTS: | 13 | private Q_SLOTS: |
14 | void initTestCase() | 14 | void initTestCase() |
15 | { | 15 | { |
16 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); | 16 | Akonadi2::Storage store("./testindex", "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); |
17 | store.removeFromDisk(); | 17 | store.removeFromDisk(); |
18 | } | 18 | } |
19 | 19 | ||
20 | void cleanup() | 20 | void cleanup() |
21 | { | 21 | { |
22 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); | 22 | Akonadi2::Storage store("./testindex", "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); |
23 | store.removeFromDisk(); | 23 | store.removeFromDisk(); |
24 | } | 24 | } |
25 | 25 | ||
26 | void testIndex() | 26 | void testIndex() |
27 | { | 27 | { |
28 | Index index(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); | 28 | Index index("./testindex", "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); |
29 | index.add("key1", "value1"); | 29 | //The first key is specifically a substring of the second key |
30 | index.add("key1", "value2"); | 30 | index.add("key", "value1"); |
31 | index.add("key2", "value3"); | 31 | index.add("keyFoo", "value2"); |
32 | index.add("keyFoo", "value3"); | ||
32 | 33 | ||
33 | { | 34 | { |
34 | QList<QByteArray> values; | 35 | QList<QByteArray> values; |
35 | index.lookup(QByteArray("key1"), [&values](const QByteArray &value) { | 36 | index.lookup(QByteArray("key"), [&values](const QByteArray &value) { |
36 | values << value; | 37 | values << value; |
37 | }, | 38 | }, |
38 | [](const Index::Error &error){ qWarning() << "Error: "; }); | 39 | [](const Index::Error &error){ qWarning() << "Error: "; }); |
39 | QCOMPARE(values.size(), 2); | 40 | QCOMPARE(values.size(), 1); |
40 | } | 41 | } |
41 | { | 42 | { |
42 | QList<QByteArray> values; | 43 | QList<QByteArray> values; |
43 | index.lookup(QByteArray("key2"), [&values](const QByteArray &value) { | 44 | index.lookup(QByteArray("keyFoo"), [&values](const QByteArray &value) { |
44 | values << value; | 45 | values << value; |
45 | }, | 46 | }, |
46 | [](const Index::Error &error){ qWarning() << "Error: "; }); | 47 | [](const Index::Error &error){ qWarning() << "Error: "; }); |
47 | QCOMPARE(values.size(), 1); | 48 | QCOMPARE(values.size(), 2); |
48 | } | 49 | } |
49 | { | 50 | { |
50 | QList<QByteArray> values; | 51 | QList<QByteArray> values; |
diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index ce1005d..f143c4d 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp | |||
@@ -97,9 +97,12 @@ private Q_SLOTS: | |||
97 | auto event = createEvent(); | 97 | auto event = createEvent(); |
98 | if (store) { | 98 | if (store) { |
99 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); | 99 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); |
100 | transaction.setAutocommit(10000); | ||
101 | for (int i = 0; i < count; i++) { | 100 | for (int i = 0; i < count; i++) { |
102 | transaction.write(keyPrefix + QByteArray::number(i), event); | 101 | transaction.write(keyPrefix + QByteArray::number(i), event); |
102 | if ((i % 10000) == 0) { | ||
103 | transaction.commit(); | ||
104 | transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); | ||
105 | } | ||
103 | } | 106 | } |
104 | transaction.commit(); | 107 | transaction.commit(); |
105 | } else { | 108 | } else { |
@@ -116,8 +119,9 @@ private Q_SLOTS: | |||
116 | { | 119 | { |
117 | if (store) { | 120 | if (store) { |
118 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadOnly); | 121 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadOnly); |
122 | auto db = transaction.openDatabase(); | ||
119 | for (int i = 0; i < count; i++) { | 123 | for (int i = 0; i < count; i++) { |
120 | transaction.scan(keyPrefix + QByteArray::number(i), [](const QByteArray &key, const QByteArray &value) -> bool { return true; }); | 124 | db.scan(keyPrefix + QByteArray::number(i), [](const QByteArray &key, const QByteArray &value) -> bool { return true; }); |
121 | } | 125 | } |
122 | } | 126 | } |
123 | } | 127 | } |
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 55ec888..fe80bb7 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -211,6 +211,120 @@ private Q_SLOTS: | |||
211 | storage2.removeFromDisk(); | 211 | storage2.removeFromDisk(); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | |||
215 | void testNoDuplicates() | ||
216 | { | ||
217 | bool gotResult = false; | ||
218 | bool gotError = false; | ||
219 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, false); | ||
220 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
221 | auto db = transaction.openDatabase(); | ||
222 | db.write("key","value"); | ||
223 | db.write("key","value"); | ||
224 | |||
225 | int numValues = db.scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
226 | gotResult = true; | ||
227 | return true; | ||
228 | }, | ||
229 | [&](const Akonadi2::Storage::Error &error) { | ||
230 | qDebug() << error.message; | ||
231 | gotError = true; | ||
232 | }); | ||
233 | |||
234 | QCOMPARE(numValues, 1); | ||
235 | QVERIFY(!gotError); | ||
236 | } | ||
237 | |||
238 | void testDuplicates() | ||
239 | { | ||
240 | bool gotResult = false; | ||
241 | bool gotError = false; | ||
242 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
243 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
244 | auto db = transaction.openDatabase(); | ||
245 | db.write("key","value1"); | ||
246 | db.write("key","value2"); | ||
247 | int numValues = db.scan("key", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
248 | gotResult = true; | ||
249 | return true; | ||
250 | }, | ||
251 | [&](const Akonadi2::Storage::Error &error) { | ||
252 | qDebug() << error.message; | ||
253 | gotError = true; | ||
254 | }); | ||
255 | |||
256 | QCOMPARE(numValues, 2); | ||
257 | QVERIFY(!gotError); | ||
258 | } | ||
259 | |||
260 | void testNonexitingNamedDb() | ||
261 | { | ||
262 | bool gotResult = false; | ||
263 | bool gotError = false; | ||
264 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadOnly); | ||
265 | int numValues = store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
266 | gotResult = true; | ||
267 | return false; | ||
268 | }, | ||
269 | [&](const Akonadi2::Storage::Error &error) { | ||
270 | qDebug() << error.message; | ||
271 | gotError = true; | ||
272 | }); | ||
273 | QCOMPARE(numValues, 0); | ||
274 | QVERIFY(!gotResult); | ||
275 | QVERIFY(!gotError); | ||
276 | } | ||
277 | |||
278 | void testWriteToNamedDb() | ||
279 | { | ||
280 | bool gotError = false; | ||
281 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); | ||
282 | store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { | ||
283 | qDebug() << error.message; | ||
284 | gotError = true; | ||
285 | }); | ||
286 | QVERIFY(!gotError); | ||
287 | } | ||
288 | |||
289 | void testWriteDuplicatesToNamedDb() | ||
290 | { | ||
291 | bool gotError = false; | ||
292 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
293 | store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { | ||
294 | qDebug() << error.message; | ||
295 | gotError = true; | ||
296 | }); | ||
297 | QVERIFY(!gotError); | ||
298 | } | ||
299 | |||
300 | //By default we want only exact matches | ||
301 | void testSubstringKeys() | ||
302 | { | ||
303 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
304 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
305 | auto db = transaction.openDatabase(); | ||
306 | db.write("sub","value1"); | ||
307 | db.write("subsub","value2"); | ||
308 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
309 | return true; | ||
310 | }); | ||
311 | |||
312 | QCOMPARE(numValues, 1); | ||
313 | } | ||
314 | |||
315 | //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. | ||
316 | void testKeyRange() | ||
317 | { | ||
318 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
319 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
320 | auto db = transaction.openDatabase(); | ||
321 | db.write("sub1","value1"); | ||
322 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
323 | return true; | ||
324 | }); | ||
325 | |||
326 | QCOMPARE(numValues, 0); | ||
327 | } | ||
214 | }; | 328 | }; |
215 | 329 | ||
216 | QTEST_MAIN(StorageTest) | 330 | QTEST_MAIN(StorageTest) |