summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/storage_lmdb.cpp17
-rw-r--r--tests/storagetest.cpp25
2 files changed, 17 insertions, 25 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 283205f..8e9b05c 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -28,11 +28,11 @@ public:
28}; 28};
29 29
30Storage::Private::Private(const QString &s, const QString &n) 30Storage::Private::Private(const QString &s, const QString &n)
31 : transaction(0), 31 : storageRoot(s),
32 name(n),
33 transaction(0),
32 readTransaction(false), 34 readTransaction(false),
33 firstOpen(true), 35 firstOpen(true)
34 storageRoot(s),
35 name(n)
36{ 36{
37 QDir dir; 37 QDir dir;
38 dir.mkdir(storageRoot); 38 dir.mkdir(storageRoot);
@@ -148,7 +148,7 @@ void Storage::abortTransaction()
148 148
149bool Storage::write(const char *key, size_t keySize, const char *value, size_t valueSize) 149bool Storage::write(const char *key, size_t keySize, const char *value, size_t valueSize)
150{ 150{
151 write(std::string(key, keySize), std::string(value, valueSize)); 151 return write(std::string(key, keySize), std::string(value, valueSize));
152} 152}
153 153
154bool Storage::write(const std::string &sKey, const std::string &sValue) 154bool Storage::write(const std::string &sKey, const std::string &sValue)
@@ -269,13 +269,6 @@ qint64 Storage::diskUsage() const
269 269
270void Storage::removeFromDisk() const 270void Storage::removeFromDisk() const
271{ 271{
272 QDir dir(d->path);
273 dir.remove("data.mdb");
274 dir.remove("lock.mdb");
275}
276
277void Storage::removeFromDisk() const
278{
279 QDir dir(d->storageRoot); 272 QDir dir(d->storageRoot);
280 dir.remove("data.mdb"); 273 dir.remove("data.mdb");
281 dir.remove("lock.mdb"); 274 dir.remove("lock.mdb");
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index 2b2805d..242e424 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -38,13 +38,13 @@ private:
38 bool success = true; 38 bool success = true;
39 bool keyMatch = true; 39 bool keyMatch = true;
40 const auto reference = keyPrefix + std::to_string(i); 40 const auto reference = keyPrefix + std::to_string(i);
41 success = storage.read(keyPrefix + std::to_string(i), [&error, &reference](const std::string &value) { 41 success = storage.read(keyPrefix + std::to_string(i), [&keyMatch, &reference](const std::string &value) {
42 if (value != reference) { 42 if (value != reference) {
43 qDebug() << "Mismatch while reading"; 43 qDebug() << "Mismatch while reading";
44 keyMatch = false; 44 keyMatch = false;
45 } 45 }
46 }); 46 });
47 return succes && keyMatch; 47 return success && keyMatch;
48 } 48 }
49 49
50private Q_SLOTS: 50private Q_SLOTS:
@@ -56,11 +56,10 @@ private Q_SLOTS:
56 56
57 void cleanupTestCase() 57 void cleanupTestCase()
58 { 58 {
59 Database db(testDataPath, dbName); 59 Storage storage(testDataPath, dbName);
60 db.removeFromDisk(); 60 storage.removeFromDisk();
61 } 61 }
62 62
63
64 void testRead() 63 void testRead()
65 { 64 {
66 const int count = 100; 65 const int count = 100;
@@ -69,14 +68,14 @@ private Q_SLOTS:
69 68
70 //ensure we can read everything back correctly 69 //ensure we can read everything back correctly
71 { 70 {
72 Database db(testDataPath, dbName); 71 Storage storage(testDataPath, dbName);
73 for (int i = 0; i < count; i++) { 72 for (int i = 0; i < count; i++) {
74 QVERIFY(verify(db, i)); 73 QVERIFY(verify(storage, i));
75 } 74 }
76 } 75 }
77 76
78 Database db(testDataPath, dbName); 77 Storage storage(testDataPath, dbName);
79 db.removeFromDisk(); 78 storage.removeFromDisk();
80 } 79 }
81 80
82 void testConcurrentRead() 81 void testConcurrentRead()
@@ -90,9 +89,9 @@ private Q_SLOTS:
90 const int concurrencyLevel = 4; 89 const int concurrencyLevel = 4;
91 for (int num = 0; num < concurrencyLevel; num++) { 90 for (int num = 0; num < concurrencyLevel; num++) {
92 futures << QtConcurrent::run([this, count](){ 91 futures << QtConcurrent::run([this, count](){
93 Database db(testDataPath, dbName); 92 Storage storage(testDataPath, dbName);
94 for (int i = 0; i < count; i++) { 93 for (int i = 0; i < count; i++) {
95 if (!verify(db, i)) { 94 if (!verify(storage, i)) {
96 qWarning() << "invalid value"; 95 qWarning() << "invalid value";
97 break; 96 break;
98 } 97 }
@@ -103,8 +102,8 @@ private Q_SLOTS:
103 future.waitForFinished(); 102 future.waitForFinished();
104 } 103 }
105 104
106 Database db(testDataPath, dbName); 105 Storage storage(testDataPath, dbName);
107 db.removeFromDisk(); 106 storage.removeFromDisk();
108 } 107 }
109}; 108};
110 109