summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/genericfacadebenchmark.cpp111
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 1c75e96..251e780 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -31,6 +31,7 @@ manual_tests (
31 storagebenchmark 31 storagebenchmark
32 dummyresourcebenchmark 32 dummyresourcebenchmark
33 genericresourcebenchmark 33 genericresourcebenchmark
34 genericfacadebenchmark
34) 35)
35 36
36auto_tests ( 37auto_tests (
diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp
new file mode 100644
index 0000000..483a597
--- /dev/null
+++ b/tests/genericfacadebenchmark.cpp
@@ -0,0 +1,111 @@
1#include <QtTest>
2
3#include <QString>
4
5#include <common/facade.h>
6#include <common/domainadaptor.h>
7#include <common/resultprovider.h>
8#include <common/synclistresult.h>
9
10#include "event_generated.h"
11
12class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder>
13{
14public:
15 TestEventAdaptorFactory()
16 : DomainTypeAdaptorFactory()
17 {
18 }
19
20 virtual ~TestEventAdaptorFactory() {};
21};
22
23class TestResourceAccess : public Akonadi2::ResourceAccessInterface
24{
25 Q_OBJECT
26public:
27 virtual ~TestResourceAccess() {};
28 KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null<void>(); }
29 KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null<void>(); }
30 KAsync::Job<void> synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null<void>(); }
31
32public Q_SLOTS:
33 void open() Q_DECL_OVERRIDE {}
34 void close() Q_DECL_OVERRIDE {}
35};
36
37class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>
38{
39public:
40 TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> > storage, const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess)
41 : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<TestEventAdaptorFactory>::create(), storage, resourceAccess)
42 {
43
44 }
45 virtual ~TestResourceFacade()
46 {
47
48 }
49};
50
51class GenericFacadeBenchmark : public QObject
52{
53 Q_OBJECT
54private Q_SLOTS:
55
56 void initTestCase()
57 {
58 Akonadi2::Storage store(Akonadi2::storageLocation(), "identifier", Akonadi2::Storage::ReadWrite);
59 store.removeFromDisk();
60 }
61
62 void testLoad()
63 {
64 const QByteArray identifier = "identifier";
65 const int count = 100000;
66
67 //Setup
68 auto domainTypeAdaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
69 {
70 Akonadi2::Storage storage(Akonadi2::storageLocation(), identifier, Akonadi2::Storage::ReadWrite);
71 auto transaction = storage.createTransaction(Akonadi2::Storage::ReadWrite);
72 auto db = transaction.openDatabase();
73 for (int i = 0; i < count; i++) {
74 auto domainObject = Akonadi2::ApplicationDomain::Event::Ptr::create();
75 domainObject->setProperty("uid", "uid");
76 domainObject->setProperty("summary", "summary");
77
78 flatbuffers::FlatBufferBuilder fbb;
79 domainTypeAdaptorFactory->createBuffer(*domainObject, fbb);
80 db.write(QString::number(i).toLatin1(), QByteArray::fromRawData(reinterpret_cast<const char*>(fbb.GetBufferPointer()), fbb.GetSize()));
81 }
82 }
83
84 Akonadi2::Query query;
85 query.liveQuery = false;
86
87 //Benchmark
88 QBENCHMARK {
89 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create();
90 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
91 auto storage = QSharedPointer<EntityStorage<Akonadi2::ApplicationDomain::Event> >::create("identifier", domainTypeAdaptorFactory);
92 TestResourceFacade facade(identifier, storage, resourceAccess);
93
94 async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(resultSet->emitter());
95
96 facade.load(query, resultSet).exec().waitForFinished();
97 resultSet->initialResultSetComplete();
98
99 //We have to wait for the events that deliver the results to be processed by the eventloop
100 result.exec();
101
102 QCOMPARE(result.size(), count);
103 }
104
105 // Print memory layout, RSS is what is in memory
106 // std::system("exec pmap -x \"$PPID\"");
107 }
108};
109
110QTEST_MAIN(GenericFacadeBenchmark)
111#include "genericfacadebenchmark.moc"