diff options
Diffstat (limited to 'tests/dummyresourcebenchmark.cpp')
-rw-r--r-- | tests/dummyresourcebenchmark.cpp | 94 |
1 files changed, 90 insertions, 4 deletions
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 01d9ca4..d83cb70 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp | |||
@@ -3,10 +3,17 @@ | |||
3 | #include <QString> | 3 | #include <QString> |
4 | 4 | ||
5 | #include "dummyresource/resourcefactory.h" | 5 | #include "dummyresource/resourcefactory.h" |
6 | #include "dummyresource/domainadaptor.h" | ||
6 | #include "clientapi.h" | 7 | #include "clientapi.h" |
7 | #include "commands.h" | 8 | #include "commands.h" |
8 | #include "entitybuffer.h" | 9 | #include "entitybuffer.h" |
9 | 10 | ||
11 | #include "event_generated.h" | ||
12 | #include "entity_generated.h" | ||
13 | #include "metadata_generated.h" | ||
14 | #include "createentity_generated.h" | ||
15 | #include <iostream> | ||
16 | |||
10 | static void removeFromDisk(const QString &name) | 17 | static void removeFromDisk(const QString &name) |
11 | { | 18 | { |
12 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite); | 19 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite); |
@@ -41,11 +48,11 @@ private Q_SLOTS: | |||
41 | time.start(); | 48 | time.start(); |
42 | int num = 10000; | 49 | int num = 10000; |
43 | for (int i = 0; i < num; i++) { | 50 | for (int i = 0; i < num; i++) { |
44 | Akonadi2::Domain::Event event; | 51 | Akonadi2::ApplicationDomain::Event event; |
45 | event.setProperty("uid", "testuid"); | 52 | event.setProperty("uid", "testuid"); |
46 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 53 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); |
47 | event.setProperty("summary", "summaryValue"); | 54 | event.setProperty("summary", "summaryValue"); |
48 | Akonadi2::Store::create<Akonadi2::Domain::Event>(event, "org.kde.dummy"); | 55 | Akonadi2::Store::create<Akonadi2::ApplicationDomain::Event>(event, "org.kde.dummy"); |
49 | } | 56 | } |
50 | auto appendTime = time.elapsed(); | 57 | auto appendTime = time.elapsed(); |
51 | 58 | ||
@@ -57,7 +64,7 @@ private Q_SLOTS: | |||
57 | query.processAll = true; | 64 | query.processAll = true; |
58 | 65 | ||
59 | query.propertyFilter.insert("uid", "nonexistantuid"); | 66 | query.propertyFilter.insert("uid", "nonexistantuid"); |
60 | async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); | 67 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query)); |
61 | result.exec(); | 68 | result.exec(); |
62 | } | 69 | } |
63 | auto allProcessedTime = time.elapsed(); | 70 | auto allProcessedTime = time.elapsed(); |
@@ -71,7 +78,7 @@ private Q_SLOTS: | |||
71 | query.processAll = false; | 78 | query.processAll = false; |
72 | 79 | ||
73 | query.propertyFilter.insert("uid", "testuid"); | 80 | query.propertyFilter.insert("uid", "testuid"); |
74 | async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); | 81 | async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query)); |
75 | result.exec(); | 82 | result.exec(); |
76 | QCOMPARE(result.size(), num); | 83 | QCOMPARE(result.size(), num); |
77 | } | 84 | } |
@@ -79,6 +86,85 @@ private Q_SLOTS: | |||
79 | qDebug() << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime; | 86 | qDebug() << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime; |
80 | qDebug() << "Query Time: " << time.elapsed() << "/sec " << num*1000/time.elapsed(); | 87 | qDebug() << "Query Time: " << time.elapsed() << "/sec " << num*1000/time.elapsed(); |
81 | } | 88 | } |
89 | |||
90 | void testWriteInProcess() | ||
91 | { | ||
92 | QTime time; | ||
93 | time.start(); | ||
94 | int num = 10000; | ||
95 | |||
96 | Akonadi2::Pipeline pipeline("org.kde.dummy"); | ||
97 | QSignalSpy revisionSpy(&pipeline, SIGNAL(revisionUpdated())); | ||
98 | DummyResource resource; | ||
99 | resource.configurePipeline(&pipeline); | ||
100 | |||
101 | flatbuffers::FlatBufferBuilder eventFbb; | ||
102 | eventFbb.Clear(); | ||
103 | { | ||
104 | auto summary = eventFbb.CreateString("summary"); | ||
105 | Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
106 | eventBuilder.add_summary(summary); | ||
107 | auto eventLocation = eventBuilder.Finish(); | ||
108 | Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
109 | } | ||
110 | |||
111 | flatbuffers::FlatBufferBuilder localFbb; | ||
112 | { | ||
113 | auto uid = localFbb.CreateString("testuid"); | ||
114 | auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
115 | localBuilder.add_uid(uid); | ||
116 | auto location = localBuilder.Finish(); | ||
117 | Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
118 | } | ||
119 | |||
120 | flatbuffers::FlatBufferBuilder entityFbb; | ||
121 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
122 | |||
123 | flatbuffers::FlatBufferBuilder fbb; | ||
124 | auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName<Akonadi2::ApplicationDomain::Event>().toStdString().data()); | ||
125 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
126 | Akonadi2::Commands::CreateEntityBuilder builder(fbb); | ||
127 | builder.add_domainType(type); | ||
128 | builder.add_delta(delta); | ||
129 | auto location = builder.Finish(); | ||
130 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | ||
131 | |||
132 | const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
133 | |||
134 | for (int i = 0; i < num; i++) { | ||
135 | resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command, command.size(), &pipeline); | ||
136 | } | ||
137 | auto appendTime = time.elapsed(); | ||
138 | |||
139 | //Wait until all messages have been processed | ||
140 | resource.processAllMessages().exec().waitForFinished(); | ||
141 | |||
142 | auto allProcessedTime = time.elapsed(); | ||
143 | |||
144 | std::cout << "Append to messagequeue " << appendTime << std::endl; | ||
145 | std::cout << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime << std::endl; | ||
146 | } | ||
147 | |||
148 | void testCreateCommand() | ||
149 | { | ||
150 | Akonadi2::ApplicationDomain::Event event; | ||
151 | |||
152 | QBENCHMARK { | ||
153 | auto mFactory = new DummyEventAdaptorFactory; | ||
154 | static flatbuffers::FlatBufferBuilder entityFbb; | ||
155 | entityFbb.Clear(); | ||
156 | mFactory->createBuffer(event, entityFbb); | ||
157 | |||
158 | static flatbuffers::FlatBufferBuilder fbb; | ||
159 | fbb.Clear(); | ||
160 | //This is the resource buffer type and not the domain type | ||
161 | auto type = fbb.CreateString("event"); | ||
162 | // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
163 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
164 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); | ||
165 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | ||
166 | } | ||
167 | } | ||
82 | }; | 168 | }; |
83 | 169 | ||
84 | QTEST_MAIN(DummyResourceBenchmark) | 170 | QTEST_MAIN(DummyResourceBenchmark) |