From 95801103c1fc773b074eea1b2d03820099ac09a6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 10 Dec 2014 21:54:04 +0100 Subject: Storage: implemented scan This can replace all our read calls. Note that we need a different API for databases where the value needs to be loaded first, so we can do a key scan before loading values. With this we can do key + value scans in one though. --- tests/storagetest.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 1974355..b3313c0 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -82,6 +82,44 @@ private Q_SLOTS: storage.removeFromDisk(); } + void testScan() + { + const int count = 100; + populate(count); + + //ensure we can scan for values + { + int hit = 0; + Storage store(testDataPath, dbName); + store.scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { + if (std::string(static_cast(keyValue), keySize) == "key50") { + hit++; + } + return true; + }); + QCOMPARE(hit, 1); + } + + //ensure we can read a single value + { + int hit = 0; + bool foundInvalidValue = false; + Storage store(testDataPath, dbName); + store.scan("key50", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { + if (std::string(static_cast(keyValue), keySize) != "key50") { + foundInvalidValue = true; + } + hit++; + return true; + }); + QVERIFY(!foundInvalidValue); + QCOMPARE(hit, 1); + } + + Storage storage(testDataPath, dbName); + storage.removeFromDisk(); + } + void testConcurrentRead() { const int count = 10000; -- cgit v1.2.3