summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-03 09:01:05 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-03 09:01:05 +0100
commit4d9746c828558c9f872e0aed52442863affb25d5 (patch)
tree507d7c2ba67f47d3cbbcf01a722236ff1b48426b /tests
parent9cea920b7dd51867a0be0fed2f461b6be73c103e (diff)
downloadsink-4d9746c828558c9f872e0aed52442863affb25d5.tar.gz
sink-4d9746c828558c9f872e0aed52442863affb25d5.zip
Fromatted the whole codebase with clang-format.
clang-format -i */**{.cpp,.h}
Diffstat (limited to 'tests')
-rw-r--r--tests/clientapitest.cpp76
-rw-r--r--tests/databasepopulationandfacadequerybenchmark.cpp61
-rw-r--r--tests/domainadaptortest.cpp12
-rw-r--r--tests/dummyresourcebenchmark.cpp78
-rw-r--r--tests/dummyresourcetest.cpp35
-rw-r--r--tests/dummyresourcewritebenchmark.cpp32
-rw-r--r--tests/genericfacadetest.cpp24
-rw-r--r--tests/genericresourcebenchmark.cpp22
-rw-r--r--tests/genericresourcetest.cpp6
-rw-r--r--tests/getrssusage.cpp106
-rw-r--r--tests/getrssusage.h2
-rw-r--r--tests/indextest.cpp23
-rw-r--r--tests/inspectiontest.cpp2
-rw-r--r--tests/maildirresourcetest.cpp205
-rw-r--r--tests/maildirsyncbenchmark.cpp12
-rw-r--r--tests/mailquerybenchmark.cpp45
-rw-r--r--tests/messagequeuetest.cpp85
-rw-r--r--tests/modelinteractivitytest.cpp27
-rw-r--r--tests/pipelinebenchmark.cpp21
-rw-r--r--tests/pipelinetest.cpp52
-rw-r--r--tests/querytest.cpp72
-rw-r--r--tests/resourcecommunicationtest.cpp34
-rw-r--r--tests/storagebenchmark.cpp34
-rw-r--r--tests/storagetest.cpp259
-rw-r--r--tests/testimplementations.h45
25 files changed, 669 insertions, 701 deletions
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index 879ffc4..172232f 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -13,34 +13,41 @@ template <typename T>
13class DummyResourceFacade : public Sink::StoreFacade<T> 13class DummyResourceFacade : public Sink::StoreFacade<T>
14{ 14{
15public: 15public:
16 static std::shared_ptr<DummyResourceFacade<T> > registerFacade(const QByteArray &instanceIdentifier = QByteArray()) 16 static std::shared_ptr<DummyResourceFacade<T>> registerFacade(const QByteArray &instanceIdentifier = QByteArray())
17 { 17 {
18 static QMap<QByteArray, std::shared_ptr<DummyResourceFacade<T> > > map; 18 static QMap<QByteArray, std::shared_ptr<DummyResourceFacade<T>>> map;
19 auto facade = std::make_shared<DummyResourceFacade<T> >(); 19 auto facade = std::make_shared<DummyResourceFacade<T>>();
20 map.insert(instanceIdentifier, facade); 20 map.insert(instanceIdentifier, facade);
21 bool alwaysReturnFacade = instanceIdentifier.isEmpty(); 21 bool alwaysReturnFacade = instanceIdentifier.isEmpty();
22 Sink::FacadeFactory::instance().registerFacade<T, DummyResourceFacade<T> >("dummyresource", 22 Sink::FacadeFactory::instance().registerFacade<T, DummyResourceFacade<T>>("dummyresource", [alwaysReturnFacade](const QByteArray &instanceIdentifier) {
23 [alwaysReturnFacade](const QByteArray &instanceIdentifier) { 23 if (alwaysReturnFacade) {
24 if (alwaysReturnFacade) { 24 return map.value(QByteArray());
25 return map.value(QByteArray());
26 }
27 return map.value(instanceIdentifier);
28 } 25 }
29 ); 26 return map.value(instanceIdentifier);
27 });
30 return facade; 28 return facade;
31 } 29 }
32 ~DummyResourceFacade(){}; 30 ~DummyResourceFacade(){};
33 KAsync::Job<void> create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; 31 KAsync::Job<void> create(const T &domainObject) Q_DECL_OVERRIDE
34 KAsync::Job<void> modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; 32 {
35 KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null<void>(); }; 33 return KAsync::null<void>();
36 QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr > load(const Sink::Query &query) Q_DECL_OVERRIDE 34 };
35 KAsync::Job<void> modify(const T &domainObject) Q_DECL_OVERRIDE
36 {
37 return KAsync::null<void>();
38 };
39 KAsync::Job<void> remove(const T &domainObject) Q_DECL_OVERRIDE
40 {
41 return KAsync::null<void>();
42 };
43 QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE
37 { 44 {
38 auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); 45 auto resultProvider = new Sink::ResultProvider<typename T::Ptr>();
39 resultProvider->onDone([resultProvider]() { 46 resultProvider->onDone([resultProvider]() {
40 Trace() << "Result provider is done"; 47 Trace() << "Result provider is done";
41 delete resultProvider; 48 delete resultProvider;
42 }); 49 });
43 //We have to do it this way, otherwise we're not setting the fetcher right 50 // We have to do it this way, otherwise we're not setting the fetcher right
44 auto emitter = resultProvider->emitter(); 51 auto emitter = resultProvider->emitter();
45 52
46 resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) { 53 resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) {
@@ -60,8 +67,7 @@ public:
60 } 67 }
61 resultProvider->initialResultSetComplete(parent); 68 resultProvider->initialResultSetComplete(parent);
62 }); 69 });
63 auto job = KAsync::start<void>([query, resultProvider]() { 70 auto job = KAsync::start<void>([query, resultProvider]() {});
64 });
65 mResultProvider = resultProvider; 71 mResultProvider = resultProvider;
66 return qMakePair(job, emitter); 72 return qMakePair(job, emitter);
67 } 73 }
@@ -73,7 +79,7 @@ public:
73 79
74/** 80/**
75 * Test of the client api implementation. 81 * Test of the client api implementation.
76 * 82 *
77 * This test works with injected dummy facades and thus doesn't write to storage. 83 * This test works with injected dummy facades and thus doesn't write to storage.
78 */ 84 */
79class ClientAPITest : public QObject 85class ClientAPITest : public QObject
@@ -113,7 +119,7 @@ private slots:
113 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 119 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
114 } 120 }
115 121
116 //TODO: This test doesn't belong to this testsuite 122 // TODO: This test doesn't belong to this testsuite
117 void resourceManagement() 123 void resourceManagement()
118 { 124 {
119 ResourceConfig::clear(); 125 ResourceConfig::clear();
@@ -158,13 +164,13 @@ private slots:
158 void testModelNested() 164 void testModelNested()
159 { 165 {
160 auto facade = DummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); 166 auto facade = DummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade();
161 auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 167 auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
162 auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 168 auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
163 subfolder->setProperty("parent", "id"); 169 subfolder->setProperty("parent", "id");
164 facade->results << folder << subfolder; 170 facade->results << folder << subfolder;
165 ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); 171 ResourceConfig::addResource("dummyresource.instance1", "dummyresource");
166 172
167 //Test 173 // Test
168 Sink::Query query; 174 Sink::Query query;
169 query.resources << "dummyresource.instance1"; 175 query.resources << "dummyresource.instance1";
170 query.liveQuery = false; 176 query.liveQuery = false;
@@ -181,13 +187,13 @@ private slots:
181 void testModelSignals() 187 void testModelSignals()
182 { 188 {
183 auto facade = DummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); 189 auto facade = DummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade();
184 auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 190 auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
185 auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 191 auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
186 subfolder->setProperty("parent", "id"); 192 subfolder->setProperty("parent", "id");
187 facade->results << folder << subfolder; 193 facade->results << folder << subfolder;
188 ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); 194 ResourceConfig::addResource("dummyresource.instance1", "dummyresource");
189 195
190 //Test 196 // Test
191 Sink::Query query; 197 Sink::Query query;
192 query.resources << "dummyresource.instance1"; 198 query.resources << "dummyresource.instance1";
193 query.liveQuery = false; 199 query.liveQuery = false;
@@ -203,13 +209,14 @@ private slots:
203 void testModelNestedLive() 209 void testModelNestedLive()
204 { 210 {
205 auto facade = DummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); 211 auto facade = DummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade();
206 auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 212 auto folder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "id", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
207 auto subfolder = QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 213 auto subfolder =
214 QSharedPointer<Sink::ApplicationDomain::Folder>::create("dummyresource.instance1", "subId", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
208 subfolder->setProperty("parent", "id"); 215 subfolder->setProperty("parent", "id");
209 facade->results << folder << subfolder; 216 facade->results << folder << subfolder;
210 ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); 217 ResourceConfig::addResource("dummyresource.instance1", "dummyresource");
211 218
212 //Test 219 // Test
213 Sink::Query query; 220 Sink::Query query;
214 query.resources << "dummyresource.instance1"; 221 query.resources << "dummyresource.instance1";
215 query.liveQuery = true; 222 query.liveQuery = true;
@@ -222,7 +229,7 @@ private slots:
222 229
223 auto resultProvider = facade->mResultProvider; 230 auto resultProvider = facade->mResultProvider;
224 231
225 //Test new toplevel folder 232 // Test new toplevel folder
226 { 233 {
227 QSignalSpy rowsInsertedSpy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); 234 QSignalSpy rowsInsertedSpy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int)));
228 auto folder2 = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 235 auto folder2 = QSharedPointer<Sink::ApplicationDomain::Folder>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
@@ -232,7 +239,7 @@ private slots:
232 QCOMPARE(rowsInsertedSpy.at(0).at(0).value<QModelIndex>(), QModelIndex()); 239 QCOMPARE(rowsInsertedSpy.at(0).at(0).value<QModelIndex>(), QModelIndex());
233 } 240 }
234 241
235 //Test changed name 242 // Test changed name
236 { 243 {
237 QSignalSpy dataChanged(model.data(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &))); 244 QSignalSpy dataChanged(model.data(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &)));
238 folder->setProperty("subject", "modifiedSubject"); 245 folder->setProperty("subject", "modifiedSubject");
@@ -241,7 +248,7 @@ private slots:
241 QTRY_COMPARE(dataChanged.count(), 1); 248 QTRY_COMPARE(dataChanged.count(), 1);
242 } 249 }
243 250
244 //Test removal 251 // Test removal
245 { 252 {
246 QSignalSpy rowsRemovedSpy(model.data(), SIGNAL(rowsRemoved(const QModelIndex &, int, int))); 253 QSignalSpy rowsRemovedSpy(model.data(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)));
247 folder->setProperty("subject", "modifiedSubject"); 254 folder->setProperty("subject", "modifiedSubject");
@@ -250,7 +257,7 @@ private slots:
250 QTRY_COMPARE(rowsRemovedSpy.count(), 1); 257 QTRY_COMPARE(rowsRemovedSpy.count(), 1);
251 } 258 }
252 259
253 //TODO: A modification can also be a move 260 // TODO: A modification can also be a move
254 } 261 }
255 262
256 void testLoadMultiResource() 263 void testLoadMultiResource()
@@ -274,7 +281,7 @@ private slots:
274 }); 281 });
275 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 282 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
276 QCOMPARE(model->rowCount(QModelIndex()), 2); 283 QCOMPARE(model->rowCount(QModelIndex()), 2);
277 //Ensure children fetched is only emitted once (when all resources are done) 284 // Ensure children fetched is only emitted once (when all resources are done)
278 QTest::qWait(50); 285 QTest::qWait(50);
279 QCOMPARE(childrenFetchedCount, 1); 286 QCOMPARE(childrenFetchedCount, 1);
280 } 287 }
@@ -291,15 +298,12 @@ private slots:
291 298
292 bool gotValue = false; 299 bool gotValue = false;
293 auto result = Sink::Store::fetchOne<Sink::ApplicationDomain::Event>(query) 300 auto result = Sink::Store::fetchOne<Sink::ApplicationDomain::Event>(query)
294 .then<void, Sink::ApplicationDomain::Event>([&gotValue](const Sink::ApplicationDomain::Event &event) { 301 .then<void, Sink::ApplicationDomain::Event>([&gotValue](const Sink::ApplicationDomain::Event &event) { gotValue = true; })
295 gotValue = true; 302 .exec();
296 }).exec();
297 result.waitForFinished(); 303 result.waitForFinished();
298 QVERIFY(!result.errorCode()); 304 QVERIFY(!result.errorCode());
299 QVERIFY(gotValue); 305 QVERIFY(gotValue);
300 } 306 }
301
302
303}; 307};
304 308
305QTEST_MAIN(ClientAPITest) 309QTEST_MAIN(ClientAPITest)
diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp
index 16537c0..4e886af 100644
--- a/tests/databasepopulationandfacadequerybenchmark.cpp
+++ b/tests/databasepopulationandfacadequerybenchmark.cpp
@@ -23,7 +23,7 @@
23 23
24/** 24/**
25 * Benchmark read performance of the facade implementation. 25 * Benchmark read performance of the facade implementation.
26 * 26 *
27 * The memory used should grow linearly with the number of retrieved entities. 27 * The memory used should grow linearly with the number of retrieved entities.
28 * The memory used should be independent from the database size, after accounting for the memory mapped db. 28 * The memory used should be independent from the database size, after accounting for the memory mapped db.
29 */ 29 */
@@ -39,7 +39,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
39 void populateDatabase(int count) 39 void populateDatabase(int count)
40 { 40 {
41 Sink::Storage(Sink::storageLocation(), "identifier", Sink::Storage::ReadWrite).removeFromDisk(); 41 Sink::Storage(Sink::storageLocation(), "identifier", Sink::Storage::ReadWrite).removeFromDisk();
42 //Setup 42 // Setup
43 auto domainTypeAdaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); 43 auto domainTypeAdaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
44 { 44 {
45 Sink::Storage storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite); 45 Sink::Storage storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite);
@@ -57,7 +57,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
57 domainObject->setProperty("attachment", attachment); 57 domainObject->setProperty("attachment", attachment);
58 flatbuffers::FlatBufferBuilder fbb; 58 flatbuffers::FlatBufferBuilder fbb;
59 domainTypeAdaptorFactory->createBuffer(*domainObject, fbb); 59 domainTypeAdaptorFactory->createBuffer(*domainObject, fbb);
60 const auto buffer = QByteArray::fromRawData(reinterpret_cast<const char*>(fbb.GetBufferPointer()), fbb.GetSize()); 60 const auto buffer = QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
61 const auto key = QUuid::createUuid().toString().toLatin1(); 61 const auto key = QUuid::createUuid().toString().toLatin1();
62 db.write(key, buffer); 62 db.write(key, buffer);
63 bufferSizeTotal += buffer.size(); 63 bufferSizeTotal += buffer.size();
@@ -72,15 +72,15 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
72 auto size = db.getSize(); 72 auto size = db.getSize();
73 auto onDisk = storage.diskUsage(); 73 auto onDisk = storage.diskUsage();
74 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal); 74 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal);
75 std::cout << "Database size [kb]: " << size/1024 << std::endl; 75 std::cout << "Database size [kb]: " << size / 1024 << std::endl;
76 std::cout << "On disk [kb]: " << onDisk/1024 << std::endl; 76 std::cout << "On disk [kb]: " << onDisk / 1024 << std::endl;
77 std::cout << "Buffer size total [kb]: " << bufferSizeTotal/1024 << std::endl; 77 std::cout << "Buffer size total [kb]: " << bufferSizeTotal / 1024 << std::endl;
78 std::cout << "Key size total [kb]: " << keysSizeTotal/1024 << std::endl; 78 std::cout << "Key size total [kb]: " << keysSizeTotal / 1024 << std::endl;
79 std::cout << "Data size total [kb]: " << dataSizeTotal/1024 << std::endl; 79 std::cout << "Data size total [kb]: " << dataSizeTotal / 1024 << std::endl;
80 std::cout << "Write amplification: " << writeAmplification << std::endl; 80 std::cout << "Write amplification: " << writeAmplification << std::endl;
81 81
82 //The buffer has an overhead, but with a reasonable attachment size it should be relatively small 82 // The buffer has an overhead, but with a reasonable attachment size it should be relatively small
83 //A write amplification of 2 should be the worst case 83 // A write amplification of 2 should be the worst case
84 QVERIFY(writeAmplification < 2); 84 QVERIFY(writeAmplification < 2);
85 } 85 }
86 } 86 }
@@ -91,13 +91,14 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
91 91
92 Sink::Query query; 92 Sink::Query query;
93 query.liveQuery = false; 93 query.liveQuery = false;
94 query.requestedProperties << "uid" << "summary"; 94 query.requestedProperties << "uid"
95 << "summary";
95 96
96 //Benchmark 97 // Benchmark
97 QTime time; 98 QTime time;
98 time.start(); 99 time.start();
99 100
100 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr> >::create(); 101 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
101 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 102 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
102 TestResourceFacade facade(identifier, resourceAccess); 103 TestResourceFacade facade(identifier, resourceAccess);
103 104
@@ -105,13 +106,9 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
105 ret.first.exec().waitForFinished(); 106 ret.first.exec().waitForFinished();
106 auto emitter = ret.second; 107 auto emitter = ret.second;
107 QList<Sink::ApplicationDomain::Event::Ptr> list; 108 QList<Sink::ApplicationDomain::Event::Ptr> list;
108 emitter->onAdded([&list](const Sink::ApplicationDomain::Event::Ptr &event) { 109 emitter->onAdded([&list](const Sink::ApplicationDomain::Event::Ptr &event) { list << event; });
109 list << event;
110 });
111 bool done = false; 110 bool done = false;
112 emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Event::Ptr &event) { 111 emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Event::Ptr &event) { done = true; });
113 done = true;
114 });
115 emitter->fetch(Sink::ApplicationDomain::Event::Ptr()); 112 emitter->fetch(Sink::ApplicationDomain::Event::Ptr());
116 QTRY_VERIFY(done); 113 QTRY_VERIFY(done);
117 QCOMPARE(list.size(), count); 114 QCOMPARE(list.size(), count);
@@ -120,35 +117,35 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
120 117
121 const auto finalRss = getCurrentRSS(); 118 const auto finalRss = getCurrentRSS();
122 const auto rssGrowth = finalRss - startingRss; 119 const auto rssGrowth = finalRss - startingRss;
123 //Since the database is memory mapped it is attributted to the resident set size. 120 // Since the database is memory mapped it is attributted to the resident set size.
124 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite).diskUsage(); 121 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite).diskUsage();
125 const auto peakRss = getPeakRSS(); 122 const auto peakRss = getPeakRSS();
126 //How much peak deviates from final rss in percent (should be around 0) 123 // How much peak deviates from final rss in percent (should be around 0)
127 const auto percentageRssError = static_cast<double>(peakRss - finalRss)*100.0/static_cast<double>(finalRss); 124 const auto percentageRssError = static_cast<double>(peakRss - finalRss) * 100.0 / static_cast<double>(finalRss);
128 auto rssGrowthPerEntity = rssGrowth/count; 125 auto rssGrowthPerEntity = rssGrowth / count;
129 126
130 std::cout << "Loaded " << list.size() << " results." << std::endl; 127 std::cout << "Loaded " << list.size() << " results." << std::endl;
131 std::cout << "The query took [ms]: " << elapsed << std::endl; 128 std::cout << "The query took [ms]: " << elapsed << std::endl;
132 std::cout << "Current Rss usage [kb]: " << finalRss/1024 << std::endl; 129 std::cout << "Current Rss usage [kb]: " << finalRss / 1024 << std::endl;
133 std::cout << "Peak Rss usage [kb]: " << peakRss/1024 << std::endl; 130 std::cout << "Peak Rss usage [kb]: " << peakRss / 1024 << std::endl;
134 std::cout << "Rss growth [kb]: " << rssGrowth/1024 << std::endl; 131 std::cout << "Rss growth [kb]: " << rssGrowth / 1024 << std::endl;
135 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl; 132 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl;
136 std::cout << "Rss without db [kb]: " << rssWithoutDb/1024 << std::endl; 133 std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl;
137 std::cout << "Percentage error: " << percentageRssError << std::endl; 134 std::cout << "Percentage error: " << percentageRssError << std::endl;
138 135
139 HAWD::Dataset dataset("facade_query", mHawdState); 136 HAWD::Dataset dataset("facade_query", mHawdState);
140 HAWD::Dataset::Row row = dataset.row(); 137 HAWD::Dataset::Row row = dataset.row();
141 row.setValue("rows", list.size()); 138 row.setValue("rows", list.size());
142 row.setValue("queryResultPerMs", (qreal)list.size()/elapsed); 139 row.setValue("queryResultPerMs", (qreal)list.size() / elapsed);
143 dataset.insertRow(row); 140 dataset.insertRow(row);
144 HAWD::Formatter::print(dataset); 141 HAWD::Formatter::print(dataset);
145 142
146 mTimePerEntity << static_cast<double>(elapsed)/static_cast<double>(count); 143 mTimePerEntity << static_cast<double>(elapsed) / static_cast<double>(count);
147 mRssGrowthPerEntity << rssGrowthPerEntity; 144 mRssGrowthPerEntity << rssGrowthPerEntity;
148 145
149 QVERIFY(percentageRssError < 10); 146 QVERIFY(percentageRssError < 10);
150 //TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase, 147 // TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase,
151 //so it doesn't look like that memory is being duplicated. 148 // so it doesn't look like that memory is being duplicated.
152 QVERIFY(rssGrowthPerEntity < 3300); 149 QVERIFY(rssGrowthPerEntity < 3300);
153 150
154 // Print memory layout, RSS is what is in memory 151 // Print memory layout, RSS is what is in memory
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp
index 5939a31..ff75d21 100644
--- a/tests/domainadaptortest.cpp
+++ b/tests/domainadaptortest.cpp
@@ -54,7 +54,7 @@ private slots:
54 54
55 void testAdaptor() 55 void testAdaptor()
56 { 56 {
57 //Create entity buffer 57 // Create entity buffer
58 flatbuffers::FlatBufferBuilder metadataFbb; 58 flatbuffers::FlatBufferBuilder metadataFbb;
59 auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); 59 auto metadataBuilder = Sink::MetadataBuilder(metadataFbb);
60 metadataBuilder.add_revision(1); 60 metadataBuilder.add_revision(1);
@@ -75,19 +75,19 @@ private slots:
75 Sink::ApplicationDomain::Buffer::FinishEventBuffer(m_fbb, buffer); 75 Sink::ApplicationDomain::Buffer::FinishEventBuffer(m_fbb, buffer);
76 76
77 flatbuffers::FlatBufferBuilder fbb; 77 flatbuffers::FlatBufferBuilder fbb;
78 Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize()); 78 Sink::EntityBuffer::assembleEntityBuffer(
79 fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize());
79 80
80 //Extract entity buffer 81 // Extract entity buffer
81 { 82 {
82 std::string data(reinterpret_cast<const char*>(fbb.GetBufferPointer()), fbb.GetSize()); 83 std::string data(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
83 Sink::EntityBuffer buffer((void*)(data.data()), data.size()); 84 Sink::EntityBuffer buffer((void *)(data.data()), data.size());
84 85
85 TestFactory factory; 86 TestFactory factory;
86 auto adaptor = factory.createAdaptor(buffer.entity()); 87 auto adaptor = factory.createAdaptor(buffer.entity());
87 QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary1")); 88 QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary1"));
88 } 89 }
89 } 90 }
90
91}; 91};
92 92
93QTEST_MAIN(DomainAdaptorTest) 93QTEST_MAIN(DomainAdaptorTest)
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp
index 77b87fb..124abc1 100644
--- a/tests/dummyresourcebenchmark.cpp
+++ b/tests/dummyresourcebenchmark.cpp
@@ -44,40 +44,38 @@ private slots:
44 { 44 {
45 } 45 }
46 46
47 static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void> > &futures) 47 static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void>> &futures)
48 { 48 {
49 auto context = new QObject; 49 auto context = new QObject;
50 return KAsync::start<void>([futures, context](KAsync::Future<void> &future) { 50 return KAsync::start<void>([futures, context](KAsync::Future<void> &future) {
51 const auto total = futures.size(); 51 const auto total = futures.size();
52 auto count = QSharedPointer<int>::create(); 52 auto count = QSharedPointer<int>::create();
53 int i = 0; 53 int i = 0;
54 for (KAsync::Future<void> subFuture : futures) { 54 for (KAsync::Future<void> subFuture : futures) {
55 i++; 55 i++;
56 if (subFuture.isFinished()) { 56 if (subFuture.isFinished()) {
57 *count += 1; 57 *count += 1;
58 continue; 58 continue;
59 } 59 }
60 //FIXME bind lifetime all watcher to future (repectively the main job 60 // FIXME bind lifetime all watcher to future (repectively the main job
61 auto watcher = QSharedPointer<KAsync::FutureWatcher<void> >::create(); 61 auto watcher = QSharedPointer<KAsync::FutureWatcher<void>>::create();
62 QObject::connect(watcher.data(), &KAsync::FutureWatcher<void>::futureReady, 62 QObject::connect(watcher.data(), &KAsync::FutureWatcher<void>::futureReady, [count, total, &future]() {
63 [count, total, &future](){ 63 *count += 1;
64 *count += 1; 64 if (*count == total) {
65 if (*count == total) { 65 future.setFinished();
66 future.setFinished(); 66 }
67 } 67 });
68 }); 68 watcher->setFuture(subFuture);
69 watcher->setFuture(subFuture); 69 context->setProperty(QString("future%1").arg(i).toLatin1().data(), QVariant::fromValue(watcher));
70 context->setProperty(QString("future%1").arg(i).toLatin1().data(), QVariant::fromValue(watcher)); 70 }
71 } 71 })
72 }).then<void>([context]() { 72 .then<void>([context]() { delete context; });
73 delete context;
74 });
75 } 73 }
76 74
77 //Ensure we can process a command in less than 0.1s 75 // Ensure we can process a command in less than 0.1s
78 void testCommandResponsiveness() 76 void testCommandResponsiveness()
79 { 77 {
80 //Test responsiveness including starting the process. 78 // Test responsiveness including starting the process.
81 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished(); 79 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished();
82 80
83 QTime time; 81 QTime time;
@@ -100,7 +98,7 @@ private slots:
100 98
101 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec(); 99 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec();
102 100
103 //Wait for notification 101 // Wait for notification
104 QTRY_VERIFY(gotNotification); 102 QTRY_VERIFY(gotNotification);
105 103
106 QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); 104 QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1());
@@ -114,7 +112,7 @@ private slots:
114 112
115 QTime time; 113 QTime time;
116 time.start(); 114 time.start();
117 QList<KAsync::Future<void> > waitCondition; 115 QList<KAsync::Future<void>> waitCondition;
118 for (int i = 0; i < num; i++) { 116 for (int i = 0; i < num; i++) {
119 Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); 117 Sink::ApplicationDomain::Event event("org.kde.dummy.instance1");
120 event.setProperty("uid", "testuid"); 118 event.setProperty("uid", "testuid");
@@ -125,7 +123,7 @@ private slots:
125 waitForCompletion(waitCondition).exec().waitForFinished(); 123 waitForCompletion(waitCondition).exec().waitForFinished();
126 auto appendTime = time.elapsed(); 124 auto appendTime = time.elapsed();
127 125
128 //Ensure everything is processed 126 // Ensure everything is processed
129 { 127 {
130 Sink::Query query; 128 Sink::Query query;
131 query.resources << "org.kde.dummy.instance1"; 129 query.resources << "org.kde.dummy.instance1";
@@ -137,13 +135,13 @@ private slots:
137 HAWD::Dataset::Row row = dataset.row(); 135 HAWD::Dataset::Row row = dataset.row();
138 136
139 row.setValue("rows", num); 137 row.setValue("rows", num);
140 row.setValue("append", (qreal)num/appendTime); 138 row.setValue("append", (qreal)num / appendTime);
141 row.setValue("total", (qreal)num/allProcessedTime); 139 row.setValue("total", (qreal)num / allProcessedTime);
142 dataset.insertRow(row); 140 dataset.insertRow(row);
143 HAWD::Formatter::print(dataset); 141 HAWD::Formatter::print(dataset);
144 142
145 auto diskUsage = DummyResource::diskUsage("org.kde.dummy.instance1"); 143 auto diskUsage = DummyResource::diskUsage("org.kde.dummy.instance1");
146 qDebug() << "Database size [kb]: " << diskUsage/1024; 144 qDebug() << "Database size [kb]: " << diskUsage / 1024;
147 145
148 // Print memory layout, RSS is what is in memory 146 // Print memory layout, RSS is what is in memory
149 // std::system("exec pmap -x \"$PPID\""); 147 // std::system("exec pmap -x \"$PPID\"");
@@ -153,7 +151,7 @@ private slots:
153 { 151 {
154 QTime time; 152 QTime time;
155 time.start(); 153 time.start();
156 //Measure query 154 // Measure query
157 { 155 {
158 time.start(); 156 time.start();
159 Sink::Query query; 157 Sink::Query query;
@@ -168,7 +166,7 @@ private slots:
168 HAWD::Dataset dataset("dummy_query_by_uid", m_hawdState); 166 HAWD::Dataset dataset("dummy_query_by_uid", m_hawdState);
169 HAWD::Dataset::Row row = dataset.row(); 167 HAWD::Dataset::Row row = dataset.row();
170 row.setValue("rows", num); 168 row.setValue("rows", num);
171 row.setValue("read", (qreal)num/queryTime); 169 row.setValue("read", (qreal)num / queryTime);
172 dataset.insertRow(row); 170 dataset.insertRow(row);
173 HAWD::Formatter::print(dataset); 171 HAWD::Formatter::print(dataset);
174 } 172 }
@@ -220,7 +218,7 @@ private slots:
220 } 218 }
221 auto appendTime = time.elapsed(); 219 auto appendTime = time.elapsed();
222 220
223 //Wait until all messages have been processed 221 // Wait until all messages have been processed
224 resource.processAllMessages().exec().waitForFinished(); 222 resource.processAllMessages().exec().waitForFinished();
225 223
226 auto allProcessedTime = time.elapsed(); 224 auto allProcessedTime = time.elapsed();
@@ -229,8 +227,8 @@ private slots:
229 HAWD::Dataset::Row row = dataset.row(); 227 HAWD::Dataset::Row row = dataset.row();
230 228
231 row.setValue("rows", num); 229 row.setValue("rows", num);
232 row.setValue("append", (qreal)num/appendTime); 230 row.setValue("append", (qreal)num / appendTime);
233 row.setValue("total", (qreal)num/allProcessedTime); 231 row.setValue("total", (qreal)num / allProcessedTime);
234 dataset.insertRow(row); 232 dataset.insertRow(row);
235 HAWD::Formatter::print(dataset); 233 HAWD::Formatter::print(dataset);
236 234
@@ -250,7 +248,7 @@ private slots:
250 248
251 static flatbuffers::FlatBufferBuilder fbb; 249 static flatbuffers::FlatBufferBuilder fbb;
252 fbb.Clear(); 250 fbb.Clear();
253 //This is the resource buffer type and not the domain type 251 // This is the resource buffer type and not the domain type
254 auto entityId = fbb.CreateString(""); 252 auto entityId = fbb.CreateString("");
255 auto type = fbb.CreateString("event"); 253 auto type = fbb.CreateString("event");
256 // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); 254 // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize());
@@ -260,7 +258,7 @@ private slots:
260 } 258 }
261 } 259 }
262 260
263 //This allows to run individual parts without doing a cleanup, but still cleaning up normally 261 // This allows to run individual parts without doing a cleanup, but still cleaning up normally
264 void testCleanupForCompleteTest() 262 void testCleanupForCompleteTest()
265 { 263 {
266 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished(); 264 Sink::Store::removeDataFromDisk("org.kde.dummy.instance1").exec().waitForFinished();
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp
index 8b5a8fa..33304e1 100644
--- a/tests/dummyresourcetest.cpp
+++ b/tests/dummyresourcetest.cpp
@@ -14,7 +14,7 @@
14 14
15/** 15/**
16 * Test of complete system using the dummy resource. 16 * Test of complete system using the dummy resource.
17 * 17 *
18 * This test requires the dummy resource installed. 18 * This test requires the dummy resource installed.
19 */ 19 */
20class DummyResourceTest : public QObject 20class DummyResourceTest : public QObject
@@ -65,7 +65,7 @@ private slots:
65 Sink::Query query; 65 Sink::Query query;
66 query.resources << "org.kde.dummy.instance1"; 66 query.resources << "org.kde.dummy.instance1";
67 67
68 //Ensure all local data is processed 68 // Ensure all local data is processed
69 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 69 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
70 70
71 query.propertyFilter.insert("uid", "testuid"); 71 query.propertyFilter.insert("uid", "testuid");
@@ -89,7 +89,7 @@ private slots:
89 Sink::Query query; 89 Sink::Query query;
90 query.resources << "org.kde.dummy.instance1"; 90 query.resources << "org.kde.dummy.instance1";
91 91
92 //Ensure all local data is processed 92 // Ensure all local data is processed
93 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 93 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
94 94
95 query.propertyFilter.insert("uid", "testuid"); 95 query.propertyFilter.insert("uid", "testuid");
@@ -117,7 +117,7 @@ private slots:
117 Sink::Query query; 117 Sink::Query query;
118 query.resources << "org.kde.dummy.instance1"; 118 query.resources << "org.kde.dummy.instance1";
119 119
120 //Ensure all local data is processed 120 // Ensure all local data is processed
121 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 121 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
122 122
123 query.propertyFilter.insert("summary", "summaryValue2"); 123 query.propertyFilter.insert("summary", "summaryValue2");
@@ -135,7 +135,7 @@ private slots:
135 auto pipeline = QSharedPointer<Sink::Pipeline>::create("org.kde.dummy.instance1"); 135 auto pipeline = QSharedPointer<Sink::Pipeline>::create("org.kde.dummy.instance1");
136 DummyResource resource("org.kde.dummy.instance1", pipeline); 136 DummyResource resource("org.kde.dummy.instance1", pipeline);
137 auto job = resource.synchronizeWithSource(); 137 auto job = resource.synchronizeWithSource();
138 //TODO pass in optional timeout? 138 // TODO pass in optional timeout?
139 auto future = job.exec(); 139 auto future = job.exec();
140 future.waitForFinished(); 140 future.waitForFinished();
141 QVERIFY(!future.errorCode()); 141 QVERIFY(!future.errorCode());
@@ -150,7 +150,7 @@ private slots:
150 Sink::Query query; 150 Sink::Query query;
151 query.resources << "org.kde.dummy.instance1"; 151 query.resources << "org.kde.dummy.instance1";
152 152
153 //Ensure all local data is processed 153 // Ensure all local data is processed
154 Sink::Store::synchronize(query).exec().waitForFinished(); 154 Sink::Store::synchronize(query).exec().waitForFinished();
155 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 155 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
156 156
@@ -167,7 +167,7 @@ private slots:
167 Sink::Query query; 167 Sink::Query query;
168 query.resources << "org.kde.dummy.instance1"; 168 query.resources << "org.kde.dummy.instance1";
169 169
170 //Ensure all local data is processed 170 // Ensure all local data is processed
171 Sink::Store::synchronize(query).exec().waitForFinished(); 171 Sink::Store::synchronize(query).exec().waitForFinished();
172 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 172 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
173 173
@@ -191,10 +191,10 @@ private slots:
191 query.resources << "org.kde.dummy.instance1"; 191 query.resources << "org.kde.dummy.instance1";
192 query.propertyFilter.insert("uid", "testuid"); 192 query.propertyFilter.insert("uid", "testuid");
193 193
194 //Ensure all local data is processed 194 // Ensure all local data is processed
195 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 195 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
196 196
197 //Test create 197 // Test create
198 Sink::ApplicationDomain::Event event2; 198 Sink::ApplicationDomain::Event event2;
199 { 199 {
200 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); 200 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query);
@@ -210,10 +210,10 @@ private slots:
210 event2.setProperty("summary", "summaryValue2"); 210 event2.setProperty("summary", "summaryValue2");
211 Sink::Store::modify<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); 211 Sink::Store::modify<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished();
212 212
213 //Ensure all local data is processed 213 // Ensure all local data is processed
214 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 214 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
215 215
216 //Test modify 216 // Test modify
217 { 217 {
218 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); 218 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query);
219 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 219 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
@@ -225,10 +225,10 @@ private slots:
225 225
226 Sink::Store::remove<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); 226 Sink::Store::remove<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished();
227 227
228 //Ensure all local data is processed 228 // Ensure all local data is processed
229 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 229 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
230 230
231 //Test remove 231 // Test remove
232 { 232 {
233 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query); 233 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query);
234 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 234 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -253,7 +253,7 @@ private slots:
253 event.setProperty("summary", "summaryValue"); 253 event.setProperty("summary", "summaryValue");
254 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished(); 254 Sink::Store::create<Sink::ApplicationDomain::Event>(event).exec().waitForFinished();
255 255
256 //Test create 256 // Test create
257 Sink::ApplicationDomain::Event event2; 257 Sink::ApplicationDomain::Event event2;
258 { 258 {
259 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 259 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
@@ -267,9 +267,9 @@ private slots:
267 event2.setProperty("summary", "summaryValue2"); 267 event2.setProperty("summary", "summaryValue2");
268 Sink::Store::modify<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); 268 Sink::Store::modify<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished();
269 269
270 //Test modify 270 // Test modify
271 { 271 {
272 //TODO wait for a change signal 272 // TODO wait for a change signal
273 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 273 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
274 auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>(); 274 auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Event::Ptr>();
275 QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); 275 QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid"));
@@ -278,12 +278,11 @@ private slots:
278 278
279 Sink::Store::remove<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished(); 279 Sink::Store::remove<Sink::ApplicationDomain::Event>(event2).exec().waitForFinished();
280 280
281 //Test remove 281 // Test remove
282 { 282 {
283 QTRY_COMPARE(model->rowCount(QModelIndex()), 0); 283 QTRY_COMPARE(model->rowCount(QModelIndex()), 0);
284 } 284 }
285 } 285 }
286
287}; 286};
288 287
289QTEST_MAIN(DummyResourceTest) 288QTEST_MAIN(DummyResourceTest)
diff --git a/tests/dummyresourcewritebenchmark.cpp b/tests/dummyresourcewritebenchmark.cpp
index 539d189..b4ab438 100644
--- a/tests/dummyresourcewritebenchmark.cpp
+++ b/tests/dummyresourcewritebenchmark.cpp
@@ -123,39 +123,39 @@ class DummyResourceWriteBenchmark : public QObject
123 Q_UNUSED(appendTime); 123 Q_UNUSED(appendTime);
124 auto bufferSizeTotal = bufferSize * num; 124 auto bufferSizeTotal = bufferSize * num;
125 125
126 //Wait until all messages have been processed 126 // Wait until all messages have been processed
127 resource.processAllMessages().exec().waitForFinished(); 127 resource.processAllMessages().exec().waitForFinished();
128 128
129 auto allProcessedTime = time.elapsed(); 129 auto allProcessedTime = time.elapsed();
130 130
131 const auto finalRss = getCurrentRSS(); 131 const auto finalRss = getCurrentRSS();
132 const auto rssGrowth = finalRss - startingRss; 132 const auto rssGrowth = finalRss - startingRss;
133 //Since the database is memory mapped it is attributted to the resident set size. 133 // Since the database is memory mapped it is attributted to the resident set size.
134 const auto rssWithoutDb = finalRss - DummyResource::diskUsage("org.kde.dummy.instance1"); 134 const auto rssWithoutDb = finalRss - DummyResource::diskUsage("org.kde.dummy.instance1");
135 const auto peakRss = getPeakRSS(); 135 const auto peakRss = getPeakRSS();
136 //How much peak deviates from final rss in percent 136 // How much peak deviates from final rss in percent
137 const auto percentageRssError = static_cast<double>(peakRss - finalRss)*100.0/static_cast<double>(finalRss); 137 const auto percentageRssError = static_cast<double>(peakRss - finalRss) * 100.0 / static_cast<double>(finalRss);
138 auto rssGrowthPerEntity = rssGrowth/num; 138 auto rssGrowthPerEntity = rssGrowth / num;
139 std::cout << "Current Rss usage [kb]: " << finalRss/1024 << std::endl; 139 std::cout << "Current Rss usage [kb]: " << finalRss / 1024 << std::endl;
140 std::cout << "Peak Rss usage [kb]: " << peakRss/1024 << std::endl; 140 std::cout << "Peak Rss usage [kb]: " << peakRss / 1024 << std::endl;
141 std::cout << "Rss growth [kb]: " << rssGrowth/1024 << std::endl; 141 std::cout << "Rss growth [kb]: " << rssGrowth / 1024 << std::endl;
142 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl; 142 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl;
143 std::cout << "Rss without db [kb]: " << rssWithoutDb/1024 << std::endl; 143 std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl;
144 std::cout << "Percentage peak rss error: " << percentageRssError << std::endl; 144 std::cout << "Percentage peak rss error: " << percentageRssError << std::endl;
145 145
146 auto onDisk = DummyResource::diskUsage("org.kde.dummy.instance1"); 146 auto onDisk = DummyResource::diskUsage("org.kde.dummy.instance1");
147 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal); 147 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal);
148 std::cout << "On disk [kb]: " << onDisk/1024 << std::endl; 148 std::cout << "On disk [kb]: " << onDisk / 1024 << std::endl;
149 std::cout << "Buffer size total [kb]: " << bufferSizeTotal/1024 << std::endl; 149 std::cout << "Buffer size total [kb]: " << bufferSizeTotal / 1024 << std::endl;
150 std::cout << "Write amplification: " << writeAmplification << std::endl; 150 std::cout << "Write amplification: " << writeAmplification << std::endl;
151 151
152 152
153 mTimePerEntity << static_cast<double>(allProcessedTime)/static_cast<double>(num); 153 mTimePerEntity << static_cast<double>(allProcessedTime) / static_cast<double>(num);
154 mRssGrowthPerEntity << rssGrowthPerEntity; 154 mRssGrowthPerEntity << rssGrowthPerEntity;
155 155
156 QVERIFY(percentageRssError < 10); 156 QVERIFY(percentageRssError < 10);
157 //TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase, 157 // TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase,
158 //so it doesn't look like that memory is being duplicated. 158 // so it doesn't look like that memory is being duplicated.
159 QVERIFY(rssGrowthPerEntity < 2500); 159 QVERIFY(rssGrowthPerEntity < 2500);
160 160
161 // HAWD::Dataset dataset("dummy_write_in_process", m_hawdState); 161 // HAWD::Dataset dataset("dummy_write_in_process", m_hawdState);
@@ -219,7 +219,7 @@ private slots:
219 std::system(QString("mdb_stat %1/%2 -ff").arg(Sink::storageLocation()).arg("org.kde.dummy.instance1").toLatin1().constData()); 219 std::system(QString("mdb_stat %1/%2 -ff").arg(Sink::storageLocation()).arg("org.kde.dummy.instance1").toLatin1().constData());
220 } 220 }
221 221
222 //This allows to run individual parts without doing a cleanup, but still cleaning up normally 222 // This allows to run individual parts without doing a cleanup, but still cleaning up normally
223 void testCleanupForCompleteTest() 223 void testCleanupForCompleteTest()
224 { 224 {
225 DummyResource::removeFromDisk("org.kde.dummy.instance1"); 225 DummyResource::removeFromDisk("org.kde.dummy.instance1");
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp
index 397bf6a..8336875 100644
--- a/tests/genericfacadetest.cpp
+++ b/tests/genericfacadetest.cpp
@@ -9,7 +9,7 @@
9#include <common/resultprovider.h> 9#include <common/resultprovider.h>
10#include <common/synclistresult.h> 10#include <common/synclistresult.h>
11 11
12//Replace with something different 12// Replace with something different
13#include "event_generated.h" 13#include "event_generated.h"
14 14
15 15
@@ -34,7 +34,7 @@ private slots:
34 Sink::Query query; 34 Sink::Query query;
35 query.liveQuery = false; 35 query.liveQuery = false;
36 36
37 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr> >::create(); 37 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
38 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 38 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
39 // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create(); 39 // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create();
40 TestResourceFacade facade("identifier", resourceAccess); 40 TestResourceFacade facade("identifier", resourceAccess);
@@ -44,7 +44,7 @@ private slots:
44 facade.load(query, *resultSet).exec().waitForFinished(); 44 facade.load(query, *resultSet).exec().waitForFinished();
45 resultSet->initialResultSetComplete(); 45 resultSet->initialResultSetComplete();
46 46
47 //We have to wait for the events that deliver the results to be processed by the eventloop 47 // We have to wait for the events that deliver the results to be processed by the eventloop
48 result.exec(); 48 result.exec();
49 49
50 QCOMPARE(result.size(), 1); 50 QCOMPARE(result.size(), 1);
@@ -55,7 +55,7 @@ private slots:
55 Sink::Query query; 55 Sink::Query query;
56 query.liveQuery = true; 56 query.liveQuery = true;
57 57
58 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr> >::create(); 58 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
59 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 59 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
60 // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create(); 60 // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create();
61 TestResourceFacade facade("identifier", resourceAccess); 61 TestResourceFacade facade("identifier", resourceAccess);
@@ -68,13 +68,13 @@ private slots:
68 result.exec(); 68 result.exec();
69 QCOMPARE(result.size(), 1); 69 QCOMPARE(result.size(), 1);
70 70
71 //Enter a second result 71 // Enter a second result
72 // storage->mResults.clear(); 72 // storage->mResults.clear();
73 // storage->mResults << QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>()); 73 // storage->mResults << QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>());
74 // storage->mLatestRevision = 2; 74 // storage->mLatestRevision = 2;
75 resourceAccess->emit revisionChanged(2); 75 resourceAccess->emit revisionChanged(2);
76 76
77 //Hack to get event loop in synclistresult to abort again 77 // Hack to get event loop in synclistresult to abort again
78 resultSet->initialResultSetComplete(); 78 resultSet->initialResultSetComplete();
79 result.exec(); 79 result.exec();
80 80
@@ -86,7 +86,7 @@ private slots:
86 Sink::Query query; 86 Sink::Query query;
87 query.liveQuery = true; 87 query.liveQuery = true;
88 88
89 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr> >::create(); 89 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
90 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 90 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
91 auto entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 91 auto entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
92 entity->setProperty("test", "test1"); 92 entity->setProperty("test", "test1");
@@ -101,7 +101,7 @@ private slots:
101 result.exec(); 101 result.exec();
102 QCOMPARE(result.size(), 1); 102 QCOMPARE(result.size(), 1);
103 103
104 //Modify the entity again 104 // Modify the entity again
105 // storage->mResults.clear(); 105 // storage->mResults.clear();
106 entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 106 entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
107 entity->setProperty("test", "test2"); 107 entity->setProperty("test", "test2");
@@ -109,7 +109,7 @@ private slots:
109 // storage->mLatestRevision = 2; 109 // storage->mLatestRevision = 2;
110 resourceAccess->emit revisionChanged(2); 110 resourceAccess->emit revisionChanged(2);
111 111
112 //Hack to get event loop in synclistresult to abort again 112 // Hack to get event loop in synclistresult to abort again
113 resultSet->initialResultSetComplete(); 113 resultSet->initialResultSetComplete();
114 result.exec(); 114 result.exec();
115 115
@@ -122,7 +122,7 @@ private slots:
122 Sink::Query query; 122 Sink::Query query;
123 query.liveQuery = true; 123 query.liveQuery = true;
124 124
125 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr> >::create(); 125 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
126 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 126 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
127 auto entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>()); 127 auto entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>());
128 // storage->mResults << entity; 128 // storage->mResults << entity;
@@ -136,13 +136,13 @@ private slots:
136 result.exec(); 136 result.exec();
137 QCOMPARE(result.size(), 1); 137 QCOMPARE(result.size(), 1);
138 138
139 //Remove the entity again 139 // Remove the entity again
140 // storage->mResults.clear(); 140 // storage->mResults.clear();
141 // storage->mRemovals << entity; 141 // storage->mRemovals << entity;
142 // storage->mLatestRevision = 2; 142 // storage->mLatestRevision = 2;
143 resourceAccess->emit revisionChanged(2); 143 resourceAccess->emit revisionChanged(2);
144 144
145 //Hack to get event loop in synclistresult to abort again 145 // Hack to get event loop in synclistresult to abort again
146 resultSet->initialResultSetComplete(); 146 resultSet->initialResultSetComplete();
147 result.exec(); 147 result.exec();
148 148
diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp
index b3af6a6..a0a368c 100644
--- a/tests/genericresourcebenchmark.cpp
+++ b/tests/genericresourcebenchmark.cpp
@@ -60,7 +60,8 @@ static QByteArray createEntityBuffer()
60 return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); 60 return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
61} 61}
62 62
63class IndexUpdater : public Sink::Preprocessor { 63class IndexUpdater : public Sink::Preprocessor
64{
64public: 65public:
65 void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 66 void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
66 { 67 {
@@ -70,7 +71,8 @@ public:
70 } 71 }
71 } 72 }
72 73
73 void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 74 void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity,
75 Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
74 { 76 {
75 } 77 }
76 78
@@ -117,7 +119,7 @@ private slots:
117 } 119 }
118 auto appendTime = time.elapsed(); 120 auto appendTime = time.elapsed();
119 121
120 //Wait until all messages have been processed 122 // Wait until all messages have been processed
121 resource.processAllMessages().exec().waitForFinished(); 123 resource.processAllMessages().exec().waitForFinished();
122 124
123 auto allProcessedTime = time.elapsed(); 125 auto allProcessedTime = time.elapsed();
@@ -129,8 +131,8 @@ private slots:
129 HAWD::Dataset::Row row = dataset.row(); 131 HAWD::Dataset::Row row = dataset.row();
130 132
131 row.setValue("rows", num); 133 row.setValue("rows", num);
132 row.setValue("append", (qreal)num/appendTime); 134 row.setValue("append", (qreal)num / appendTime);
133 row.setValue("total", (qreal)num/allProcessedTime); 135 row.setValue("total", (qreal)num / allProcessedTime);
134 dataset.insertRow(row); 136 dataset.insertRow(row);
135 HAWD::Formatter::print(dataset); 137 HAWD::Formatter::print(dataset);
136 } 138 }
@@ -145,7 +147,7 @@ private slots:
145 const QByteArray resourceIdentifier = "org.kde.test.instance1"; 147 const QByteArray resourceIdentifier = "org.kde.test.instance1";
146 auto indexer = QSharedPointer<IndexUpdater>::create(); 148 auto indexer = QSharedPointer<IndexUpdater>::create();
147 149
148 pipeline->setPreprocessors("event", QVector<Sink::Preprocessor*>() << indexer.data()); 150 pipeline->setPreprocessors("event", QVector<Sink::Preprocessor *>() << indexer.data());
149 pipeline->setAdaptorFactory("event", eventFactory); 151 pipeline->setAdaptorFactory("event", eventFactory);
150 152
151 TestResource resource("org.kde.test.instance1", pipeline); 153 TestResource resource("org.kde.test.instance1", pipeline);
@@ -160,7 +162,7 @@ private slots:
160 } 162 }
161 auto appendTime = time.elapsed(); 163 auto appendTime = time.elapsed();
162 164
163 //Wait until all messages have been processed 165 // Wait until all messages have been processed
164 resource.processAllMessages().exec().waitForFinished(); 166 resource.processAllMessages().exec().waitForFinished();
165 167
166 auto allProcessedTime = time.elapsed(); 168 auto allProcessedTime = time.elapsed();
@@ -172,8 +174,8 @@ private slots:
172 HAWD::Dataset::Row row = dataset.row(); 174 HAWD::Dataset::Row row = dataset.row();
173 175
174 row.setValue("rows", num); 176 row.setValue("rows", num);
175 row.setValue("append", (qreal)num/appendTime); 177 row.setValue("append", (qreal)num / appendTime);
176 row.setValue("total", (qreal)num/allProcessedTime); 178 row.setValue("total", (qreal)num / allProcessedTime);
177 dataset.insertRow(row); 179 dataset.insertRow(row);
178 HAWD::Formatter::print(dataset); 180 HAWD::Formatter::print(dataset);
179 } 181 }
@@ -190,7 +192,7 @@ private slots:
190 192
191 static flatbuffers::FlatBufferBuilder fbb; 193 static flatbuffers::FlatBufferBuilder fbb;
192 fbb.Clear(); 194 fbb.Clear();
193 //This is the resource buffer type and not the domain type 195 // This is the resource buffer type and not the domain type
194 auto type = fbb.CreateString("event"); 196 auto type = fbb.CreateString("event");
195 // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); 197 // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize());
196 auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); 198 auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize());
diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp
index a04c634..7474cbf 100644
--- a/tests/genericresourcetest.cpp
+++ b/tests/genericresourcetest.cpp
@@ -16,7 +16,7 @@
16 16
17/** 17/**
18 * Test of the generic resource implementation. 18 * Test of the generic resource implementation.
19 * 19 *
20 * This test relies on a working pipeline implementation, and writes to storage. 20 * This test relies on a working pipeline implementation, and writes to storage.
21 */ 21 */
22class GenericResourceTest : public QObject 22class GenericResourceTest : public QObject
@@ -30,7 +30,7 @@ private slots:
30 Sink::Log::setDebugOutputLevel(Sink::Log::Trace); 30 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
31 } 31 }
32 32
33 ///Ensure the resource can process messages 33 /// Ensure the resource can process messages
34 void testProcessCommand() 34 void testProcessCommand()
35 { 35 {
36 flatbuffers::FlatBufferBuilder eventFbb; 36 flatbuffers::FlatBufferBuilder eventFbb;
@@ -70,7 +70,7 @@ private slots:
70 QVERIFY(Sink::Commands::VerifyCreateEntityBuffer(verifyer)); 70 QVERIFY(Sink::Commands::VerifyCreateEntityBuffer(verifyer));
71 } 71 }
72 72
73 //Actual test 73 // Actual test
74 auto pipeline = QSharedPointer<Sink::Pipeline>::create("org.kde.test.instance1"); 74 auto pipeline = QSharedPointer<Sink::Pipeline>::create("org.kde.test.instance1");
75 QSignalSpy revisionSpy(pipeline.data(), SIGNAL(revisionUpdated(qint64))); 75 QSignalSpy revisionSpy(pipeline.data(), SIGNAL(revisionUpdated(qint64)));
76 QVERIFY(revisionSpy.isValid()); 76 QVERIFY(revisionSpy.isValid());
diff --git a/tests/getrssusage.cpp b/tests/getrssusage.cpp
index 020c7d6..16fec52 100644
--- a/tests/getrssusage.cpp
+++ b/tests/getrssusage.cpp
@@ -21,7 +21,7 @@
21#if defined(__APPLE__) && defined(__MACH__) 21#if defined(__APPLE__) && defined(__MACH__)
22#include <mach/mach.h> 22#include <mach/mach.h>
23 23
24#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__))) 24#elif(defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
25#include <fcntl.h> 25#include <fcntl.h>
26#include <procfs.h> 26#include <procfs.h>
27 27
@@ -40,85 +40,79 @@
40 * memory use) measured in bytes, or zero if the value cannot be 40 * memory use) measured in bytes, or zero if the value cannot be
41 * determined on this OS. 41 * determined on this OS.
42 */ 42 */
43size_t getPeakRSS( ) 43size_t getPeakRSS()
44{ 44{
45#if defined(_WIN32) 45#if defined(_WIN32)
46 /* Windows -------------------------------------------------- */ 46 /* Windows -------------------------------------------------- */
47 PROCESS_MEMORY_COUNTERS info; 47 PROCESS_MEMORY_COUNTERS info;
48 GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ); 48 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
49 return (size_t)info.PeakWorkingSetSize; 49 return (size_t)info.PeakWorkingSetSize;
50 50
51#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__))) 51#elif(defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
52 /* AIX and Solaris ------------------------------------------ */ 52 /* AIX and Solaris ------------------------------------------ */
53 struct psinfo psinfo; 53 struct psinfo psinfo;
54 int fd = -1; 54 int fd = -1;
55 if ( (fd = open( "/proc/self/psinfo", O_RDONLY )) == -1 ) 55 if ((fd = open("/proc/self/psinfo", O_RDONLY)) == -1)
56 return (size_t)0L; /* Can't open? */ 56 return (size_t)0L; /* Can't open? */
57 if ( read( fd, &psinfo, sizeof(psinfo) ) != sizeof(psinfo) ) 57 if (read(fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
58 { 58 close(fd);
59 close( fd ); 59 return (size_t)0L; /* Can't read? */
60 return (size_t)0L; /* Can't read? */ 60 }
61 } 61 close(fd);
62 close( fd ); 62 return (size_t)(psinfo.pr_rssize * 1024L);
63 return (size_t)(psinfo.pr_rssize * 1024L);
64 63
65#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) 64#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
66 /* BSD, Linux, and OSX -------------------------------------- */ 65 /* BSD, Linux, and OSX -------------------------------------- */
67 struct rusage rusage; 66 struct rusage rusage;
68 getrusage( RUSAGE_SELF, &rusage ); 67 getrusage(RUSAGE_SELF, &rusage);
69#if defined(__APPLE__) && defined(__MACH__) 68#if defined(__APPLE__) && defined(__MACH__)
70 return (size_t)rusage.ru_maxrss; 69 return (size_t)rusage.ru_maxrss;
71#else 70#else
72 return (size_t)(rusage.ru_maxrss * 1024L); 71 return (size_t)(rusage.ru_maxrss * 1024L);
73#endif 72#endif
74 73
75#else 74#else
76 /* Unknown OS ----------------------------------------------- */ 75 /* Unknown OS ----------------------------------------------- */
77 return (size_t)0L; /* Unsupported. */ 76 return (size_t)0L; /* Unsupported. */
78#endif 77#endif
79} 78}
80 79
81 80
82
83
84
85/** 81/**
86 * Returns the current resident set size (physical memory use) measured 82 * Returns the current resident set size (physical memory use) measured
87 * in bytes, or zero if the value cannot be determined on this OS. 83 * in bytes, or zero if the value cannot be determined on this OS.
88 */ 84 */
89size_t getCurrentRSS( ) 85size_t getCurrentRSS()
90{ 86{
91#if defined(_WIN32) 87#if defined(_WIN32)
92 /* Windows -------------------------------------------------- */ 88 /* Windows -------------------------------------------------- */
93 PROCESS_MEMORY_COUNTERS info; 89 PROCESS_MEMORY_COUNTERS info;
94 GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ); 90 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
95 return (size_t)info.WorkingSetSize; 91 return (size_t)info.WorkingSetSize;
96 92
97#elif defined(__APPLE__) && defined(__MACH__) 93#elif defined(__APPLE__) && defined(__MACH__)
98 /* OSX ------------------------------------------------------ */ 94 /* OSX ------------------------------------------------------ */
99 struct mach_task_basic_info info; 95 struct mach_task_basic_info info;
100 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; 96 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
101 if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO, 97 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &infoCount) != KERN_SUCCESS)
102 (task_info_t)&info, &infoCount ) != KERN_SUCCESS ) 98 return (size_t)0L; /* Can't access? */
103 return (size_t)0L; /* Can't access? */ 99 return (size_t)info.resident_size;
104 return (size_t)info.resident_size;
105 100
106#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) 101#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
107 /* Linux ---------------------------------------------------- */ 102 /* Linux ---------------------------------------------------- */
108 long rss = 0L; 103 long rss = 0L;
109 FILE* fp = NULL; 104 FILE *fp = NULL;
110 if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL ) 105 if ((fp = fopen("/proc/self/statm", "r")) == NULL)
111 return (size_t)0L; /* Can't open? */ 106 return (size_t)0L; /* Can't open? */
112 if ( fscanf( fp, "%*s%ld", &rss ) != 1 ) 107 if (fscanf(fp, "%*s%ld", &rss) != 1) {
113 { 108 fclose(fp);
114 fclose( fp ); 109 return (size_t)0L; /* Can't read? */
115 return (size_t)0L; /* Can't read? */ 110 }
116 } 111 fclose(fp);
117 fclose( fp ); 112 return (size_t)rss * (size_t)sysconf(_SC_PAGESIZE);
118 return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE);
119 113
120#else 114#else
121 /* AIX, BSD, Solaris, and Unknown OS ------------------------ */ 115 /* AIX, BSD, Solaris, and Unknown OS ------------------------ */
122 return (size_t)0L; /* Unsupported. */ 116 return (size_t)0L; /* Unsupported. */
123#endif 117#endif
124} 118}
diff --git a/tests/getrssusage.h b/tests/getrssusage.h
index e47b14c..bc3d91e 100644
--- a/tests/getrssusage.h
+++ b/tests/getrssusage.h
@@ -22,7 +22,7 @@
22#if defined(__APPLE__) && defined(__MACH__) 22#if defined(__APPLE__) && defined(__MACH__)
23#include <mach/mach.h> 23#include <mach/mach.h>
24 24
25#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__))) 25#elif(defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
26#include <fcntl.h> 26#include <fcntl.h>
27#include <procfs.h> 27#include <procfs.h>
28 28
diff --git a/tests/indextest.cpp b/tests/indextest.cpp
index 1676ecb..fa3ace4 100644
--- a/tests/indextest.cpp
+++ b/tests/indextest.cpp
@@ -29,42 +29,29 @@ private slots:
29 void testIndex() 29 void testIndex()
30 { 30 {
31 Index index("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite); 31 Index index("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite);
32 //The first key is specifically a substring of the second key 32 // The first key is specifically a substring of the second key
33 index.add("key", "value1"); 33 index.add("key", "value1");
34 index.add("keyFoo", "value2"); 34 index.add("keyFoo", "value2");
35 index.add("keyFoo", "value3"); 35 index.add("keyFoo", "value3");
36 36
37 { 37 {
38 QList<QByteArray> values; 38 QList<QByteArray> values;
39 index.lookup(QByteArray("key"), [&values](const QByteArray &value) { 39 index.lookup(QByteArray("key"), [&values](const QByteArray &value) { values << value; }, [](const Index::Error &error) { qWarning() << "Error: "; });
40 values << value;
41 },
42 [](const Index::Error &error){ qWarning() << "Error: "; });
43 QCOMPARE(values.size(), 1); 40 QCOMPARE(values.size(), 1);
44 } 41 }
45 { 42 {
46 QList<QByteArray> values; 43 QList<QByteArray> values;
47 index.lookup(QByteArray("keyFoo"), [&values](const QByteArray &value) { 44 index.lookup(QByteArray("keyFoo"), [&values](const QByteArray &value) { values << value; }, [](const Index::Error &error) { qWarning() << "Error: "; });
48 values << value;
49 },
50 [](const Index::Error &error){ qWarning() << "Error: "; });
51 QCOMPARE(values.size(), 2); 45 QCOMPARE(values.size(), 2);
52 } 46 }
53 { 47 {
54 QList<QByteArray> values; 48 QList<QByteArray> values;
55 index.lookup(QByteArray("key3"), [&values](const QByteArray &value) { 49 index.lookup(QByteArray("key3"), [&values](const QByteArray &value) { values << value; }, [](const Index::Error &error) { qWarning() << "Error: "; });
56 values << value;
57 },
58 [](const Index::Error &error){ qWarning() << "Error: "; });
59 QCOMPARE(values.size(), 0); 50 QCOMPARE(values.size(), 0);
60 } 51 }
61 { 52 {
62 QList<QByteArray> values; 53 QList<QByteArray> values;
63 index.lookup(QByteArray("key"), [&values](const QByteArray &value) { 54 index.lookup(QByteArray("key"), [&values](const QByteArray &value) { values << value; }, [](const Index::Error &error) { qWarning() << "Error: "; }, true);
64 values << value;
65 },
66 [](const Index::Error &error){ qWarning() << "Error: "; },
67 true);
68 QCOMPARE(values.size(), 3); 55 QCOMPARE(values.size(), 3);
69 } 56 }
70 } 57 }
diff --git a/tests/inspectiontest.cpp b/tests/inspectiontest.cpp
index cdf62e6..38bf23d 100644
--- a/tests/inspectiontest.cpp
+++ b/tests/inspectiontest.cpp
@@ -41,7 +41,7 @@ private slots:
41 41
42 Mail mail(QByteArray("org.kde.dummy.instance1"), QByteArray("identifier"), 0, QSharedPointer<MemoryBufferAdaptor::MemoryBufferAdaptor>::create()); 42 Mail mail(QByteArray("org.kde.dummy.instance1"), QByteArray("identifier"), 0, QSharedPointer<MemoryBufferAdaptor::MemoryBufferAdaptor>::create());
43 43
44 //testInspection is a magic property that the dummyresource supports 44 // testInspection is a magic property that the dummyresource supports
45 auto inspectionCommand = ResourceControl::Inspection::PropertyInspection(mail, "testInspection", success); 45 auto inspectionCommand = ResourceControl::Inspection::PropertyInspection(mail, "testInspection", success);
46 auto result = ResourceControl::inspect<Mail>(inspectionCommand).exec(); 46 auto result = ResourceControl::inspect<Mail>(inspectionCommand).exec();
47 result.waitForFinished(); 47 result.waitForFinished();
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp
index d5f7f95..b5c1c3c 100644
--- a/tests/maildirresourcetest.cpp
+++ b/tests/maildirresourcetest.cpp
@@ -12,8 +12,7 @@
12#include "pipeline.h" 12#include "pipeline.h"
13#include "log.h" 13#include "log.h"
14 14
15static bool copyRecursively(const QString &srcFilePath, 15static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
16 const QString &tgtFilePath)
17{ 16{
18 QFileInfo srcFileInfo(srcFilePath); 17 QFileInfo srcFileInfo(srcFilePath);
19 if (srcFileInfo.isDir()) { 18 if (srcFileInfo.isDir()) {
@@ -26,10 +25,8 @@ static bool copyRecursively(const QString &srcFilePath,
26 QDir sourceDir(srcFilePath); 25 QDir sourceDir(srcFilePath);
27 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); 26 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
28 foreach (const QString &fileName, fileNames) { 27 foreach (const QString &fileName, fileNames) {
29 const QString newSrcFilePath 28 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
30 = srcFilePath + QLatin1Char('/') + fileName; 29 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
31 const QString newTgtFilePath
32 = tgtFilePath + QLatin1Char('/') + fileName;
33 if (!copyRecursively(newSrcFilePath, newTgtFilePath)) 30 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
34 return false; 31 return false;
35 } 32 }
@@ -44,7 +41,7 @@ static bool copyRecursively(const QString &srcFilePath,
44 41
45/** 42/**
46 * Test of complete system using the maildir resource. 43 * Test of complete system using the maildir resource.
47 * 44 *
48 * This test requires the maildir resource installed. 45 * This test requires the maildir resource installed.
49 */ 46 */
50class MaildirResourceTest : public QObject 47class MaildirResourceTest : public QObject
@@ -89,7 +86,7 @@ private slots:
89 Sink::Query query; 86 Sink::Query query;
90 query.resources << "org.kde.maildir.instance1"; 87 query.resources << "org.kde.maildir.instance1";
91 88
92 //Ensure all local data is processed 89 // Ensure all local data is processed
93 Sink::Store::synchronize(query).exec().waitForFinished(); 90 Sink::Store::synchronize(query).exec().waitForFinished();
94 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 91 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
95 92
@@ -104,7 +101,7 @@ private slots:
104 query.resources << "org.kde.maildir.instance1"; 101 query.resources << "org.kde.maildir.instance1";
105 query.parentProperty = "parent"; 102 query.parentProperty = "parent";
106 103
107 //Ensure all local data is processed 104 // Ensure all local data is processed
108 Sink::Store::synchronize(query).exec().waitForFinished(); 105 Sink::Store::synchronize(query).exec().waitForFinished();
109 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 106 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
110 107
@@ -121,23 +118,18 @@ private slots:
121 { 118 {
122 using namespace Sink; 119 using namespace Sink;
123 using namespace Sink::ApplicationDomain; 120 using namespace Sink::ApplicationDomain;
124 //Ensure all local data is processed 121 // Ensure all local data is processed
125 auto query = Query::ResourceFilter("org.kde.maildir.instance1"); 122 auto query = Query::ResourceFilter("org.kde.maildir.instance1");
126 Store::synchronize(query).exec().waitForFinished(); 123 Store::synchronize(query).exec().waitForFinished();
127 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 124 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
128 auto result = Store::fetchOne<Folder>( 125 auto result = Store::fetchOne<Folder>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name"))
129 Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name") 126 .then<QList<Mail::Ptr>, Folder>([](const Folder &folder) {
130 ) 127 Trace() << "Found a folder" << folder.identifier();
131 .then<QList<Mail::Ptr>, Folder>([](const Folder &folder) { 128 return Store::fetchAll<Mail>(Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder"
132 Trace() << "Found a folder" << folder.identifier(); 129 << "subject"));
133 return Store::fetchAll<Mail>( 130 })
134 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 131 .then<void, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { QVERIFY(mails.size() >= 1); })
135 ); 132 .exec();
136 })
137 .then<void, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) {
138 QVERIFY(mails.size() >= 1);
139 })
140 .exec();
141 result.waitForFinished(); 133 result.waitForFinished();
142 QVERIFY(!result.errorCode()); 134 QVERIFY(!result.errorCode());
143 } 135 }
@@ -146,9 +138,12 @@ private slots:
146 { 138 {
147 Sink::Query query; 139 Sink::Query query;
148 query.resources << "org.kde.maildir.instance1"; 140 query.resources << "org.kde.maildir.instance1";
149 query.requestedProperties << "folder" << "subject" << "mimeMessage" << "date"; 141 query.requestedProperties << "folder"
142 << "subject"
143 << "mimeMessage"
144 << "date";
150 145
151 //Ensure all local data is processed 146 // Ensure all local data is processed
152 Sink::Store::synchronize(query).exec().waitForFinished(); 147 Sink::Store::synchronize(query).exec().waitForFinished();
153 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 148 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
154 149
@@ -171,7 +166,7 @@ private slots:
171 query.resources << "org.kde.maildir.instance1"; 166 query.resources << "org.kde.maildir.instance1";
172 query.requestedProperties << "name"; 167 query.requestedProperties << "name";
173 168
174 //Ensure all local data is processed 169 // Ensure all local data is processed
175 Sink::Store::synchronize(query).exec().waitForFinished(); 170 Sink::Store::synchronize(query).exec().waitForFinished();
176 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 171 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
177 172
@@ -179,7 +174,7 @@ private slots:
179 QDir dir(targetPath); 174 QDir dir(targetPath);
180 QVERIFY(dir.rename("inbox", "newbox")); 175 QVERIFY(dir.rename("inbox", "newbox"));
181 176
182 //Ensure all local data is processed 177 // Ensure all local data is processed
183 Sink::Store::synchronize(query).exec().waitForFinished(); 178 Sink::Store::synchronize(query).exec().waitForFinished();
184 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 179 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
185 180
@@ -193,13 +188,14 @@ private slots:
193 { 188 {
194 Sink::Query query; 189 Sink::Query query;
195 query.resources << "org.kde.maildir.instance1"; 190 query.resources << "org.kde.maildir.instance1";
196 query.requestedProperties << "folder" << "subject"; 191 query.requestedProperties << "folder"
192 << "subject";
197 193
198 //Ensure all local data is processed 194 // Ensure all local data is processed
199 Sink::Store::synchronize(query).exec().waitForFinished(); 195 Sink::Store::synchronize(query).exec().waitForFinished();
200 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 196 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
201 197
202 //Ensure all local data is processed 198 // Ensure all local data is processed
203 Sink::Store::synchronize(query).exec().waitForFinished(); 199 Sink::Store::synchronize(query).exec().waitForFinished();
204 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 200 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
205 201
@@ -212,9 +208,10 @@ private slots:
212 { 208 {
213 Sink::Query query; 209 Sink::Query query;
214 query.resources << "org.kde.maildir.instance1"; 210 query.resources << "org.kde.maildir.instance1";
215 query.requestedProperties << "folder" << "subject"; 211 query.requestedProperties << "folder"
212 << "subject";
216 213
217 //Ensure all local data is processed 214 // Ensure all local data is processed
218 Sink::Store::synchronize(query).exec().waitForFinished(); 215 Sink::Store::synchronize(query).exec().waitForFinished();
219 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 216 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
220 217
@@ -222,7 +219,7 @@ private slots:
222 QFile file(targetPath); 219 QFile file(targetPath);
223 QVERIFY(file.remove()); 220 QVERIFY(file.remove());
224 221
225 //Ensure all local data is processed 222 // Ensure all local data is processed
226 Sink::Store::synchronize(query).exec().waitForFinished(); 223 Sink::Store::synchronize(query).exec().waitForFinished();
227 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 224 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
228 225
@@ -236,7 +233,7 @@ private slots:
236 Sink::Query query; 233 Sink::Query query;
237 query.resources << "org.kde.maildir.instance1"; 234 query.resources << "org.kde.maildir.instance1";
238 235
239 //Ensure all local data is processed 236 // Ensure all local data is processed
240 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 237 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
241 238
242 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); 239 Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1");
@@ -244,7 +241,7 @@ private slots:
244 241
245 Sink::Store::create(folder).exec().waitForFinished(); 242 Sink::Store::create(folder).exec().waitForFinished();
246 243
247 //Ensure all local data is processed 244 // Ensure all local data is processed
248 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 245 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
249 246
250 auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; 247 auto targetPath = tempDir.path() + "/maildir1/testCreateFolder";
@@ -284,16 +281,16 @@ private slots:
284 Sink::Query query; 281 Sink::Query query;
285 query.resources << "org.kde.maildir.instance1"; 282 query.resources << "org.kde.maildir.instance1";
286 283
287 //Ensure all local data is processed 284 // Ensure all local data is processed
288 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 285 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
289 286
290 Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); 287 Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1");
291 mail.setProperty("name", "testCreateMail"); 288 mail.setProperty("name", "testCreateMail");
292 //FIXME instead of properties, ensure the mimeMessage property is used and the file is moved as expected 289 // FIXME instead of properties, ensure the mimeMessage property is used and the file is moved as expected
293 290
294 Sink::Store::create(mail).exec().waitForFinished(); 291 Sink::Store::create(mail).exec().waitForFinished();
295 292
296 //Ensure all local data is processed 293 // Ensure all local data is processed
297 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 294 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
298 295
299 auto targetPath = tempDir.path() + "/maildir1/new"; 296 auto targetPath = tempDir.path() + "/maildir1/new";
@@ -312,25 +309,23 @@ private slots:
312 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 309 ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
313 310
314 auto result = Store::fetchOne<Folder>( 311 auto result = Store::fetchOne<Folder>(
315 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 312 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name"))
316 ) 313 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) {
317 .then<void, KAsync::Job<void>, Folder>([query](const Folder &folder) { 314 return Store::fetchAll<Mail>(Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder"
318 return Store::fetchAll<Mail>( 315 << "subject"))
319 Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 316 .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) {
320 ) 317 // Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
321 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 318 if (mails.size() != 1) {
322 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 319 return KAsync::error<void>(1, "Wrong number of mails.");
323 if (mails.size() != 1) { 320 }
324 return KAsync::error<void>(1, "Wrong number of mails."); 321 auto mail = mails.first();
325 } 322
326 auto mail = mails.first(); 323 return Store::remove(*mail)
327 324 .then(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already
328 return Store::remove(*mail) 325 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false)));
329 .then(ResourceControl::flushReplayQueue(query.resources)) //The change needs to be replayed already 326 });
330 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::ExistenceInspection(*mail, false))); 327 })
331 }); 328 .exec();
332 })
333 .exec();
334 result.waitForFinished(); 329 result.waitForFinished();
335 QVERIFY(!result.errorCode()); 330 QVERIFY(!result.errorCode());
336 } 331 }
@@ -347,61 +342,61 @@ private slots:
347 Folder f; 342 Folder f;
348 343
349 auto result = Store::fetchOne<Folder>( 344 auto result = Store::fetchOne<Folder>(
350 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") 345 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name"))
351 ) 346 .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) {
352 .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) { 347 f = folder;
353 f = folder; 348 return Store::fetchAll<Mail>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) +
354 return Store::fetchAll<Mail>( 349 Query::RequestedProperties(QByteArrayList() << "folder"
355 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") 350 << "subject"))
356 ) 351 .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) {
357 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([query](const QList<Mail::Ptr> &mails) { 352 // Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
358 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 353 if (mails.size() != 1) {
359 if (mails.size() != 1) { 354 return KAsync::error<void>(1, "Wrong number of mails.");
360 return KAsync::error<void>(1, "Wrong number of mails."); 355 }
361 } 356 auto mail = mails.first();
362 auto mail = mails.first(); 357 mail->setProperty("unread", true);
363 mail->setProperty("unread", true); 358 return Store::modify(*mail)
364 return Store::modify(*mail) 359 .then<void>(ResourceControl::flushReplayQueue(query.resources)) // The change needs to be replayed already
365 .then<void>(ResourceControl::flushReplayQueue(query.resources)) //The change needs to be replayed already 360 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "unread", true)))
366 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "unread", true))) 361 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject"))));
367 .then(ResourceControl::inspect<Mail>(ResourceControl::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject")))); 362 });
368 }); 363 })
369 }) 364 .exec();
370 .exec();
371 result.waitForFinished(); 365 result.waitForFinished();
372 QVERIFY(!result.errorCode()); 366 QVERIFY(!result.errorCode());
373 367
374 //Verify that we can still query for all relevant information 368 // Verify that we can still query for all relevant information
375 auto result2 = Store::fetchAll<Mail>( 369 auto result2 = Store::fetchAll<Mail>(
376 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject" << "mimeMessage" << "unread") 370 Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder"
377 ) 371 << "subject"
378 .then<void, KAsync::Job<void>, QList<Mail::Ptr> >([](const QList<Mail::Ptr> &mails) { 372 << "mimeMessage"
379 //Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE 373 << "unread"))
380 if (mails.size() != 1) { 374 .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) {
381 qWarning() << "Wrong number of mails"; 375 // Can't use QCOMPARE because it tries to return FIXME Implement ASYNCCOMPARE
382 return KAsync::error<void>(1, "Wrong number of mails."); 376 if (mails.size() != 1) {
383 } 377 qWarning() << "Wrong number of mails";
384 auto mail = mails.first(); 378 return KAsync::error<void>(1, "Wrong number of mails.");
385 if (mail->getProperty("subject").toString().isEmpty()) { 379 }
386 qWarning() << "Wrong subject"; 380 auto mail = mails.first();
387 return KAsync::error<void>(1, "Wrong subject."); 381 if (mail->getProperty("subject").toString().isEmpty()) {
388 } 382 qWarning() << "Wrong subject";
389 if (mail->getProperty("unread").toBool() != true) { 383 return KAsync::error<void>(1, "Wrong subject.");
390 qWarning() << "Not unread"; 384 }
391 return KAsync::error<void>(1, "Not unread."); 385 if (mail->getProperty("unread").toBool() != true) {
392 } 386 qWarning() << "Not unread";
393 QFileInfo info(mail->getProperty("mimeMessage").toString()); 387 return KAsync::error<void>(1, "Not unread.");
394 if (!info.exists()) { 388 }
395 qWarning() << "Wrong subject"; 389 QFileInfo info(mail->getProperty("mimeMessage").toString());
396 return KAsync::error<void>(1, "Can't find mime message."); 390 if (!info.exists()) {
397 } 391 qWarning() << "Wrong subject";
398 return KAsync::null<void>(); 392 return KAsync::error<void>(1, "Can't find mime message.");
399 }) 393 }
400 .exec(); 394 return KAsync::null<void>();
395 })
396 .exec();
401 result2.waitForFinished(); 397 result2.waitForFinished();
402 QVERIFY(!result2.errorCode()); 398 QVERIFY(!result2.errorCode());
403 } 399 }
404
405}; 400};
406 401
407QTEST_MAIN(MaildirResourceTest) 402QTEST_MAIN(MaildirResourceTest)
diff --git a/tests/maildirsyncbenchmark.cpp b/tests/maildirsyncbenchmark.cpp
index 7904a82..06c5ab1 100644
--- a/tests/maildirsyncbenchmark.cpp
+++ b/tests/maildirsyncbenchmark.cpp
@@ -16,8 +16,7 @@
16#include "log.h" 16#include "log.h"
17 17
18 18
19static bool copyRecursively(const QString &srcFilePath, 19static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
20 const QString &tgtFilePath)
21{ 20{
22 QFileInfo srcFileInfo(srcFilePath); 21 QFileInfo srcFileInfo(srcFilePath);
23 if (srcFileInfo.isDir()) { 22 if (srcFileInfo.isDir()) {
@@ -30,10 +29,8 @@ static bool copyRecursively(const QString &srcFilePath,
30 QDir sourceDir(srcFilePath); 29 QDir sourceDir(srcFilePath);
31 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); 30 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
32 foreach (const QString &fileName, fileNames) { 31 foreach (const QString &fileName, fileNames) {
33 const QString newSrcFilePath 32 const QString newSrcFilePath = srcFilePath + QLatin1Char('/') + fileName;
34 = srcFilePath + QLatin1Char('/') + fileName; 33 const QString newTgtFilePath = tgtFilePath + QLatin1Char('/') + fileName;
35 const QString newTgtFilePath
36 = tgtFilePath + QLatin1Char('/') + fileName;
37 if (!copyRecursively(newSrcFilePath, newTgtFilePath)) 34 if (!copyRecursively(newSrcFilePath, newTgtFilePath))
38 return false; 35 return false;
39 } 36 }
@@ -48,7 +45,7 @@ static bool copyRecursively(const QString &srcFilePath,
48 45
49/** 46/**
50 * Test of complete system using the maildir resource. 47 * Test of complete system using the maildir resource.
51 * 48 *
52 * This test requires the maildir resource installed. 49 * This test requires the maildir resource installed.
53 */ 50 */
54class MaildirSyncBenchmark : public QObject 51class MaildirSyncBenchmark : public QObject
@@ -102,7 +99,6 @@ private slots:
102 // row.setValue("totalTime", allProcessedTime); 99 // row.setValue("totalTime", allProcessedTime);
103 // dataset.insertRow(row); 100 // dataset.insertRow(row);
104 // HAWD::Formatter::print(dataset); 101 // HAWD::Formatter::print(dataset);
105
106 } 102 }
107}; 103};
108 104
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp
index ea919ac..6b93863 100644
--- a/tests/mailquerybenchmark.cpp
+++ b/tests/mailquerybenchmark.cpp
@@ -61,9 +61,9 @@ class MailQueryBenchmark : public QObject
61 auto pipeline = QSharedPointer<Sink::Pipeline>::create(resourceIdentifier); 61 auto pipeline = QSharedPointer<Sink::Pipeline>::create(resourceIdentifier);
62 62
63 auto mailFactory = QSharedPointer<TestMailAdaptorFactory>::create(); 63 auto mailFactory = QSharedPointer<TestMailAdaptorFactory>::create();
64 auto indexer = QSharedPointer<DefaultIndexUpdater<Sink::ApplicationDomain::Mail> >::create(); 64 auto indexer = QSharedPointer<DefaultIndexUpdater<Sink::ApplicationDomain::Mail>>::create();
65 65
66 pipeline->setPreprocessors("mail", QVector<Sink::Preprocessor*>() << indexer.data()); 66 pipeline->setPreprocessors("mail", QVector<Sink::Preprocessor *>() << indexer.data());
67 pipeline->setAdaptorFactory("mail", mailFactory); 67 pipeline->setAdaptorFactory("mail", mailFactory);
68 68
69 auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); 69 auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create();
@@ -88,11 +88,11 @@ class MailQueryBenchmark : public QObject
88 const auto startingRss = getCurrentRSS(); 88 const auto startingRss = getCurrentRSS();
89 89
90 90
91 //Benchmark 91 // Benchmark
92 QTime time; 92 QTime time;
93 time.start(); 93 time.start();
94 94
95 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Mail::Ptr> >::create(); 95 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Mail::Ptr>>::create();
96 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 96 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
97 TestMailResourceFacade facade(resourceIdentifier, resourceAccess); 97 TestMailResourceFacade facade(resourceIdentifier, resourceAccess);
98 98
@@ -100,13 +100,9 @@ class MailQueryBenchmark : public QObject
100 ret.first.exec().waitForFinished(); 100 ret.first.exec().waitForFinished();
101 auto emitter = ret.second; 101 auto emitter = ret.second;
102 QList<Sink::ApplicationDomain::Mail::Ptr> list; 102 QList<Sink::ApplicationDomain::Mail::Ptr> list;
103 emitter->onAdded([&list](const Sink::ApplicationDomain::Mail::Ptr &mail) { 103 emitter->onAdded([&list](const Sink::ApplicationDomain::Mail::Ptr &mail) { list << mail; });
104 list << mail;
105 });
106 bool done = false; 104 bool done = false;
107 emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Mail::Ptr &mail) { 105 emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Mail::Ptr &mail) { done = true; });
108 done = true;
109 });
110 emitter->fetch(Sink::ApplicationDomain::Mail::Ptr()); 106 emitter->fetch(Sink::ApplicationDomain::Mail::Ptr());
111 QTRY_VERIFY(done); 107 QTRY_VERIFY(done);
112 QCOMPARE(list.size(), query.limit); 108 QCOMPARE(list.size(), query.limit);
@@ -115,32 +111,32 @@ class MailQueryBenchmark : public QObject
115 111
116 const auto finalRss = getCurrentRSS(); 112 const auto finalRss = getCurrentRSS();
117 const auto rssGrowth = finalRss - startingRss; 113 const auto rssGrowth = finalRss - startingRss;
118 //Since the database is memory mapped it is attributted to the resident set size. 114 // Since the database is memory mapped it is attributted to the resident set size.
119 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), resourceIdentifier, Sink::Storage::ReadWrite).diskUsage(); 115 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), resourceIdentifier, Sink::Storage::ReadWrite).diskUsage();
120 const auto peakRss = getPeakRSS(); 116 const auto peakRss = getPeakRSS();
121 //How much peak deviates from final rss in percent (should be around 0) 117 // How much peak deviates from final rss in percent (should be around 0)
122 const auto percentageRssError = static_cast<double>(peakRss - finalRss)*100.0/static_cast<double>(finalRss); 118 const auto percentageRssError = static_cast<double>(peakRss - finalRss) * 100.0 / static_cast<double>(finalRss);
123 auto rssGrowthPerEntity = rssGrowth/count; 119 auto rssGrowthPerEntity = rssGrowth / count;
124 120
125 std::cout << "Loaded " << list.size() << " results." << std::endl; 121 std::cout << "Loaded " << list.size() << " results." << std::endl;
126 std::cout << "The query took [ms]: " << elapsed << std::endl; 122 std::cout << "The query took [ms]: " << elapsed << std::endl;
127 std::cout << "Current Rss usage [kb]: " << finalRss/1024 << std::endl; 123 std::cout << "Current Rss usage [kb]: " << finalRss / 1024 << std::endl;
128 std::cout << "Peak Rss usage [kb]: " << peakRss/1024 << std::endl; 124 std::cout << "Peak Rss usage [kb]: " << peakRss / 1024 << std::endl;
129 std::cout << "Rss growth [kb]: " << rssGrowth/1024 << std::endl; 125 std::cout << "Rss growth [kb]: " << rssGrowth / 1024 << std::endl;
130 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl; 126 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl;
131 std::cout << "Rss without db [kb]: " << rssWithoutDb/1024 << std::endl; 127 std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl;
132 std::cout << "Percentage error: " << percentageRssError << std::endl; 128 std::cout << "Percentage error: " << percentageRssError << std::endl;
133 129
134 HAWD::Dataset dataset("mail_query", mHawdState); 130 HAWD::Dataset dataset("mail_query", mHawdState);
135 HAWD::Dataset::Row row = dataset.row(); 131 HAWD::Dataset::Row row = dataset.row();
136 row.setValue("rows", list.size()); 132 row.setValue("rows", list.size());
137 row.setValue("queryResultPerMs", (qreal)list.size()/elapsed); 133 row.setValue("queryResultPerMs", (qreal)list.size() / elapsed);
138 dataset.insertRow(row); 134 dataset.insertRow(row);
139 HAWD::Formatter::print(dataset); 135 HAWD::Formatter::print(dataset);
140 136
141 QVERIFY(percentageRssError < 10); 137 QVERIFY(percentageRssError < 10);
142 //TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase, 138 // TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase,
143 //so it doesn't look like that memory is being duplicated. 139 // so it doesn't look like that memory is being duplicated.
144 QVERIFY(rssGrowthPerEntity < 3300); 140 QVERIFY(rssGrowthPerEntity < 3300);
145 141
146 // Print memory layout, RSS is what is in memory 142 // Print memory layout, RSS is what is in memory
@@ -159,7 +155,9 @@ private slots:
159 { 155 {
160 Sink::Query query; 156 Sink::Query query;
161 query.liveQuery = false; 157 query.liveQuery = false;
162 query.requestedProperties << "uid" << "subject" << "date"; 158 query.requestedProperties << "uid"
159 << "subject"
160 << "date";
163 query.sortProperty = "date"; 161 query.sortProperty = "date";
164 query.propertyFilter.insert("folder", "folder1"); 162 query.propertyFilter.insert("folder", "folder1");
165 query.limit = 1000; 163 query.limit = 1000;
@@ -167,7 +165,6 @@ private slots:
167 populateDatabase(50000); 165 populateDatabase(50000);
168 testLoad(query, 50000); 166 testLoad(query, 50000);
169 } 167 }
170
171}; 168};
172 169
173QTEST_MAIN(MailQueryBenchmark) 170QTEST_MAIN(MailQueryBenchmark)
diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp
index 06a4ae6..484ff86 100644
--- a/tests/messagequeuetest.cpp
+++ b/tests/messagequeuetest.cpp
@@ -45,12 +45,7 @@ private slots:
45 MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); 45 MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue");
46 bool gotValue = false; 46 bool gotValue = false;
47 bool gotError = false; 47 bool gotError = false;
48 queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { 48 queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { gotValue = true; }, [&](const MessageQueue::Error &error) { gotError = true; });
49 gotValue = true;
50 },
51 [&](const MessageQueue::Error &error) {
52 gotError = true;
53 });
54 QVERIFY(!gotValue); 49 QVERIFY(!gotValue);
55 QVERIFY(!gotError); 50 QVERIFY(!gotError);
56 } 51 }
@@ -69,9 +64,7 @@ private slots:
69 QSignalSpy spy(&queue, SIGNAL(drained())); 64 QSignalSpy spy(&queue, SIGNAL(drained()));
70 queue.enqueue("value1"); 65 queue.enqueue("value1");
71 66
72 queue.dequeue([](void *ptr, int size, std::function<void(bool success)> callback) { 67 queue.dequeue([](void *ptr, int size, std::function<void(bool success)> callback) { callback(true); }, [](const MessageQueue::Error &error) {});
73 callback(true);
74 }, [](const MessageQueue::Error &error) {});
75 QCOMPARE(spy.size(), 1); 68 QCOMPARE(spy.size(), 1);
76 } 69 }
77 70
@@ -91,15 +84,14 @@ private slots:
91 const auto expected = values.dequeue(); 84 const auto expected = values.dequeue();
92 bool gotValue = false; 85 bool gotValue = false;
93 bool gotError = false; 86 bool gotError = false;
94 queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { 87 queue.dequeue(
95 if (QByteArray(static_cast<char*>(ptr), size) == expected) { 88 [&](void *ptr, int size, std::function<void(bool success)> callback) {
96 gotValue = true; 89 if (QByteArray(static_cast<char *>(ptr), size) == expected) {
97 } 90 gotValue = true;
98 callback(true); 91 }
99 }, 92 callback(true);
100 [&](const MessageQueue::Error &error) { 93 },
101 gotError = true; 94 [&](const MessageQueue::Error &error) { gotError = true; });
102 });
103 QVERIFY(gotValue); 95 QVERIFY(gotValue);
104 QVERIFY(!gotError); 96 QVERIFY(!gotError);
105 } 97 }
@@ -123,22 +115,21 @@ private slots:
123 bool gotValue = false; 115 bool gotValue = false;
124 bool gotError = false; 116 bool gotError = false;
125 117
126 queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { 118 queue.dequeue(
127 if (QByteArray(static_cast<char*>(ptr), size) == expected) { 119 [&](void *ptr, int size, std::function<void(bool success)> callback) {
128 gotValue = true; 120 if (QByteArray(static_cast<char *>(ptr), size) == expected) {
129 } 121 gotValue = true;
130 auto timer = new QTimer(); 122 }
131 timer->setSingleShot(true); 123 auto timer = new QTimer();
132 QObject::connect(timer, &QTimer::timeout, [timer, callback, &eventLoop]() { 124 timer->setSingleShot(true);
133 delete timer; 125 QObject::connect(timer, &QTimer::timeout, [timer, callback, &eventLoop]() {
134 callback(true); 126 delete timer;
135 eventLoop.exit(); 127 callback(true);
136 }); 128 eventLoop.exit();
137 timer->start(0); 129 });
138 }, 130 timer->start(0);
139 [&](const MessageQueue::Error &error) { 131 },
140 gotError = true; 132 [&](const MessageQueue::Error &error) { gotError = true; });
141 });
142 eventLoop.exec(); 133 eventLoop.exec();
143 QVERIFY(gotValue); 134 QVERIFY(gotValue);
144 QVERIFY(!gotError); 135 QVERIFY(!gotError);
@@ -155,13 +146,12 @@ private slots:
155 queue.enqueue("value1"); 146 queue.enqueue("value1");
156 147
157 bool gotError = false; 148 bool gotError = false;
158 queue.dequeue([&](void *ptr, int size, std::function<void(bool success)> callback) { 149 queue.dequeue(
159 queue.enqueue("value3"); 150 [&](void *ptr, int size, std::function<void(bool success)> callback) {
160 callback(true); 151 queue.enqueue("value3");
161 }, 152 callback(true);
162 [&](const MessageQueue::Error &error) { 153 },
163 gotError = true; 154 [&](const MessageQueue::Error &error) { gotError = true; });
164 });
165 QVERIFY(!gotError); 155 QVERIFY(!gotError);
166 } 156 }
167 157
@@ -174,15 +164,15 @@ private slots:
174 164
175 int count = 0; 165 int count = 0;
176 queue.dequeueBatch(2, [&count](const QByteArray &data) { 166 queue.dequeueBatch(2, [&count](const QByteArray &data) {
177 count++; 167 count++;
178 return KAsync::null<void>(); 168 return KAsync::null<void>();
179 }).exec().waitForFinished(); 169 }).exec().waitForFinished();
180 QCOMPARE(count, 2); 170 QCOMPARE(count, 2);
181 171
182 queue.dequeueBatch(1, [&count](const QByteArray &data) { 172 queue.dequeueBatch(1, [&count](const QByteArray &data) {
183 count++; 173 count++;
184 return KAsync::null<void>(); 174 return KAsync::null<void>();
185 }).exec().waitForFinished(); 175 }).exec().waitForFinished();
186 QCOMPARE(count, 3); 176 QCOMPARE(count, 3);
187 } 177 }
188 178
@@ -203,7 +193,6 @@ private slots:
203 QVERIFY(!queue.isEmpty()); 193 QVERIFY(!queue.isEmpty());
204 QCOMPARE(spy.count(), 1); 194 QCOMPARE(spy.count(), 1);
205 } 195 }
206
207}; 196};
208 197
209QTEST_MAIN(MessageQueueTest) 198QTEST_MAIN(MessageQueueTest)
diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp
index ad23e0f..d0a0920 100644
--- a/tests/modelinteractivitytest.cpp
+++ b/tests/modelinteractivitytest.cpp
@@ -16,20 +16,23 @@ static int blockingTime;
16class TimeMeasuringApplication : public QCoreApplication 16class TimeMeasuringApplication : public QCoreApplication
17{ 17{
18 QElapsedTimer t; 18 QElapsedTimer t;
19
19public: 20public:
20 TimeMeasuringApplication(int& argc, char ** argv) : QCoreApplication(argc, argv) { } 21 TimeMeasuringApplication(int &argc, char **argv) : QCoreApplication(argc, argv)
21 virtual ~TimeMeasuringApplication() { } 22 {
23 }
24 virtual ~TimeMeasuringApplication()
25 {
26 }
22 27
23 virtual bool notify(QObject* receiver, QEvent* event) 28 virtual bool notify(QObject *receiver, QEvent *event)
24 { 29 {
25 t.start(); 30 t.start();
26 const bool ret = QCoreApplication::notify(receiver, event); 31 const bool ret = QCoreApplication::notify(receiver, event);
27 if(t.elapsed() > 1) 32 if (t.elapsed() > 1)
28 std::cout << QString("processing event type %1 for object %2 took %3ms") 33 std::cout
29 .arg((int)event->type()) 34 << QString("processing event type %1 for object %2 took %3ms").arg((int)event->type()).arg("" /* receiver->objectName().toLocal8Bit().data()*/).arg((int)t.elapsed()).toStdString()
30 .arg(""/* receiver->objectName().toLocal8Bit().data()*/) 35 << std::endl;
31 .arg((int)t.elapsed())
32 .toStdString() << std::endl;
33 blockingTime += t.elapsed(); 36 blockingTime += t.elapsed();
34 return ret; 37 return ret;
35 } 38 }
@@ -62,7 +65,7 @@ private slots:
62 65
63 void testSingle() 66 void testSingle()
64 { 67 {
65 //Setup 68 // Setup
66 { 69 {
67 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); 70 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
68 for (int i = 0; i < 1000; i++) { 71 for (int i = 0; i < 1000; i++) {
@@ -76,13 +79,13 @@ private slots:
76 79
77 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 80 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
78 81
79 //Test 82 // Test
80 QTime time; 83 QTime time;
81 time.start(); 84 time.start();
82 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 85 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
83 blockingTime += time.elapsed(); 86 blockingTime += time.elapsed();
84 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 87 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
85 //Never block longer than 10 ms 88 // Never block longer than 10 ms
86 QVERIFY2(blockingTime < 10, QString("Total blocking time: %1").arg(blockingTime).toLatin1().data()); 89 QVERIFY2(blockingTime < 10, QString("Total blocking time: %1").arg(blockingTime).toLatin1().data());
87 } 90 }
88}; 91};
diff --git a/tests/pipelinebenchmark.cpp b/tests/pipelinebenchmark.cpp
index 5743830..0133a6c 100644
--- a/tests/pipelinebenchmark.cpp
+++ b/tests/pipelinebenchmark.cpp
@@ -54,7 +54,8 @@
54// } 54// }
55// } 55// }
56// 56//
57// void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 57// void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity,
58// Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
58// { 59// {
59// } 60// }
60// 61//
@@ -66,7 +67,7 @@
66 67
67/** 68/**
68 * Benchmark pipeline processing speed. 69 * Benchmark pipeline processing speed.
69 * 70 *
70 * This benchmark especially highlights: 71 * This benchmark especially highlights:
71 * * Cost of an index in speed and size 72 * * Cost of an index in speed and size
72 */ 73 */
@@ -77,7 +78,7 @@ class PipelineBenchmark : public QObject
77 QByteArray resourceIdentifier; 78 QByteArray resourceIdentifier;
78 HAWD::State mHawdState; 79 HAWD::State mHawdState;
79 80
80 void populateDatabase(int count, const QVector<Sink::Preprocessor*> &preprocessors) 81 void populateDatabase(int count, const QVector<Sink::Preprocessor *> &preprocessors)
81 { 82 {
82 TestResource::removeFromDisk(resourceIdentifier); 83 TestResource::removeFromDisk(resourceIdentifier);
83 84
@@ -112,18 +113,17 @@ class PipelineBenchmark : public QObject
112 // Print memory layout, RSS is what is in memory 113 // Print memory layout, RSS is what is in memory
113 // std::system("exec pmap -x \"$PPID\""); 114 // std::system("exec pmap -x \"$PPID\"");
114 // 115 //
115 std::cout << "Size: " << Sink::Storage(Sink::storageLocation(), resourceIdentifier, Sink::Storage::ReadOnly).diskUsage()/1024 << " [kb]" << std::endl; 116 std::cout << "Size: " << Sink::Storage(Sink::storageLocation(), resourceIdentifier, Sink::Storage::ReadOnly).diskUsage() / 1024 << " [kb]" << std::endl;
116 std::cout << "Time: " << allProcessedTime << " [ms]" << std::endl; 117 std::cout << "Time: " << allProcessedTime << " [ms]" << std::endl;
117 118
118 HAWD::Dataset dataset("pipeline", mHawdState); 119 HAWD::Dataset dataset("pipeline", mHawdState);
119 HAWD::Dataset::Row row = dataset.row(); 120 HAWD::Dataset::Row row = dataset.row();
120 121
121 row.setValue("rows", count); 122 row.setValue("rows", count);
122 row.setValue("append", (qreal)count/appendTime); 123 row.setValue("append", (qreal)count / appendTime);
123 row.setValue("total", (qreal)count/allProcessedTime); 124 row.setValue("total", (qreal)count / allProcessedTime);
124 dataset.insertRow(row); 125 dataset.insertRow(row);
125 HAWD::Formatter::print(dataset); 126 HAWD::Formatter::print(dataset);
126
127 } 127 }
128 128
129private slots: 129private slots:
@@ -136,15 +136,14 @@ private slots:
136 136
137 void testWithoutIndex() 137 void testWithoutIndex()
138 { 138 {
139 populateDatabase(10000, QVector<Sink::Preprocessor*>()); 139 populateDatabase(10000, QVector<Sink::Preprocessor *>());
140 } 140 }
141 141
142 void testWithIndex() 142 void testWithIndex()
143 { 143 {
144 auto indexer = QSharedPointer<DefaultIndexUpdater<Sink::ApplicationDomain::Mail> >::create(); 144 auto indexer = QSharedPointer<DefaultIndexUpdater<Sink::ApplicationDomain::Mail>>::create();
145 populateDatabase(10000, QVector<Sink::Preprocessor*>() << indexer.data()); 145 populateDatabase(10000, QVector<Sink::Preprocessor *>() << indexer.data());
146 } 146 }
147
148}; 147};
149 148
150QTEST_MAIN(PipelineBenchmark) 149QTEST_MAIN(PipelineBenchmark)
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index 92b7554..cdd260d 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -143,7 +143,8 @@ QByteArray deleteEntityCommand(const QByteArray &uid, qint64 revision)
143 return command; 143 return command;
144} 144}
145 145
146class TestProcessor : public Sink::Preprocessor { 146class TestProcessor : public Sink::Preprocessor
147{
147public: 148public:
148 void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 149 void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
149 { 150 {
@@ -151,7 +152,8 @@ public:
151 newRevisions << revision; 152 newRevisions << revision;
152 } 153 }
153 154
154 void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE 155 void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity,
156 Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE
155 { 157 {
156 modifiedUids << uid; 158 modifiedUids << uid;
157 modifiedRevisions << revision; 159 modifiedRevisions << revision;
@@ -214,42 +216,42 @@ private slots:
214 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); 216 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
215 pipeline.setAdaptorFactory("event", adaptorFactory); 217 pipeline.setAdaptorFactory("event", adaptorFactory);
216 218
217 //Create the initial revision 219 // Create the initial revision
218 pipeline.startTransaction(); 220 pipeline.startTransaction();
219 pipeline.newEntity(command.constData(), command.size()); 221 pipeline.newEntity(command.constData(), command.size());
220 pipeline.commit(); 222 pipeline.commit();
221 223
222 //Get uid of written entity 224 // Get uid of written entity
223 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); 225 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
224 QCOMPARE(keys.size(), 1); 226 QCOMPARE(keys.size(), 1);
225 const auto key = keys.first(); 227 const auto key = keys.first();
226 const auto uid = Sink::Storage::uidFromKey(key); 228 const auto uid = Sink::Storage::uidFromKey(key);
227 229
228 //Execute the modification 230 // Execute the modification
229 entityFbb.Clear(); 231 entityFbb.Clear();
230 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); 232 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1);
231 pipeline.startTransaction(); 233 pipeline.startTransaction();
232 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 234 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
233 pipeline.commit(); 235 pipeline.commit();
234 236
235 //Ensure we've got the new revision with the modification 237 // Ensure we've got the new revision with the modification
236 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 2)); 238 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 2));
237 QVERIFY(!buffer.isEmpty()); 239 QVERIFY(!buffer.isEmpty());
238 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 240 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
239 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); 241 auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity());
240 QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary2"), "The modification isn't applied."); 242 QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary2"), "The modification isn't applied.");
241 //Ensure we didn't modify anything else 243 // Ensure we didn't modify anything else
242 QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects."); 244 QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects.");
243 245
244 //Both revisions are in the store at this point 246 // Both revisions are in the store at this point
245 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); 247 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2);
246 248
247 //Cleanup old revisions 249 // Cleanup old revisions
248 pipeline.startTransaction(); 250 pipeline.startTransaction();
249 pipeline.cleanupRevision(2); 251 pipeline.cleanupRevision(2);
250 pipeline.commit(); 252 pipeline.commit();
251 253
252 //And now only the latest revision is left 254 // And now only the latest revision is left
253 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 1); 255 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 1);
254 } 256 }
255 257
@@ -263,18 +265,18 @@ private slots:
263 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); 265 auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
264 pipeline.setAdaptorFactory("event", adaptorFactory); 266 pipeline.setAdaptorFactory("event", adaptorFactory);
265 267
266 //Create the initial revision 268 // Create the initial revision
267 pipeline.startTransaction(); 269 pipeline.startTransaction();
268 pipeline.newEntity(command.constData(), command.size()); 270 pipeline.newEntity(command.constData(), command.size());
269 pipeline.commit(); 271 pipeline.commit();
270 272
271 //Get uid of written entity 273 // Get uid of written entity
272 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); 274 auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main");
273 QCOMPARE(keys.size(), 1); 275 QCOMPARE(keys.size(), 1);
274 const auto uid = Sink::Storage::uidFromKey(keys.first()); 276 const auto uid = Sink::Storage::uidFromKey(keys.first());
275 277
276 278
277 //Create another operation inbetween 279 // Create another operation inbetween
278 { 280 {
279 entityFbb.Clear(); 281 entityFbb.Clear();
280 auto command = createEntityCommand(createEvent(entityFbb)); 282 auto command = createEntityCommand(createEvent(entityFbb));
@@ -283,14 +285,14 @@ private slots:
283 pipeline.commit(); 285 pipeline.commit();
284 } 286 }
285 287
286 //Execute the modification on revision 2 288 // Execute the modification on revision 2
287 entityFbb.Clear(); 289 entityFbb.Clear();
288 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 2); 290 auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 2);
289 pipeline.startTransaction(); 291 pipeline.startTransaction();
290 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 292 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
291 pipeline.commit(); 293 pipeline.commit();
292 294
293 //Ensure we've got the new revision with the modification 295 // Ensure we've got the new revision with the modification
294 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 3)); 296 auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 3));
295 QVERIFY(!buffer.isEmpty()); 297 QVERIFY(!buffer.isEmpty());
296 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); 298 Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size());
@@ -305,7 +307,7 @@ private slots:
305 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); 307 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1");
306 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create()); 308 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
307 309
308 //Create the initial revision 310 // Create the initial revision
309 pipeline.startTransaction(); 311 pipeline.startTransaction();
310 pipeline.newEntity(command.constData(), command.size()); 312 pipeline.newEntity(command.constData(), command.size());
311 pipeline.commit(); 313 pipeline.commit();
@@ -315,21 +317,21 @@ private slots:
315 317
316 const auto uid = Sink::Storage::uidFromKey(result.first()); 318 const auto uid = Sink::Storage::uidFromKey(result.first());
317 319
318 //Delete entity 320 // Delete entity
319 auto deleteCommand = deleteEntityCommand(uid, 1); 321 auto deleteCommand = deleteEntityCommand(uid, 1);
320 pipeline.startTransaction(); 322 pipeline.startTransaction();
321 pipeline.deletedEntity(deleteCommand.constData(), deleteCommand.size()); 323 pipeline.deletedEntity(deleteCommand.constData(), deleteCommand.size());
322 pipeline.commit(); 324 pipeline.commit();
323 325
324 //We have a new revision that indicates the deletion 326 // We have a new revision that indicates the deletion
325 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); 327 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2);
326 328
327 //Cleanup old revisions 329 // Cleanup old revisions
328 pipeline.startTransaction(); 330 pipeline.startTransaction();
329 pipeline.cleanupRevision(2); 331 pipeline.cleanupRevision(2);
330 pipeline.commit(); 332 pipeline.commit();
331 333
332 //And all revisions are gone 334 // And all revisions are gone
333 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0); 335 QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 0);
334 } 336 }
335 337
@@ -340,17 +342,17 @@ private slots:
340 TestProcessor testProcessor; 342 TestProcessor testProcessor;
341 343
342 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); 344 Sink::Pipeline pipeline("org.kde.pipelinetest.instance1");
343 pipeline.setPreprocessors("event", QVector<Sink::Preprocessor*>() << &testProcessor); 345 pipeline.setPreprocessors("event", QVector<Sink::Preprocessor *>() << &testProcessor);
344 pipeline.startTransaction(); 346 pipeline.startTransaction();
345 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create()); 347 pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create());
346 348
347 //Actual test 349 // Actual test
348 { 350 {
349 auto command = createEntityCommand(createEvent(entityFbb)); 351 auto command = createEntityCommand(createEvent(entityFbb));
350 pipeline.newEntity(command.constData(), command.size()); 352 pipeline.newEntity(command.constData(), command.size());
351 QCOMPARE(testProcessor.newUids.size(), 1); 353 QCOMPARE(testProcessor.newUids.size(), 1);
352 QCOMPARE(testProcessor.newRevisions.size(), 1); 354 QCOMPARE(testProcessor.newRevisions.size(), 1);
353 //Key doesn't contain revision and is just the uid 355 // Key doesn't contain revision and is just the uid
354 QCOMPARE(testProcessor.newUids.at(0), Sink::Storage::uidFromKey(testProcessor.newUids.at(0))); 356 QCOMPARE(testProcessor.newUids.at(0), Sink::Storage::uidFromKey(testProcessor.newUids.at(0)));
355 } 357 }
356 pipeline.commit(); 358 pipeline.commit();
@@ -364,7 +366,7 @@ private slots:
364 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); 366 pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size());
365 QCOMPARE(testProcessor.modifiedUids.size(), 1); 367 QCOMPARE(testProcessor.modifiedUids.size(), 1);
366 QCOMPARE(testProcessor.modifiedRevisions.size(), 1); 368 QCOMPARE(testProcessor.modifiedRevisions.size(), 1);
367 //Key doesn't contain revision and is just the uid 369 // Key doesn't contain revision and is just the uid
368 QCOMPARE(testProcessor.modifiedUids.at(0), Sink::Storage::uidFromKey(testProcessor.modifiedUids.at(0))); 370 QCOMPARE(testProcessor.modifiedUids.at(0), Sink::Storage::uidFromKey(testProcessor.modifiedUids.at(0)));
369 } 371 }
370 pipeline.commit(); 372 pipeline.commit();
@@ -376,7 +378,7 @@ private slots:
376 QCOMPARE(testProcessor.deletedUids.size(), 1); 378 QCOMPARE(testProcessor.deletedUids.size(), 1);
377 QCOMPARE(testProcessor.deletedUids.size(), 1); 379 QCOMPARE(testProcessor.deletedUids.size(), 1);
378 QCOMPARE(testProcessor.deletedSummaries.size(), 1); 380 QCOMPARE(testProcessor.deletedSummaries.size(), 1);
379 //Key doesn't contain revision and is just the uid 381 // Key doesn't contain revision and is just the uid
380 QCOMPARE(testProcessor.deletedUids.at(0), Sink::Storage::uidFromKey(testProcessor.deletedUids.at(0))); 382 QCOMPARE(testProcessor.deletedUids.at(0), Sink::Storage::uidFromKey(testProcessor.deletedUids.at(0)));
381 QCOMPARE(testProcessor.deletedSummaries.at(0), QByteArray("summary2")); 383 QCOMPARE(testProcessor.deletedSummaries.at(0), QByteArray("summary2"));
382 } 384 }
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
index 2531c25..7b9129e 100644
--- a/tests/querytest.cpp
+++ b/tests/querytest.cpp
@@ -42,12 +42,12 @@ private slots:
42 42
43 void testNoResources() 43 void testNoResources()
44 { 44 {
45 //Test 45 // Test
46 Sink::Query query; 46 Sink::Query query;
47 query.resources << "foobar"; 47 query.resources << "foobar";
48 query.liveQuery = true; 48 query.liveQuery = true;
49 49
50 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data 50 // We fetch before the data is available and rely on the live query mechanism to deliver the actual data
51 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 51 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
52 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 52 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
53 QCOMPARE(model->rowCount(), 0); 53 QCOMPARE(model->rowCount(), 0);
@@ -56,39 +56,39 @@ private slots:
56 56
57 void testSingle() 57 void testSingle()
58 { 58 {
59 //Setup 59 // Setup
60 { 60 {
61 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); 61 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
62 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); 62 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished();
63 } 63 }
64 64
65 //Test 65 // Test
66 Sink::Query query; 66 Sink::Query query;
67 query.resources << "org.kde.dummy.instance1"; 67 query.resources << "org.kde.dummy.instance1";
68 query.liveQuery = true; 68 query.liveQuery = true;
69 69
70 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data 70 // We fetch before the data is available and rely on the live query mechanism to deliver the actual data
71 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 71 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
72 QTRY_COMPARE(model->rowCount(), 1); 72 QTRY_COMPARE(model->rowCount(), 1);
73 } 73 }
74 74
75 void testSingleWithDelay() 75 void testSingleWithDelay()
76 { 76 {
77 //Setup 77 // Setup
78 { 78 {
79 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); 79 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
80 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); 80 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished();
81 } 81 }
82 82
83 //Test 83 // Test
84 Sink::Query query; 84 Sink::Query query;
85 query.resources << "org.kde.dummy.instance1"; 85 query.resources << "org.kde.dummy.instance1";
86 query.liveQuery = false; 86 query.liveQuery = false;
87 87
88 //Ensure all local data is processed 88 // Ensure all local data is processed
89 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 89 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
90 90
91 //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data 91 // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data
92 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 92 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
93 93
94 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 94 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
@@ -98,7 +98,7 @@ private slots:
98 void testById() 98 void testById()
99 { 99 {
100 QByteArray id; 100 QByteArray id;
101 //Setup 101 // Setup
102 { 102 {
103 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); 103 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
104 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); 104 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished();
@@ -107,17 +107,17 @@ private slots:
107 Sink::Query query; 107 Sink::Query query;
108 query.resources << "org.kde.dummy.instance1"; 108 query.resources << "org.kde.dummy.instance1";
109 109
110 //Ensure all local data is processed 110 // Ensure all local data is processed
111 Sink::Store::synchronize(query).exec().waitForFinished(); 111 Sink::Store::synchronize(query).exec().waitForFinished();
112 112
113 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data 113 // We fetch before the data is available and rely on the live query mechanism to deliver the actual data
114 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 114 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
115 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 115 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
116 QVERIFY(model->rowCount() >= 1); 116 QVERIFY(model->rowCount() >= 1);
117 id = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->identifier(); 117 id = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->identifier();
118 } 118 }
119 119
120 //Test 120 // Test
121 Sink::Query query; 121 Sink::Query query;
122 query.resources << "org.kde.dummy.instance1"; 122 query.resources << "org.kde.dummy.instance1";
123 query.ids << id; 123 query.ids << id;
@@ -128,18 +128,18 @@ private slots:
128 128
129 void testFolder() 129 void testFolder()
130 { 130 {
131 //Setup 131 // Setup
132 { 132 {
133 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); 133 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1");
134 Sink::Store::create<Sink::ApplicationDomain::Folder>(folder).exec().waitForFinished(); 134 Sink::Store::create<Sink::ApplicationDomain::Folder>(folder).exec().waitForFinished();
135 } 135 }
136 136
137 //Test 137 // Test
138 Sink::Query query; 138 Sink::Query query;
139 query.resources << "org.kde.dummy.instance1"; 139 query.resources << "org.kde.dummy.instance1";
140 query.liveQuery = true; 140 query.liveQuery = true;
141 141
142 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data 142 // We fetch before the data is available and rely on the live query mechanism to deliver the actual data
143 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 143 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
144 QTRY_COMPARE(model->rowCount(), 1); 144 QTRY_COMPARE(model->rowCount(), 1);
145 auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); 145 auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>();
@@ -148,7 +148,7 @@ private slots:
148 148
149 void testFolderTree() 149 void testFolderTree()
150 { 150 {
151 //Setup 151 // Setup
152 { 152 {
153 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); 153 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1");
154 Sink::Store::create<Sink::ApplicationDomain::Folder>(folder).exec().waitForFinished(); 154 Sink::Store::create<Sink::ApplicationDomain::Folder>(folder).exec().waitForFinished();
@@ -156,7 +156,7 @@ private slots:
156 Sink::Query query; 156 Sink::Query query;
157 query.resources << "org.kde.dummy.instance1"; 157 query.resources << "org.kde.dummy.instance1";
158 158
159 //Ensure all local data is processed 159 // Ensure all local data is processed
160 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 160 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
161 161
162 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 162 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
@@ -171,15 +171,15 @@ private slots:
171 Sink::Store::create<Sink::ApplicationDomain::Folder>(subfolder).exec().waitForFinished(); 171 Sink::Store::create<Sink::ApplicationDomain::Folder>(subfolder).exec().waitForFinished();
172 } 172 }
173 173
174 //Test 174 // Test
175 Sink::Query query; 175 Sink::Query query;
176 query.resources << "org.kde.dummy.instance1"; 176 query.resources << "org.kde.dummy.instance1";
177 query.parentProperty = "parent"; 177 query.parentProperty = "parent";
178 178
179 //Ensure all local data is processed 179 // Ensure all local data is processed
180 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 180 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
181 181
182 //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data 182 // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data
183 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 183 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
184 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 184 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
185 QCOMPARE(model->rowCount(), 1); 185 QCOMPARE(model->rowCount(), 1);
@@ -190,7 +190,7 @@ private slots:
190 190
191 void testMailByUid() 191 void testMailByUid()
192 { 192 {
193 //Setup 193 // Setup
194 { 194 {
195 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); 195 Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1");
196 mail.setProperty("uid", "test1"); 196 mail.setProperty("uid", "test1");
@@ -198,16 +198,16 @@ private slots:
198 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); 198 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished();
199 } 199 }
200 200
201 //Test 201 // Test
202 Sink::Query query; 202 Sink::Query query;
203 query.resources << "org.kde.dummy.instance1"; 203 query.resources << "org.kde.dummy.instance1";
204 query.liveQuery = false; 204 query.liveQuery = false;
205 query.propertyFilter.insert("uid", "test1"); 205 query.propertyFilter.insert("uid", "test1");
206 206
207 //Ensure all local data is processed 207 // Ensure all local data is processed
208 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 208 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
209 209
210 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data 210 // We fetch before the data is available and rely on the live query mechanism to deliver the actual data
211 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 211 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
212 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 212 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
213 QCOMPARE(model->rowCount(), 1); 213 QCOMPARE(model->rowCount(), 1);
@@ -215,7 +215,7 @@ private slots:
215 215
216 void testMailByFolder() 216 void testMailByFolder()
217 { 217 {
218 //Setup 218 // Setup
219 Sink::ApplicationDomain::Folder::Ptr folderEntity; 219 Sink::ApplicationDomain::Folder::Ptr folderEntity;
220 { 220 {
221 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); 221 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1");
@@ -224,7 +224,7 @@ private slots:
224 Sink::Query query; 224 Sink::Query query;
225 query.resources << "org.kde.dummy.instance1"; 225 query.resources << "org.kde.dummy.instance1";
226 226
227 //Ensure all local data is processed 227 // Ensure all local data is processed
228 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 228 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
229 229
230 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 230 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
@@ -240,15 +240,15 @@ private slots:
240 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished(); 240 Sink::Store::create<Sink::ApplicationDomain::Mail>(mail).exec().waitForFinished();
241 } 241 }
242 242
243 //Test 243 // Test
244 Sink::Query query; 244 Sink::Query query;
245 query.resources << "org.kde.dummy.instance1"; 245 query.resources << "org.kde.dummy.instance1";
246 query.propertyFilter.insert("folder", folderEntity->identifier()); 246 query.propertyFilter.insert("folder", folderEntity->identifier());
247 247
248 //Ensure all local data is processed 248 // Ensure all local data is processed
249 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 249 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
250 250
251 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data 251 // We fetch before the data is available and rely on the live query mechanism to deliver the actual data
252 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 252 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
253 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 253 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
254 QCOMPARE(model->rowCount(), 1); 254 QCOMPARE(model->rowCount(), 1);
@@ -256,7 +256,7 @@ private slots:
256 256
257 void testMailByFolderSortedByDate() 257 void testMailByFolderSortedByDate()
258 { 258 {
259 //Setup 259 // Setup
260 Sink::ApplicationDomain::Folder::Ptr folderEntity; 260 Sink::ApplicationDomain::Folder::Ptr folderEntity;
261 { 261 {
262 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); 262 Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1");
@@ -265,7 +265,7 @@ private slots:
265 Sink::Query query; 265 Sink::Query query;
266 query.resources << "org.kde.dummy.instance1"; 266 query.resources << "org.kde.dummy.instance1";
267 267
268 //Ensure all local data is processed 268 // Ensure all local data is processed
269 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 269 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
270 270
271 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 271 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query);
@@ -299,7 +299,7 @@ private slots:
299 } 299 }
300 } 300 }
301 301
302 //Test 302 // Test
303 Sink::Query query; 303 Sink::Query query;
304 query.resources << "org.kde.dummy.instance1"; 304 query.resources << "org.kde.dummy.instance1";
305 query.propertyFilter.insert("folder", folderEntity->identifier()); 305 query.propertyFilter.insert("folder", folderEntity->identifier());
@@ -307,19 +307,19 @@ private slots:
307 query.limit = 1; 307 query.limit = 1;
308 query.liveQuery = false; 308 query.liveQuery = false;
309 309
310 //Ensure all local data is processed 310 // Ensure all local data is processed
311 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); 311 Sink::ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished();
312 312
313 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); 313 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
314 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 314 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
315 //The model is not sorted, but the limited set is sorted, so we can only test for the latest result. 315 // The model is not sorted, but the limited set is sorted, so we can only test for the latest result.
316 QCOMPARE(model->rowCount(), 1); 316 QCOMPARE(model->rowCount(), 1);
317 QCOMPARE(model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getProperty("uid").toByteArray(), QByteArray("testLatest")); 317 QCOMPARE(model->index(0, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getProperty("uid").toByteArray(), QByteArray("testLatest"));
318 318
319 model->fetchMore(QModelIndex()); 319 model->fetchMore(QModelIndex());
320 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); 320 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
321 QCOMPARE(model->rowCount(), 2); 321 QCOMPARE(model->rowCount(), 2);
322 //We can't make any assumptions about the order of the indexes 322 // We can't make any assumptions about the order of the indexes
323 // QCOMPARE(model->index(1, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getProperty("uid").toByteArray(), QByteArray("testSecond")); 323 // QCOMPARE(model->index(1, 0).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getProperty("uid").toByteArray(), QByteArray("testSecond"));
324 } 324 }
325}; 325};
diff --git a/tests/resourcecommunicationtest.cpp b/tests/resourcecommunicationtest.cpp
index db8703e..2daf372 100644
--- a/tests/resourcecommunicationtest.cpp
+++ b/tests/resourcecommunicationtest.cpp
@@ -51,14 +51,13 @@ private slots:
51 int errors = 0; 51 int errors = 0;
52 for (int i = 0; i < count; i++) { 52 for (int i = 0; i < count; i++) {
53 auto result = resourceAccess.sendCommand(Sink::Commands::PingCommand) 53 auto result = resourceAccess.sendCommand(Sink::Commands::PingCommand)
54 .then<void>([&complete]() { 54 .then<void>([&complete]() { complete++; },
55 complete++; 55 [&errors, &complete](int error, const QString &msg) {
56 }, 56 qWarning() << msg;
57 [&errors, &complete](int error, const QString &msg) { 57 errors++;
58 qWarning() << msg; 58 complete++;
59 errors++; 59 })
60 complete++; 60 .exec();
61 }).exec();
62 } 61 }
63 QTRY_COMPARE(complete, count); 62 QTRY_COMPARE(complete, count);
64 QVERIFY(!errors); 63 QVERIFY(!errors);
@@ -77,17 +76,18 @@ private slots:
77 int errors = 0; 76 int errors = 0;
78 for (int i = 0; i < count; i++) { 77 for (int i = 0; i < count; i++) {
79 resourceAccess.sendCommand(Sink::Commands::PingCommand) 78 resourceAccess.sendCommand(Sink::Commands::PingCommand)
80 .then<void>([&complete]() { 79 .then<void>([&complete]() { complete++; },
81 complete++; 80 [&errors, &complete](int error, const QString &msg) {
82 }, 81 qWarning() << msg;
83 [&errors, &complete](int error, const QString &msg) { 82 errors++;
84 qWarning() << msg; 83 complete++;
85 errors++; 84 })
86 complete++; 85 .then<void>([&resourceAccess]() {
87 }).then<void>([&resourceAccess]() {
88 resourceAccess.close(); 86 resourceAccess.close();
89 resourceAccess.open(); 87 resourceAccess.open();
90 }).exec().waitForFinished(); 88 })
89 .exec()
90 .waitForFinished();
91 } 91 }
92 QTRY_COMPARE(complete, count); 92 QTRY_COMPARE(complete, count);
93 QVERIFY(!errors); 93 QVERIFY(!errors);
diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp
index 8498df9..a1ddcc9 100644
--- a/tests/storagebenchmark.cpp
+++ b/tests/storagebenchmark.cpp
@@ -18,7 +18,7 @@ using namespace flatbuffers;
18 18
19static QByteArray createEvent() 19static QByteArray createEvent()
20{ 20{
21 static const size_t attachmentSize = 1024*2; // 2KB 21 static const size_t attachmentSize = 1024 * 2; // 2KB
22 static uint8_t rawData[attachmentSize]; 22 static uint8_t rawData[attachmentSize];
23 static FlatBufferBuilder fbb; 23 static FlatBufferBuilder fbb;
24 fbb.Clear(); 24 fbb.Clear();
@@ -26,13 +26,13 @@ static QByteArray createEvent()
26 uint8_t *rawDataPtr = Q_NULLPTR; 26 uint8_t *rawDataPtr = Q_NULLPTR;
27 auto summary = fbb.CreateString("summary"); 27 auto summary = fbb.CreateString("summary");
28 auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr); 28 auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr);
29 //auto data = fbb.CreateVector(rawData, attachmentSize); 29 // auto data = fbb.CreateVector(rawData, attachmentSize);
30 Calendar::EventBuilder eventBuilder(fbb); 30 Calendar::EventBuilder eventBuilder(fbb);
31 eventBuilder.add_summary(summary); 31 eventBuilder.add_summary(summary);
32 eventBuilder.add_attachment(data); 32 eventBuilder.add_attachment(data);
33 auto eventLocation = eventBuilder.Finish(); 33 auto eventLocation = eventBuilder.Finish();
34 Calendar::FinishEventBuffer(fbb, eventLocation); 34 Calendar::FinishEventBuffer(fbb, eventLocation);
35 memcpy((void*)rawDataPtr, rawData, attachmentSize); 35 memcpy((void *)rawDataPtr, rawData, attachmentSize);
36 } 36 }
37 37
38 return QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); 38 return QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
@@ -45,7 +45,7 @@ class StorageBenchmark : public QObject
45{ 45{
46 Q_OBJECT 46 Q_OBJECT
47private: 47private:
48 //This should point to a directory on disk and not a ramdisk (since we're measuring performance) 48 // This should point to a directory on disk and not a ramdisk (since we're measuring performance)
49 QString testDataPath; 49 QString testDataPath;
50 QString dbName; 50 QString dbName;
51 QString filePath; 51 QString filePath;
@@ -76,7 +76,7 @@ private slots:
76 76
77 QTime time; 77 QTime time;
78 time.start(); 78 time.start();
79 //Test db write time 79 // Test db write time
80 { 80 {
81 auto transaction = store->createTransaction(Sink::Storage::ReadWrite); 81 auto transaction = store->createTransaction(Sink::Storage::ReadWrite);
82 for (int i = 0; i < count; i++) { 82 for (int i = 0; i < count; i++) {
@@ -91,7 +91,7 @@ private slots:
91 qreal dbWriteDuration = time.restart(); 91 qreal dbWriteDuration = time.restart();
92 qreal dbWriteOpsPerMs = count / dbWriteDuration; 92 qreal dbWriteOpsPerMs = count / dbWriteDuration;
93 93
94 //Test file write time 94 // Test file write time
95 { 95 {
96 std::ofstream myfile; 96 std::ofstream myfile;
97 myfile.open(filePath.toStdString()); 97 myfile.open(filePath.toStdString());
@@ -103,7 +103,7 @@ private slots:
103 qreal fileWriteDuration = time.restart(); 103 qreal fileWriteDuration = time.restart();
104 qreal fileWriteOpsPerMs = count / fileWriteDuration; 104 qreal fileWriteOpsPerMs = count / fileWriteDuration;
105 105
106 //Db read time 106 // Db read time
107 { 107 {
108 auto transaction = store->createTransaction(Sink::Storage::ReadOnly); 108 auto transaction = store->createTransaction(Sink::Storage::ReadOnly);
109 auto db = transaction.openDatabase(); 109 auto db = transaction.openDatabase();
@@ -127,10 +127,10 @@ private slots:
127 void testSizes() 127 void testSizes()
128 { 128 {
129 Sink::Storage store(testDataPath, dbName); 129 Sink::Storage store(testDataPath, dbName);
130 qDebug() << "Database size [kb]: " << store.diskUsage()/1024; 130 qDebug() << "Database size [kb]: " << store.diskUsage() / 1024;
131 131
132 QFileInfo fileInfo(filePath); 132 QFileInfo fileInfo(filePath);
133 qDebug() << "File size [kb]: " << fileInfo.size()/1024; 133 qDebug() << "File size [kb]: " << fileInfo.size() / 1024;
134 } 134 }
135 135
136 void testScan() 136 void testScan()
@@ -139,13 +139,15 @@ private slots:
139 139
140 QBENCHMARK { 140 QBENCHMARK {
141 int hit = 0; 141 int hit = 0;
142 store->createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 142 store->createTransaction(Sink::Storage::ReadOnly)
143 if (key == "key10000") { 143 .openDatabase()
144 //qDebug() << "hit"; 144 .scan("", [&](const QByteArray &key, const QByteArray &value) -> bool {
145 hit++; 145 if (key == "key10000") {
146 } 146 // qDebug() << "hit";
147 return true; 147 hit++;
148 }); 148 }
149 return true;
150 });
149 QCOMPARE(hit, 1); 151 QCOMPARE(hit, 1);
150 } 152 }
151 } 153 }
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index ebd9b8f..31809ce 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -24,7 +24,7 @@ private:
24 Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadWrite); 24 Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadWrite);
25 auto transaction = storage.createTransaction(Sink::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();
@@ -41,19 +41,20 @@ private:
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(Sink::Storage::ReadOnly).openDatabase().scan(keyPrefix + QByteArray::number(i), 44 storage.createTransaction(Sink::Storage::ReadOnly)
45 [&keyMatch, &reference](const QByteArray &key, const QByteArray &value) -> bool { 45 .openDatabase()
46 if (value != reference) { 46 .scan(keyPrefix + QByteArray::number(i),
47 qDebug() << "Mismatch while reading"; 47 [&keyMatch, &reference](const QByteArray &key, const QByteArray &value) -> bool {
48 keyMatch = false; 48 if (value != reference) {
49 } 49 qDebug() << "Mismatch while reading";
50 return keyMatch; 50 keyMatch = false;
51 }, 51 }
52 [&success](const Sink::Storage::Error &error) { 52 return keyMatch;
53 qDebug() << error.message; 53 },
54 success = false; 54 [&success](const Sink::Storage::Error &error) {
55 } 55 qDebug() << error.message;
56 ); 56 success = false;
57 });
57 return success && keyMatch; 58 return success && keyMatch;
58 } 59 }
59 60
@@ -87,7 +88,7 @@ private slots:
87 88
88 populate(count); 89 populate(count);
89 90
90 //ensure we can read everything back correctly 91 // ensure we can read everything back correctly
91 { 92 {
92 Sink::Storage storage(testDataPath, dbName); 93 Sink::Storage storage(testDataPath, dbName);
93 for (int i = 0; i < count; i++) { 94 for (int i = 0; i < count; i++) {
@@ -101,31 +102,35 @@ private slots:
101 const int count = 100; 102 const int count = 100;
102 populate(count); 103 populate(count);
103 104
104 //ensure we can scan for values 105 // ensure we can scan for values
105 { 106 {
106 int hit = 0; 107 int hit = 0;
107 Sink::Storage store(testDataPath, dbName); 108 Sink::Storage store(testDataPath, dbName);
108 store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 109 store.createTransaction(Sink::Storage::ReadOnly)
109 if (key == "key50") { 110 .openDatabase()
110 hit++; 111 .scan("", [&](const QByteArray &key, const QByteArray &value) -> bool {
111 } 112 if (key == "key50") {
112 return true; 113 hit++;
113 }); 114 }
115 return true;
116 });
114 QCOMPARE(hit, 1); 117 QCOMPARE(hit, 1);
115 } 118 }
116 119
117 //ensure we can read a single value 120 // ensure we can read a single value
118 { 121 {
119 int hit = 0; 122 int hit = 0;
120 bool foundInvalidValue = false; 123 bool foundInvalidValue = false;
121 Sink::Storage store(testDataPath, dbName); 124 Sink::Storage store(testDataPath, dbName);
122 store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool { 125 store.createTransaction(Sink::Storage::ReadOnly)
123 if (key != "key50") { 126 .openDatabase()
124 foundInvalidValue = true; 127 .scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool {
125 } 128 if (key != "key50") {
126 hit++; 129 foundInvalidValue = true;
127 return true; 130 }
128 }); 131 hit++;
132 return true;
133 });
129 QVERIFY(!foundInvalidValue); 134 QVERIFY(!foundInvalidValue);
130 QCOMPARE(hit, 1); 135 QCOMPARE(hit, 1);
131 } 136 }
@@ -137,9 +142,7 @@ private slots:
137 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 142 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
138 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 143 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
139 transaction.openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { 144 transaction.openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool {
140 transaction.openDatabase().remove(key, [](const Sink::Storage::Error &) { 145 transaction.openDatabase().remove(key, [](const Sink::Storage::Error &) { QVERIFY(false); });
141 QVERIFY(false);
142 });
143 return false; 146 return false;
144 }); 147 });
145 } 148 }
@@ -148,12 +151,12 @@ private slots:
148 { 151 {
149 populate(3); 152 populate(3);
150 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 153 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
151 store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { 154 store.createTransaction(Sink::Storage::ReadOnly)
152 store.createTransaction(Sink::Storage::ReadWrite).openDatabase().remove(key, [](const Sink::Storage::Error &) { 155 .openDatabase()
153 QVERIFY(false); 156 .scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool {
157 store.createTransaction(Sink::Storage::ReadWrite).openDatabase().remove(key, [](const Sink::Storage::Error &) { QVERIFY(false); });
158 return false;
154 }); 159 });
155 return false;
156 });
157 } 160 }
158 161
159 void testReadEmptyDb() 162 void testReadEmptyDb()
@@ -166,14 +169,15 @@ private slots:
166 qDebug() << error.message; 169 qDebug() << error.message;
167 gotError = true; 170 gotError = true;
168 }); 171 });
169 int numValues = db.scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 172 int numValues = db.scan("",
170 gotResult = true; 173 [&](const QByteArray &key, const QByteArray &value) -> bool {
171 return false; 174 gotResult = true;
172 }, 175 return false;
173 [&](const Sink::Storage::Error &error) { 176 },
174 qDebug() << error.message; 177 [&](const Sink::Storage::Error &error) {
175 gotError = true; 178 qDebug() << error.message;
176 }); 179 gotError = true;
180 });
177 QCOMPARE(numValues, 0); 181 QCOMPARE(numValues, 0);
178 QVERIFY(!gotResult); 182 QVERIFY(!gotResult);
179 QVERIFY(!gotError); 183 QVERIFY(!gotError);
@@ -181,20 +185,20 @@ private slots:
181 185
182 void testConcurrentRead() 186 void testConcurrentRead()
183 { 187 {
184 //With a count of 10000 this test is more likely to expose problems, but also takes some time to execute. 188 // With a count of 10000 this test is more likely to expose problems, but also takes some time to execute.
185 const int count = 1000; 189 const int count = 1000;
186 190
187 populate(count); 191 populate(count);
188 // QTest::qWait(500); 192 // QTest::qWait(500);
189 193
190 //We repeat the test a bunch of times since failing is relatively random 194 // We repeat the test a bunch of times since failing is relatively random
191 for (int tries = 0; tries < 10; tries++) { 195 for (int tries = 0; tries < 10; tries++) {
192 bool error = false; 196 bool error = false;
193 //Try to concurrently read 197 // Try to concurrently read
194 QList<QFuture<void> > futures; 198 QList<QFuture<void>> futures;
195 const int concurrencyLevel = 20; 199 const int concurrencyLevel = 20;
196 for (int num = 0; num < concurrencyLevel; num++) { 200 for (int num = 0; num < concurrencyLevel; num++) {
197 futures << QtConcurrent::run([this, count, &error](){ 201 futures << QtConcurrent::run([this, count, &error]() {
198 Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadOnly); 202 Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadOnly);
199 Sink::Storage storage2(testDataPath, dbName + "2", Sink::Storage::ReadOnly); 203 Sink::Storage storage2(testDataPath, dbName + "2", Sink::Storage::ReadOnly);
200 for (int i = 0; i < count; i++) { 204 for (int i = 0; i < count; i++) {
@@ -205,7 +209,7 @@ private slots:
205 } 209 }
206 }); 210 });
207 } 211 }
208 for(auto future : futures) { 212 for (auto future : futures) {
209 future.waitForFinished(); 213 future.waitForFinished();
210 } 214 }
211 QVERIFY(!error); 215 QVERIFY(!error);
@@ -226,17 +230,18 @@ private slots:
226 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 230 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
227 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 231 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
228 auto db = transaction.openDatabase("default", nullptr, false); 232 auto db = transaction.openDatabase("default", nullptr, false);
229 db.write("key","value"); 233 db.write("key", "value");
230 db.write("key","value"); 234 db.write("key", "value");
231 235
232 int numValues = db.scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 236 int numValues = db.scan("",
233 gotResult = true; 237 [&](const QByteArray &key, const QByteArray &value) -> bool {
234 return true; 238 gotResult = true;
235 }, 239 return true;
236 [&](const Sink::Storage::Error &error) { 240 },
237 qDebug() << error.message; 241 [&](const Sink::Storage::Error &error) {
238 gotError = true; 242 qDebug() << error.message;
239 }); 243 gotError = true;
244 });
240 245
241 QCOMPARE(numValues, 1); 246 QCOMPARE(numValues, 1);
242 QVERIFY(!gotError); 247 QVERIFY(!gotError);
@@ -249,16 +254,17 @@ private slots:
249 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 254 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
250 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 255 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
251 auto db = transaction.openDatabase("default", nullptr, true); 256 auto db = transaction.openDatabase("default", nullptr, true);
252 db.write("key","value1"); 257 db.write("key", "value1");
253 db.write("key","value2"); 258 db.write("key", "value2");
254 int numValues = db.scan("key", [&](const QByteArray &key, const QByteArray &value) -> bool { 259 int numValues = db.scan("key",
255 gotResult = true; 260 [&](const QByteArray &key, const QByteArray &value) -> bool {
256 return true; 261 gotResult = true;
257 }, 262 return true;
258 [&](const Sink::Storage::Error &error) { 263 },
259 qDebug() << error.message; 264 [&](const Sink::Storage::Error &error) {
260 gotError = true; 265 qDebug() << error.message;
261 }); 266 gotError = true;
267 });
262 268
263 QCOMPARE(numValues, 2); 269 QCOMPARE(numValues, 2);
264 QVERIFY(!gotError); 270 QVERIFY(!gotError);
@@ -269,14 +275,17 @@ private slots:
269 bool gotResult = false; 275 bool gotResult = false;
270 bool gotError = false; 276 bool gotError = false;
271 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadOnly); 277 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadOnly);
272 int numValues = store.createTransaction(Sink::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { 278 int numValues = store.createTransaction(Sink::Storage::ReadOnly)
273 gotResult = true; 279 .openDatabase("test")
274 return false; 280 .scan("",
275 }, 281 [&](const QByteArray &key, const QByteArray &value) -> bool {
276 [&](const Sink::Storage::Error &error) { 282 gotResult = true;
277 qDebug() << error.message; 283 return false;
278 gotError = true; 284 },
279 }); 285 [&](const Sink::Storage::Error &error) {
286 qDebug() << error.message;
287 gotError = true;
288 });
280 QCOMPARE(numValues, 0); 289 QCOMPARE(numValues, 0);
281 QVERIFY(!gotResult); 290 QVERIFY(!gotResult);
282 QVERIFY(!gotError); 291 QVERIFY(!gotError);
@@ -286,10 +295,12 @@ private slots:
286 { 295 {
287 bool gotError = false; 296 bool gotError = false;
288 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 297 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
289 store.createTransaction(Sink::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Sink::Storage::Error &error) { 298 store.createTransaction(Sink::Storage::ReadWrite)
290 qDebug() << error.message; 299 .openDatabase("test")
291 gotError = true; 300 .write("key1", "value1", [&](const Sink::Storage::Error &error) {
292 }); 301 qDebug() << error.message;
302 gotError = true;
303 });
293 QVERIFY(!gotError); 304 QVERIFY(!gotError);
294 } 305 }
295 306
@@ -297,24 +308,24 @@ private slots:
297 { 308 {
298 bool gotError = false; 309 bool gotError = false;
299 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 310 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
300 store.createTransaction(Sink::Storage::ReadWrite).openDatabase("test", nullptr, true).write("key1", "value1", [&](const Sink::Storage::Error &error) { 311 store.createTransaction(Sink::Storage::ReadWrite)
301 qDebug() << error.message; 312 .openDatabase("test", nullptr, true)
302 gotError = true; 313 .write("key1", "value1", [&](const Sink::Storage::Error &error) {
303 }); 314 qDebug() << error.message;
315 gotError = true;
316 });
304 QVERIFY(!gotError); 317 QVERIFY(!gotError);
305 } 318 }
306 319
307 //By default we want only exact matches 320 // By default we want only exact matches
308 void testSubstringKeys() 321 void testSubstringKeys()
309 { 322 {
310 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 323 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
311 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 324 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
312 auto db = transaction.openDatabase("test", nullptr, true); 325 auto db = transaction.openDatabase("test", nullptr, true);
313 db.write("sub","value1"); 326 db.write("sub", "value1");
314 db.write("subsub","value2"); 327 db.write("subsub", "value2");
315 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { 328 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { return true; });
316 return true;
317 });
318 329
319 QCOMPARE(numValues, 1); 330 QCOMPARE(numValues, 1);
320 } 331 }
@@ -324,12 +335,10 @@ private slots:
324 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 335 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
325 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 336 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
326 auto db = transaction.openDatabase("test", nullptr, false); 337 auto db = transaction.openDatabase("test", nullptr, false);
327 db.write("sub","value1"); 338 db.write("sub", "value1");
328 db.write("subsub","value2"); 339 db.write("subsub", "value2");
329 db.write("wubsub","value3"); 340 db.write("wubsub", "value3");
330 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { 341 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { return true; }, nullptr, true);
331 return true;
332 }, nullptr, true);
333 342
334 QCOMPARE(numValues, 2); 343 QCOMPARE(numValues, 2);
335 } 344 }
@@ -339,12 +348,10 @@ private slots:
339 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 348 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
340 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 349 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
341 auto db = transaction.openDatabase("test", nullptr, true); 350 auto db = transaction.openDatabase("test", nullptr, true);
342 db.write("sub","value1"); 351 db.write("sub", "value1");
343 db.write("subsub","value2"); 352 db.write("subsub", "value2");
344 db.write("wubsub","value3"); 353 db.write("wubsub", "value3");
345 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { 354 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { return true; }, nullptr, true);
346 return true;
347 }, nullptr, true);
348 355
349 QCOMPARE(numValues, 2); 356 QCOMPARE(numValues, 2);
350 } 357 }
@@ -354,9 +361,9 @@ private slots:
354 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 361 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
355 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 362 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
356 auto db = transaction.openDatabase("test", nullptr, false); 363 auto db = transaction.openDatabase("test", nullptr, false);
357 db.write("sub_2","value2"); 364 db.write("sub_2", "value2");
358 db.write("sub_1","value1"); 365 db.write("sub_1", "value1");
359 db.write("sub_3","value3"); 366 db.write("sub_3", "value3");
360 QList<QByteArray> results; 367 QList<QByteArray> results;
361 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { 368 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool {
362 results << value; 369 results << value;
@@ -369,16 +376,14 @@ private slots:
369 QCOMPARE(results.at(2), QByteArray("value3")); 376 QCOMPARE(results.at(2), QByteArray("value3"));
370 } 377 }
371 378
372 //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. 379 // Ensure we don't retrieve a key that is greater than the current key. We only want equal keys.
373 void testKeyRange() 380 void testKeyRange()
374 { 381 {
375 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 382 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
376 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 383 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
377 auto db = transaction.openDatabase("test", nullptr, true); 384 auto db = transaction.openDatabase("test", nullptr, true);
378 db.write("sub1","value1"); 385 db.write("sub1", "value1");
379 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { 386 int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { return true; });
380 return true;
381 });
382 387
383 QCOMPARE(numValues, 0); 388 QCOMPARE(numValues, 0);
384 } 389 }
@@ -388,14 +393,12 @@ private slots:
388 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 393 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
389 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 394 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
390 auto db = transaction.openDatabase("test", nullptr, false); 395 auto db = transaction.openDatabase("test", nullptr, false);
391 db.write("sub1","value1"); 396 db.write("sub1", "value1");
392 db.write("sub2","value2"); 397 db.write("sub2", "value2");
393 db.write("wub3","value3"); 398 db.write("wub3", "value3");
394 db.write("wub4","value4"); 399 db.write("wub4", "value4");
395 QByteArray result; 400 QByteArray result;
396 db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { 401 db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { result = value; });
397 result = value;
398 });
399 402
400 QCOMPARE(result, QByteArray("value2")); 403 QCOMPARE(result, QByteArray("value2"));
401 } 404 }
@@ -405,11 +408,9 @@ private slots:
405 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 408 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
406 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 409 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
407 auto db = transaction.openDatabase("test", nullptr, false); 410 auto db = transaction.openDatabase("test", nullptr, false);
408 db.write("sub2","value2"); 411 db.write("sub2", "value2");
409 QByteArray result; 412 QByteArray result;
410 db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { 413 db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { result = value; });
411 result = value;
412 });
413 414
414 QCOMPARE(result, QByteArray("value2")); 415 QCOMPARE(result, QByteArray("value2"));
415 } 416 }
@@ -419,12 +420,10 @@ private slots:
419 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); 420 Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite);
420 auto transaction = store.createTransaction(Sink::Storage::ReadWrite); 421 auto transaction = store.createTransaction(Sink::Storage::ReadWrite);
421 auto db = transaction.openDatabase("test", nullptr, false); 422 auto db = transaction.openDatabase("test", nullptr, false);
422 db.write("sub2","value2"); 423 db.write("sub2", "value2");
423 db.write("wub3","value3"); 424 db.write("wub3", "value3");
424 QByteArray result; 425 QByteArray result;
425 db.findLatest("wub", [&](const QByteArray &key, const QByteArray &value) { 426 db.findLatest("wub", [&](const QByteArray &key, const QByteArray &value) { result = value; });
426 result = value;
427 });
428 427
429 QCOMPARE(result, QByteArray("value3")); 428 QCOMPARE(result, QByteArray("value3"));
430 } 429 }
diff --git a/tests/testimplementations.h b/tests/testimplementations.h
index adfdab3..688875d 100644
--- a/tests/testimplementations.h
+++ b/tests/testimplementations.h
@@ -28,7 +28,7 @@
28#include <common/genericresource.h> 28#include <common/genericresource.h>
29#include <common/commands.h> 29#include <common/commands.h>
30 30
31//Replace with something different 31// Replace with something different
32#include "event_generated.h" 32#include "event_generated.h"
33#include "mail_generated.h" 33#include "mail_generated.h"
34#include "createentity_generated.h" 34#include "createentity_generated.h"
@@ -36,37 +36,48 @@
36class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event, Sink::ApplicationDomain::Buffer::Event, Sink::ApplicationDomain::Buffer::EventBuilder> 36class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event, Sink::ApplicationDomain::Buffer::Event, Sink::ApplicationDomain::Buffer::EventBuilder>
37{ 37{
38public: 38public:
39 TestEventAdaptorFactory() 39 TestEventAdaptorFactory() : DomainTypeAdaptorFactory()
40 : DomainTypeAdaptorFactory()
41 { 40 {
42 } 41 }
43 42
44 virtual ~TestEventAdaptorFactory() {}; 43 virtual ~TestEventAdaptorFactory(){};
45}; 44};
46 45
47class TestMailAdaptorFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail, Sink::ApplicationDomain::Buffer::Mail, Sink::ApplicationDomain::Buffer::MailBuilder> 46class TestMailAdaptorFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail, Sink::ApplicationDomain::Buffer::Mail, Sink::ApplicationDomain::Buffer::MailBuilder>
48{ 47{
49public: 48public:
50 TestMailAdaptorFactory() 49 TestMailAdaptorFactory() : DomainTypeAdaptorFactory()
51 : DomainTypeAdaptorFactory()
52 { 50 {
53 } 51 }
54 52
55 virtual ~TestMailAdaptorFactory() {}; 53 virtual ~TestMailAdaptorFactory(){};
56}; 54};
57 55
58class TestResourceAccess : public Sink::ResourceAccessInterface 56class TestResourceAccess : public Sink::ResourceAccessInterface
59{ 57{
60 Q_OBJECT 58 Q_OBJECT
61public: 59public:
62 virtual ~TestResourceAccess() {}; 60 virtual ~TestResourceAccess(){};
63 KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null<void>(); } 61 KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE
64 KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null<void>(); } 62 {
65 KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null<void>(); } 63 return KAsync::null<void>();
64 }
65 KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE
66 {
67 return KAsync::null<void>();
68 }
69 KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE
70 {
71 return KAsync::null<void>();
72 }
66 73
67public slots: 74public slots:
68 void open() Q_DECL_OVERRIDE {} 75 void open() Q_DECL_OVERRIDE
69 void close() Q_DECL_OVERRIDE {} 76 {
77 }
78 void close() Q_DECL_OVERRIDE
79 {
80 }
70}; 81};
71 82
72class TestResourceFacade : public Sink::GenericFacade<Sink::ApplicationDomain::Event> 83class TestResourceFacade : public Sink::GenericFacade<Sink::ApplicationDomain::Event>
@@ -75,11 +86,9 @@ public:
75 TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess) 86 TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess)
76 : Sink::GenericFacade<Sink::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), resourceAccess) 87 : Sink::GenericFacade<Sink::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), resourceAccess)
77 { 88 {
78
79 } 89 }
80 virtual ~TestResourceFacade() 90 virtual ~TestResourceFacade()
81 { 91 {
82
83 } 92 }
84}; 93};
85 94
@@ -89,19 +98,16 @@ public:
89 TestMailResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess) 98 TestMailResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess)
90 : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(instanceIdentifier, QSharedPointer<TestMailAdaptorFactory>::create(), resourceAccess) 99 : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(instanceIdentifier, QSharedPointer<TestMailAdaptorFactory>::create(), resourceAccess)
91 { 100 {
92
93 } 101 }
94 virtual ~TestMailResourceFacade() 102 virtual ~TestMailResourceFacade()
95 { 103 {
96
97 } 104 }
98}; 105};
99 106
100class TestResource : public Sink::GenericResource 107class TestResource : public Sink::GenericResource
101{ 108{
102public: 109public:
103 TestResource(const QByteArray &instanceIdentifier, QSharedPointer<Sink::Pipeline> pipeline) 110 TestResource(const QByteArray &instanceIdentifier, QSharedPointer<Sink::Pipeline> pipeline) : Sink::GenericResource(instanceIdentifier, pipeline)
104 : Sink::GenericResource(instanceIdentifier, pipeline)
105 { 111 {
106 } 112 }
107 113
@@ -126,4 +132,3 @@ QByteArray createCommand(const DomainType &domainObject, DomainTypeAdaptorFactor
126 Sink::Commands::FinishCreateEntityBuffer(fbb, location); 132 Sink::Commands::FinishCreateEntityBuffer(fbb, location);
127 return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); 133 return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
128} 134}
129