summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/dummyresourcetest.cpp15
-rw-r--r--tests/genericfacadebenchmark.cpp111
-rw-r--r--tests/genericfacadetest.cpp4
4 files changed, 129 insertions, 2 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/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp
index e3b3f07..a28e071 100644
--- a/tests/dummyresourcetest.cpp
+++ b/tests/dummyresourcetest.cpp
@@ -164,6 +164,21 @@ private Q_SLOTS:
164 qDebug() << value->getProperty("summary").toString(); 164 qDebug() << value->getProperty("summary").toString();
165 } 165 }
166 166
167 void testSyncAndFacadeMail()
168 {
169 Akonadi2::Query query;
170 query.resources << "org.kde.dummy.instance1";
171 query.syncOnDemand = true;
172 query.processAll = true;
173
174 async::SyncListResult<Akonadi2::ApplicationDomain::Mail::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Mail>(query));
175 result.exec();
176 QVERIFY(!result.isEmpty());
177 auto value = result.first();
178 QVERIFY(!value->getProperty("subject").toString().isEmpty());
179 qDebug() << value->getProperty("subject").toString();
180 }
181
167 void testWriteModifyDelete() 182 void testWriteModifyDelete()
168 { 183 {
169 Akonadi2::ApplicationDomain::Event event; 184 Akonadi2::ApplicationDomain::Event event;
diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp
new file mode 100644
index 0000000..7cd6c75
--- /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, "bufferType");
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"
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp
index 7aaec23..45ca54d 100644
--- a/tests/genericfacadetest.cpp
+++ b/tests/genericfacadetest.cpp
@@ -74,7 +74,7 @@ private Q_SLOTS:
74 query.liveQuery = false; 74 query.liveQuery = false;
75 75
76 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create(); 76 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create();
77 auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create()); 77 auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create(), "bufferType");
78 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 78 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
79 storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); 79 storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create();
80 TestResourceFacade facade("identifier", storage, resourceAccess); 80 TestResourceFacade facade("identifier", storage, resourceAccess);
@@ -96,7 +96,7 @@ private Q_SLOTS:
96 query.liveQuery = true; 96 query.liveQuery = true;
97 97
98 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create(); 98 auto resultSet = QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> >::create();
99 auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create()); 99 auto storage = QSharedPointer<TestEntityStorage>::create("identifier", QSharedPointer<TestEventAdaptorFactory>::create(), "bufferType");
100 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 100 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
101 storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); 101 storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create();
102 TestResourceFacade facade("identifier", storage, resourceAccess); 102 TestResourceFacade facade("identifier", storage, resourceAccess);