summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt15
-rw-r--r--tests/domainadaptortest.cpp100
-rw-r--r--tests/dummyresourcebenchmark.cpp94
-rw-r--r--tests/dummyresourcetest.cpp20
4 files changed, 133 insertions, 96 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8257c8a..d3e6870 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,6 +2,7 @@ add_subdirectory(hawd)
2 2
3set(CMAKE_AUTOMOC ON) 3set(CMAKE_AUTOMOC ON)
4include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/hawd) 4include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/hawd)
5include_directories (${CMAKE_CURRENT_BINARY_DIR}/../dummyresource)
5 6
6generate_flatbuffers(calendar) 7generate_flatbuffers(calendar)
7 8
@@ -13,14 +14,26 @@ macro(manual_tests)
13 endforeach(_testname) 14 endforeach(_testname)
14endmacro(manual_tests) 15endmacro(manual_tests)
15 16
17macro(auto_tests)
18 foreach(_testname ${ARGN})
19 add_executable(${_testname} ${_testname}.cpp)
20 add_test(${_testname} ${_testname})
21 qt5_use_modules(${_testname} Core Test Concurrent)
22 target_link_libraries(${_testname} akonadi2common libhawd)
23 endforeach(_testname)
24endmacro(auto_tests)
25
16manual_tests ( 26manual_tests (
17 storagebenchmark 27 storagebenchmark
28 dummyresourcebenchmark
29)
30
31auto_tests (
18 storagetest 32 storagetest
19 dummyresourcetest 33 dummyresourcetest
20 domainadaptortest 34 domainadaptortest
21 messagequeuetest 35 messagequeuetest
22 indextest 36 indextest
23 dummyresourcebenchmark
24) 37)
25 38
26target_link_libraries(dummyresourcetest akonadi2_resource_dummy) 39target_link_libraries(dummyresourcetest akonadi2_resource_dummy)
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp
index cedbf94..1e285dc 100644
--- a/tests/domainadaptortest.cpp
+++ b/tests/domainadaptortest.cpp
@@ -13,89 +13,12 @@
13#include "metadata_generated.h" 13#include "metadata_generated.h"
14#include "entity_generated.h" 14#include "entity_generated.h"
15 15
16class TestEventAdaptor : public Akonadi2::Domain::BufferAdaptor 16class TestFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::Event, Akonadi2::ApplicationDomain::Buffer::EventBuilder, Akonadi2::ApplicationDomain::Buffer::EventBuilder>
17{
18public:
19 TestEventAdaptor()
20 : Akonadi2::Domain::BufferAdaptor()
21 {
22 }
23
24 void setProperty(const QString &key, const QVariant &value)
25 {
26 if (mResourceMapper->mWriteAccessors.contains(key)) {
27 // mResourceMapper.setProperty(key, value, mResourceBuffer);
28 } else {
29 // mLocalMapper.;
30 }
31 }
32
33 virtual QVariant getProperty(const QString &key) const
34 {
35 if (mResourceBuffer && mResourceMapper->mReadAccessors.contains(key)) {
36 return mResourceMapper->getProperty(key, mResourceBuffer);
37 } else if (mLocalBuffer) {
38 return mLocalMapper->getProperty(key, mLocalBuffer);
39 }
40 return QVariant();
41 }
42
43 Akonadi2::Domain::Buffer::Event const *mLocalBuffer;
44 Akonadi2::Domain::Buffer::Event const *mResourceBuffer;
45
46 QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> > mLocalMapper;
47 QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> > mResourceMapper;
48};
49
50class TestFactory : public DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, Akonadi2::Domain::Buffer::Event>
51{ 17{
52public: 18public:
53 TestFactory() 19 TestFactory()
54 { 20 {
55 mResourceMapper = QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> >::create(); 21 mResourceWriteMapper = initializeWritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder>();
56 mResourceMapper->mReadAccessors.insert("summary", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant {
57 if (buffer->summary()) {
58 return QString::fromStdString(buffer->summary()->c_str());
59 }
60 return QVariant();
61 });
62 }
63
64 virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity)
65 {
66 Akonadi2::Domain::Buffer::Event const *resourceBuffer = 0;
67 if (auto resourceData = entity.resource()) {
68 flatbuffers::Verifier verifyer(resourceData->Data(), resourceData->size());
69 if (Akonadi2::Domain::Buffer::VerifyEventBuffer(verifyer)) {
70 resourceBuffer = Akonadi2::Domain::Buffer::GetEvent(resourceData->Data());
71 if (resourceBuffer->summary()) {
72 qDebug() << QString::fromStdString(std::string(resourceBuffer->summary()->c_str()));
73 }
74 }
75 }
76
77 // Akonadi2::Metadata const *metadataBuffer = 0;
78 // if (auto metadataData = entity.metadata()) {
79 // flatbuffers::Verifier verifyer(metadataData->Data(), metadataData->size());
80 // if (Akonadi2::VerifyMetadataBuffer(verifyer)) {
81 // metadataBuffer = Akonadi2::GetMetadata(metadataData);
82 // }
83 // }
84
85 Akonadi2::Domain::Buffer::Event const *localBuffer = 0;
86 if (auto localData = entity.local()) {
87 flatbuffers::Verifier verifyer(localData->Data(), localData->size());
88 if (Akonadi2::Domain::Buffer::VerifyEventBuffer(verifyer)) {
89 localBuffer = Akonadi2::Domain::Buffer::GetEvent(localData);
90 }
91 }
92
93 auto adaptor = QSharedPointer<TestEventAdaptor>::create();
94 adaptor->mLocalBuffer = localBuffer;
95 adaptor->mResourceBuffer = resourceBuffer;
96 adaptor->mResourceMapper = mResourceMapper;
97 adaptor->mLocalMapper = mLocalMapper;
98 return adaptor;
99 } 22 }
100}; 23};
101 24
@@ -111,6 +34,21 @@ private Q_SLOTS:
111 { 34 {
112 } 35 }
113 36
37 void testCreateBufferPart()
38 {
39 auto writeMapper = initializeWritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder>();
40
41 Akonadi2::ApplicationDomain::Event event;
42 event.setProperty("summary", "foo");
43
44 flatbuffers::FlatBufferBuilder fbb;
45 auto pos = createBufferPart<Akonadi2::ApplicationDomain::Buffer::EventBuilder, Akonadi2::ApplicationDomain::Buffer::Event>(event, fbb, *writeMapper);
46 Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos);
47
48 flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize());
49 QVERIFY(verifier.VerifyBuffer<Akonadi2::ApplicationDomain::Buffer::Event>());
50 }
51
114 void testAdaptor() 52 void testAdaptor()
115 { 53 {
116 //Create entity buffer 54 //Create entity buffer
@@ -127,12 +65,12 @@ private Q_SLOTS:
127 static uint8_t rawData[100]; 65 static uint8_t rawData[100];
128 auto attachment = m_fbb.CreateVector(rawData, 100); 66 auto attachment = m_fbb.CreateVector(rawData, 100);
129 67
130 auto builder = Akonadi2::Domain::Buffer::EventBuilder(m_fbb); 68 auto builder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(m_fbb);
131 builder.add_summary(summary); 69 builder.add_summary(summary);
132 builder.add_description(description); 70 builder.add_description(description);
133 builder.add_attachment(attachment); 71 builder.add_attachment(attachment);
134 auto buffer = builder.Finish(); 72 auto buffer = builder.Finish();
135 Akonadi2::Domain::Buffer::FinishEventBuffer(m_fbb, buffer); 73 Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(m_fbb, buffer);
136 74
137 flatbuffers::FlatBufferBuilder fbb; 75 flatbuffers::FlatBufferBuilder fbb;
138 Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize()); 76 Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize());
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
10static void removeFromDisk(const QString &name) 17static 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
84QTEST_MAIN(DummyResourceBenchmark) 170QTEST_MAIN(DummyResourceBenchmark)
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp
index b185664..5fed7cd 100644
--- a/tests/dummyresourcetest.cpp
+++ b/tests/dummyresourcetest.cpp
@@ -49,26 +49,26 @@ private Q_SLOTS:
49 eventFbb.Clear(); 49 eventFbb.Clear();
50 { 50 {
51 auto summary = eventFbb.CreateString("summary"); 51 auto summary = eventFbb.CreateString("summary");
52 Akonadi2::Domain::Buffer::EventBuilder eventBuilder(eventFbb); 52 Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb);
53 eventBuilder.add_summary(summary); 53 eventBuilder.add_summary(summary);
54 auto eventLocation = eventBuilder.Finish(); 54 auto eventLocation = eventBuilder.Finish();
55 Akonadi2::Domain::Buffer::FinishEventBuffer(eventFbb, eventLocation); 55 Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation);
56 } 56 }
57 57
58 flatbuffers::FlatBufferBuilder localFbb; 58 flatbuffers::FlatBufferBuilder localFbb;
59 { 59 {
60 auto uid = localFbb.CreateString("testuid"); 60 auto uid = localFbb.CreateString("testuid");
61 auto localBuilder = Akonadi2::Domain::Buffer::EventBuilder(localFbb); 61 auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb);
62 localBuilder.add_uid(uid); 62 localBuilder.add_uid(uid);
63 auto location = localBuilder.Finish(); 63 auto location = localBuilder.Finish();
64 Akonadi2::Domain::Buffer::FinishEventBuffer(localFbb, location); 64 Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location);
65 } 65 }
66 66
67 flatbuffers::FlatBufferBuilder entityFbb; 67 flatbuffers::FlatBufferBuilder entityFbb;
68 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); 68 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
69 69
70 flatbuffers::FlatBufferBuilder fbb; 70 flatbuffers::FlatBufferBuilder fbb;
71 auto type = fbb.CreateString(Akonadi2::Domain::getTypeName<Akonadi2::Domain::Event>().toStdString().data()); 71 auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName<Akonadi2::ApplicationDomain::Event>().toStdString().data());
72 auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); 72 auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize());
73 Akonadi2::Commands::CreateEntityBuilder builder(fbb); 73 Akonadi2::Commands::CreateEntityBuilder builder(fbb);
74 builder.add_domainType(type); 74 builder.add_domainType(type);
@@ -98,18 +98,18 @@ private Q_SLOTS:
98 98
99 void testProperty() 99 void testProperty()
100 { 100 {
101 Akonadi2::Domain::Event event; 101 Akonadi2::ApplicationDomain::Event event;
102 event.setProperty("uid", "testuid"); 102 event.setProperty("uid", "testuid");
103 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); 103 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid"));
104 } 104 }
105 105
106 void testWriteToFacadeAndQueryByUid() 106 void testWriteToFacadeAndQueryByUid()
107 { 107 {
108 Akonadi2::Domain::Event event; 108 Akonadi2::ApplicationDomain::Event event;
109 event.setProperty("uid", "testuid"); 109 event.setProperty("uid", "testuid");
110 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); 110 QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid"));
111 event.setProperty("summary", "summaryValue"); 111 event.setProperty("summary", "summaryValue");
112 Akonadi2::Store::create<Akonadi2::Domain::Event>(event, "org.kde.dummy"); 112 Akonadi2::Store::create<Akonadi2::ApplicationDomain::Event>(event, "org.kde.dummy");
113 113
114 Akonadi2::Query query; 114 Akonadi2::Query query;
115 query.resources << "org.kde.dummy"; 115 query.resources << "org.kde.dummy";
@@ -117,7 +117,7 @@ private Q_SLOTS:
117 query.processAll = true; 117 query.processAll = true;
118 118
119 query.propertyFilter.insert("uid", "testuid"); 119 query.propertyFilter.insert("uid", "testuid");
120 async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); 120 async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query));
121 result.exec(); 121 result.exec();
122 QCOMPARE(result.size(), 1); 122 QCOMPARE(result.size(), 1);
123 auto value = result.first(); 123 auto value = result.first();
@@ -147,7 +147,7 @@ private Q_SLOTS:
147 query.syncOnDemand = true; 147 query.syncOnDemand = true;
148 query.processAll = true; 148 query.processAll = true;
149 149
150 async::SyncListResult<Akonadi2::Domain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::Domain::Event>(query)); 150 async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query));
151 result.exec(); 151 result.exec();
152 QVERIFY(!result.isEmpty()); 152 QVERIFY(!result.isEmpty());
153 auto value = result.first(); 153 auto value = result.first();