diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-19 19:54:24 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-19 19:54:24 +0200 |
commit | e6df6dc808314bac332368675c87af97313fef91 (patch) | |
tree | 41a6f8e4bf3fdd2feda40c5e91af63e347508409 | |
parent | 820f9633f15aa20a03a44348012e98d6bd5e6bd9 (diff) | |
download | sink-e6df6dc808314bac332368675c87af97313fef91.tar.gz sink-e6df6dc808314bac332368675c87af97313fef91.zip |
GenericResourceBenchmark
Will eventually replace most parts of DummyResourceBenchmark
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/genericresourcebenchmark.cpp | 151 |
2 files changed, 152 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 542b4ed..1c75e96 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -30,6 +30,7 @@ endmacro(auto_tests) | |||
30 | manual_tests ( | 30 | manual_tests ( |
31 | storagebenchmark | 31 | storagebenchmark |
32 | dummyresourcebenchmark | 32 | dummyresourcebenchmark |
33 | genericresourcebenchmark | ||
33 | ) | 34 | ) |
34 | 35 | ||
35 | auto_tests ( | 36 | auto_tests ( |
diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp new file mode 100644 index 0000000..01dc95d --- /dev/null +++ b/tests/genericresourcebenchmark.cpp | |||
@@ -0,0 +1,151 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include "event_generated.h" | ||
6 | #include "entity_generated.h" | ||
7 | #include "metadata_generated.h" | ||
8 | #include "createentity_generated.h" | ||
9 | #include "commands.h" | ||
10 | #include "entitybuffer.h" | ||
11 | #include "pipeline.h" | ||
12 | #include "genericresource.h" | ||
13 | #include "definitions.h" | ||
14 | #include "domainadaptor.h" | ||
15 | #include <iostream> | ||
16 | |||
17 | class TestResource : public Akonadi2::GenericResource | ||
18 | { | ||
19 | public: | ||
20 | TestResource(const QByteArray &instanceIdentifier, QSharedPointer<Akonadi2::Pipeline> pipeline) | ||
21 | : Akonadi2::GenericResource(instanceIdentifier, pipeline) | ||
22 | { | ||
23 | } | ||
24 | |||
25 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | ||
26 | { | ||
27 | return KAsync::null<void>(); | ||
28 | } | ||
29 | }; | ||
30 | |||
31 | class TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder> | ||
32 | { | ||
33 | public: | ||
34 | TestEventAdaptorFactory() | ||
35 | : DomainTypeAdaptorFactory() | ||
36 | { | ||
37 | } | ||
38 | |||
39 | virtual ~TestEventAdaptorFactory() {}; | ||
40 | }; | ||
41 | |||
42 | |||
43 | static void removeFromDisk(const QString &name) | ||
44 | { | ||
45 | Akonadi2::Storage store(Akonadi2::storageLocation(), name, Akonadi2::Storage::ReadWrite); | ||
46 | store.removeFromDisk(); | ||
47 | } | ||
48 | |||
49 | static QByteArray createEntityBuffer() | ||
50 | { | ||
51 | flatbuffers::FlatBufferBuilder eventFbb; | ||
52 | eventFbb.Clear(); | ||
53 | { | ||
54 | auto summary = eventFbb.CreateString("summary"); | ||
55 | Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
56 | eventBuilder.add_summary(summary); | ||
57 | auto eventLocation = eventBuilder.Finish(); | ||
58 | Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
59 | } | ||
60 | |||
61 | flatbuffers::FlatBufferBuilder localFbb; | ||
62 | { | ||
63 | auto uid = localFbb.CreateString("testuid"); | ||
64 | auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
65 | localBuilder.add_uid(uid); | ||
66 | auto location = localBuilder.Finish(); | ||
67 | Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
68 | } | ||
69 | |||
70 | flatbuffers::FlatBufferBuilder entityFbb; | ||
71 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
72 | |||
73 | flatbuffers::FlatBufferBuilder fbb; | ||
74 | auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName<Akonadi2::ApplicationDomain::Event>().toStdString().data()); | ||
75 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
76 | Akonadi2::Commands::CreateEntityBuilder builder(fbb); | ||
77 | builder.add_domainType(type); | ||
78 | builder.add_delta(delta); | ||
79 | auto location = builder.Finish(); | ||
80 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | ||
81 | |||
82 | return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
83 | } | ||
84 | |||
85 | class GenericResourceBenchmark : public QObject | ||
86 | { | ||
87 | Q_OBJECT | ||
88 | private Q_SLOTS: | ||
89 | |||
90 | void init() | ||
91 | { | ||
92 | removeFromDisk("org.kde.test.instance1"); | ||
93 | removeFromDisk("org.kde.test.instance1.userqueue"); | ||
94 | removeFromDisk("org.kde.test.instance1.synchronizerqueue"); | ||
95 | Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); | ||
96 | qDebug(); | ||
97 | qDebug() << "-----------------------------------------"; | ||
98 | qDebug(); | ||
99 | } | ||
100 | |||
101 | |||
102 | void testWriteInProcess() | ||
103 | { | ||
104 | int num = 50000; | ||
105 | |||
106 | auto pipeline = QSharedPointer<Akonadi2::Pipeline>::create("org.kde.test.instance1"); | ||
107 | TestResource resource("org.kde.test.instance1", pipeline); | ||
108 | |||
109 | auto command = createEntityBuffer(); | ||
110 | |||
111 | QTime time; | ||
112 | time.start(); | ||
113 | |||
114 | for (int i = 0; i < num; i++) { | ||
115 | resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); | ||
116 | } | ||
117 | auto appendTime = time.elapsed(); | ||
118 | |||
119 | //Wait until all messages have been processed | ||
120 | resource.processAllMessages().exec().waitForFinished(); | ||
121 | |||
122 | auto allProcessedTime = time.elapsed(); | ||
123 | |||
124 | std::cout << "Append to messagequeue " << appendTime << " /sec " << num*1000/appendTime << std::endl; | ||
125 | std::cout << "All processed: " << allProcessedTime << " /sec " << num*1000/allProcessedTime << std::endl; | ||
126 | } | ||
127 | |||
128 | void testCreateCommand() | ||
129 | { | ||
130 | Akonadi2::ApplicationDomain::Event event; | ||
131 | |||
132 | QBENCHMARK { | ||
133 | auto mFactory = new TestEventAdaptorFactory; | ||
134 | static flatbuffers::FlatBufferBuilder entityFbb; | ||
135 | entityFbb.Clear(); | ||
136 | mFactory->createBuffer(event, entityFbb); | ||
137 | |||
138 | static flatbuffers::FlatBufferBuilder fbb; | ||
139 | fbb.Clear(); | ||
140 | //This is the resource buffer type and not the domain type | ||
141 | auto type = fbb.CreateString("event"); | ||
142 | // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
143 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
144 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); | ||
145 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | ||
146 | } | ||
147 | } | ||
148 | }; | ||
149 | |||
150 | QTEST_MAIN(GenericResourceBenchmark) | ||
151 | #include "genericresourcebenchmark.moc" | ||