diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-09-07 16:28:25 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-09-07 16:28:25 +0200 |
commit | 43ae43bc74800473aadf9c5c807603cdf8516d36 (patch) | |
tree | 59aa76bf8c7b94547cad9ca9b5a9dd37082a5f70 | |
parent | bec7ebcd95f1539b5d8a9fe472c3c05809386c18 (diff) | |
download | sink-43ae43bc74800473aadf9c5c807603cdf8516d36.tar.gz sink-43ae43bc74800473aadf9c5c807603cdf8516d36.zip |
GenericFacadeBenchmark
genericfacadebenchmark
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/genericfacadebenchmark.cpp | 111 |
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 | ||
36 | auto_tests ( | 37 | auto_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 | |||
12 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
13 | { | ||
14 | public: | ||
15 | TestEventAdaptorFactory() | ||
16 | : DomainTypeAdaptorFactory() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | virtual ~TestEventAdaptorFactory() {}; | ||
21 | }; | ||
22 | |||
23 | class TestResourceAccess : public Akonadi2::ResourceAccessInterface | ||
24 | { | ||
25 | Q_OBJECT | ||
26 | public: | ||
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 | |||
32 | public Q_SLOTS: | ||
33 | void open() Q_DECL_OVERRIDE {} | ||
34 | void close() Q_DECL_OVERRIDE {} | ||
35 | }; | ||
36 | |||
37 | class TestResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | ||
38 | { | ||
39 | public: | ||
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 | |||
51 | class GenericFacadeBenchmark : public QObject | ||
52 | { | ||
53 | Q_OBJECT | ||
54 | private 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 | |||
110 | QTEST_MAIN(GenericFacadeBenchmark) | ||
111 | #include "genericfacadebenchmark.moc" | ||