diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/genericfacadetest.cpp | 154 | ||||
-rw-r--r-- | tests/genericresourcebenchmark.cpp | 209 | ||||
-rw-r--r-- | tests/genericresourcetest.cpp | 85 |
4 files changed, 0 insertions, 452 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a69fcb3..7144d41 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -21,10 +21,8 @@ include(SinkTest) | |||
21 | manual_tests ( | 21 | manual_tests ( |
22 | storagebenchmark | 22 | storagebenchmark |
23 | dummyresourcebenchmark | 23 | dummyresourcebenchmark |
24 | # genericresourcebenchmark | ||
25 | mailquerybenchmark | 24 | mailquerybenchmark |
26 | pipelinebenchmark | 25 | pipelinebenchmark |
27 | # genericfacadebenchmark | ||
28 | ) | 26 | ) |
29 | 27 | ||
30 | auto_tests ( | 28 | auto_tests ( |
@@ -35,8 +33,6 @@ auto_tests ( | |||
35 | domainadaptortest | 33 | domainadaptortest |
36 | messagequeuetest | 34 | messagequeuetest |
37 | indextest | 35 | indextest |
38 | # genericresourcetest | ||
39 | # genericfacadetest | ||
40 | resourcecommunicationtest | 36 | resourcecommunicationtest |
41 | pipelinetest | 37 | pipelinetest |
42 | querytest | 38 | querytest |
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp deleted file mode 100644 index 0267dac..0000000 --- a/tests/genericfacadetest.cpp +++ /dev/null | |||
@@ -1,154 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include "testimplementations.h" | ||
6 | |||
7 | #include <common/facade.h> | ||
8 | #include <common/domainadaptor.h> | ||
9 | #include <common/resultprovider.h> | ||
10 | #include <common/synclistresult.h> | ||
11 | #include <common/test.h> | ||
12 | |||
13 | // Replace with something different | ||
14 | #include "event_generated.h" | ||
15 | |||
16 | |||
17 | /** | ||
18 | * Test for the generic facade implementation. | ||
19 | * | ||
20 | * This test doesn't use the actual storage and thus only tests the update logic of the facade. | ||
21 | * //FIXME this now uses the actual storage | ||
22 | */ | ||
23 | class GenericFacadeTest : public QObject | ||
24 | { | ||
25 | Q_OBJECT | ||
26 | private slots: | ||
27 | void initTestCase() | ||
28 | { | ||
29 | Sink::Test::initTest(); | ||
30 | } | ||
31 | |||
32 | void testLoad() | ||
33 | { | ||
34 | Sink::Query query; | ||
35 | query.liveQuery = false; | ||
36 | |||
37 | auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create(); | ||
38 | auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
39 | // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create(); | ||
40 | TestResourceFacade facade("identifier", resourceAccess); | ||
41 | |||
42 | async::SyncListResult<Sink::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | ||
43 | |||
44 | facade.load(query, *resultSet).exec().waitForFinished(); | ||
45 | resultSet->initialResultSetComplete(); | ||
46 | |||
47 | // We have to wait for the events that deliver the results to be processed by the eventloop | ||
48 | result.exec(); | ||
49 | |||
50 | QCOMPARE(result.size(), 1); | ||
51 | } | ||
52 | |||
53 | void testLiveQuery() | ||
54 | { | ||
55 | Sink::Query query; | ||
56 | query.liveQuery = true; | ||
57 | |||
58 | auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create(); | ||
59 | auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
60 | // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create(); | ||
61 | TestResourceFacade facade("identifier", resourceAccess); | ||
62 | |||
63 | async::SyncListResult<Sink::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | ||
64 | |||
65 | facade.load(query, *resultSet).exec().waitForFinished(); | ||
66 | resultSet->initialResultSetComplete(); | ||
67 | |||
68 | result.exec(); | ||
69 | QCOMPARE(result.size(), 1); | ||
70 | |||
71 | // Enter a second result | ||
72 | // storage->mResults.clear(); | ||
73 | // storage->mResults << QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>()); | ||
74 | // storage->mLatestRevision = 2; | ||
75 | resourceAccess->emit revisionChanged(2); | ||
76 | |||
77 | // Hack to get event loop in synclistresult to abort again | ||
78 | resultSet->initialResultSetComplete(); | ||
79 | result.exec(); | ||
80 | |||
81 | QCOMPARE(result.size(), 2); | ||
82 | } | ||
83 | |||
84 | void testLiveQueryModify() | ||
85 | { | ||
86 | Sink::Query query; | ||
87 | query.liveQuery = true; | ||
88 | |||
89 | auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create(); | ||
90 | auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
91 | auto entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
92 | entity->setProperty("test", "test1"); | ||
93 | // storage->mResults << entity; | ||
94 | TestResourceFacade facade("identifier", resourceAccess); | ||
95 | |||
96 | async::SyncListResult<Sink::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | ||
97 | |||
98 | facade.load(query, *resultSet).exec().waitForFinished(); | ||
99 | resultSet->initialResultSetComplete(); | ||
100 | |||
101 | result.exec(); | ||
102 | QCOMPARE(result.size(), 1); | ||
103 | |||
104 | // Modify the entity again | ||
105 | // storage->mResults.clear(); | ||
106 | entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
107 | entity->setProperty("test", "test2"); | ||
108 | // storage->mModifications << entity; | ||
109 | // storage->mLatestRevision = 2; | ||
110 | resourceAccess->emit revisionChanged(2); | ||
111 | |||
112 | // Hack to get event loop in synclistresult to abort again | ||
113 | resultSet->initialResultSetComplete(); | ||
114 | result.exec(); | ||
115 | |||
116 | QCOMPARE(result.size(), 1); | ||
117 | QCOMPARE(result.first()->getProperty("test").toByteArray(), QByteArray("test2")); | ||
118 | } | ||
119 | |||
120 | void testLiveQueryRemove() | ||
121 | { | ||
122 | Sink::Query query; | ||
123 | query.liveQuery = true; | ||
124 | |||
125 | auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create(); | ||
126 | auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); | ||
127 | auto entity = QSharedPointer<Sink::ApplicationDomain::Event>::create("resource", "id2", 0, QSharedPointer<Sink::ApplicationDomain::BufferAdaptor>()); | ||
128 | // storage->mResults << entity; | ||
129 | TestResourceFacade facade("identifier", resourceAccess); | ||
130 | |||
131 | async::SyncListResult<Sink::ApplicationDomain::Event::Ptr> result(resultSet->emitter()); | ||
132 | |||
133 | facade.load(query, *resultSet).exec().waitForFinished(); | ||
134 | resultSet->initialResultSetComplete(); | ||
135 | |||
136 | result.exec(); | ||
137 | QCOMPARE(result.size(), 1); | ||
138 | |||
139 | // Remove the entity again | ||
140 | // storage->mResults.clear(); | ||
141 | // storage->mRemovals << entity; | ||
142 | // storage->mLatestRevision = 2; | ||
143 | resourceAccess->emit revisionChanged(2); | ||
144 | |||
145 | // Hack to get event loop in synclistresult to abort again | ||
146 | resultSet->initialResultSetComplete(); | ||
147 | result.exec(); | ||
148 | |||
149 | QCOMPARE(result.size(), 0); | ||
150 | } | ||
151 | }; | ||
152 | |||
153 | QTEST_MAIN(GenericFacadeTest) | ||
154 | #include "genericfacadetest.moc" | ||
diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp deleted file mode 100644 index 2315d0b..0000000 --- a/tests/genericresourcebenchmark.cpp +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include "testimplementations.h" | ||
6 | |||
7 | #include "event_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 "index.h" | ||
16 | |||
17 | #include "hawd/dataset.h" | ||
18 | #include "hawd/formatter.h" | ||
19 | |||
20 | |||
21 | static void removeFromDisk(const QString &name) | ||
22 | { | ||
23 | Sink::Storage store(Sink::storageLocation(), name, Sink::Storage::ReadWrite); | ||
24 | store.removeFromDisk(); | ||
25 | } | ||
26 | |||
27 | static QByteArray createEntityBuffer() | ||
28 | { | ||
29 | flatbuffers::FlatBufferBuilder eventFbb; | ||
30 | eventFbb.Clear(); | ||
31 | { | ||
32 | auto summary = eventFbb.CreateString("summary"); | ||
33 | Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
34 | eventBuilder.add_summary(summary); | ||
35 | auto eventLocation = eventBuilder.Finish(); | ||
36 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
37 | } | ||
38 | |||
39 | flatbuffers::FlatBufferBuilder localFbb; | ||
40 | { | ||
41 | auto uid = localFbb.CreateString("testuid"); | ||
42 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
43 | localBuilder.add_uid(uid); | ||
44 | auto location = localBuilder.Finish(); | ||
45 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
46 | } | ||
47 | |||
48 | flatbuffers::FlatBufferBuilder entityFbb; | ||
49 | Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
50 | |||
51 | flatbuffers::FlatBufferBuilder fbb; | ||
52 | auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>().toStdString().data()); | ||
53 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
54 | Sink::Commands::CreateEntityBuilder builder(fbb); | ||
55 | builder.add_domainType(type); | ||
56 | builder.add_delta(delta); | ||
57 | auto location = builder.Finish(); | ||
58 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
59 | |||
60 | return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
61 | } | ||
62 | |||
63 | class IndexUpdater : public Sink::Preprocessor | ||
64 | { | ||
65 | public: | ||
66 | void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
67 | { | ||
68 | for (int i = 0; i < 10; i++) { | ||
69 | Index ridIndex(QString("index.index%1").arg(i).toLatin1(), transaction); | ||
70 | ridIndex.add("foo", uid); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, | ||
75 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
76 | { | ||
77 | } | ||
78 | |||
79 | void deletedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
80 | { | ||
81 | } | ||
82 | }; | ||
83 | |||
84 | /** | ||
85 | * Benchmark write performance of generic resource implementation including queues and pipeline. | ||
86 | */ | ||
87 | class GenericResourceBenchmark : public QObject | ||
88 | { | ||
89 | Q_OBJECT | ||
90 | private slots: | ||
91 | |||
92 | void init() | ||
93 | { | ||
94 | Sink::Log::setDebugOutputLevel(Sink::Log::Warning); | ||
95 | } | ||
96 | |||
97 | void initTestCase() | ||
98 | { | ||
99 | removeFromDisk("sink.test.instance1"); | ||
100 | removeFromDisk("sink.test.instance1.userqueue"); | ||
101 | removeFromDisk("sink.test.instance1.synchronizerqueue"); | ||
102 | } | ||
103 | |||
104 | |||
105 | void testWriteInProcess() | ||
106 | { | ||
107 | int num = 10000; | ||
108 | |||
109 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.test.instance1"); | ||
110 | TestResource resource("sink.test.instance1", pipeline); | ||
111 | |||
112 | auto command = createEntityBuffer(); | ||
113 | |||
114 | QTime time; | ||
115 | time.start(); | ||
116 | |||
117 | for (int i = 0; i < num; i++) { | ||
118 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
119 | } | ||
120 | auto appendTime = time.elapsed(); | ||
121 | |||
122 | // Wait until all messages have been processed | ||
123 | resource.processAllMessages().exec().waitForFinished(); | ||
124 | |||
125 | auto allProcessedTime = time.elapsed(); | ||
126 | |||
127 | // Print memory layout, RSS is what is in memory | ||
128 | // std::system("exec pmap -x \"$PPID\""); | ||
129 | |||
130 | HAWD::Dataset dataset("generic_write_in_process", m_hawdState); | ||
131 | HAWD::Dataset::Row row = dataset.row(); | ||
132 | |||
133 | row.setValue("rows", num); | ||
134 | row.setValue("append", (qreal)num / appendTime); | ||
135 | row.setValue("total", (qreal)num / allProcessedTime); | ||
136 | dataset.insertRow(row); | ||
137 | HAWD::Formatter::print(dataset); | ||
138 | } | ||
139 | |||
140 | void testWriteInProcessWithIndex() | ||
141 | { | ||
142 | int num = 50000; | ||
143 | |||
144 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.test.instance1"); | ||
145 | |||
146 | auto eventFactory = QSharedPointer<TestEventAdaptorFactory>::create(); | ||
147 | const QByteArray resourceIdentifier = "sink.test.instance1"; | ||
148 | auto indexer = QSharedPointer<IndexUpdater>::create(); | ||
149 | |||
150 | pipeline->setPreprocessors("event", QVector<Sink::Preprocessor *>() << indexer.data()); | ||
151 | pipeline->setAdaptorFactory("event", eventFactory); | ||
152 | |||
153 | TestResource resource("sink.test.instance1", pipeline); | ||
154 | |||
155 | auto command = createEntityBuffer(); | ||
156 | |||
157 | QTime time; | ||
158 | time.start(); | ||
159 | |||
160 | for (int i = 0; i < num; i++) { | ||
161 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
162 | } | ||
163 | auto appendTime = time.elapsed(); | ||
164 | |||
165 | // Wait until all messages have been processed | ||
166 | resource.processAllMessages().exec().waitForFinished(); | ||
167 | |||
168 | auto allProcessedTime = time.elapsed(); | ||
169 | |||
170 | // Print memory layout, RSS is what is in memory | ||
171 | // std::system("exec pmap -x \"$PPID\""); | ||
172 | |||
173 | HAWD::Dataset dataset("generic_write_in_process_with_indexes", m_hawdState); | ||
174 | HAWD::Dataset::Row row = dataset.row(); | ||
175 | |||
176 | row.setValue("rows", num); | ||
177 | row.setValue("append", (qreal)num / appendTime); | ||
178 | row.setValue("total", (qreal)num / allProcessedTime); | ||
179 | dataset.insertRow(row); | ||
180 | HAWD::Formatter::print(dataset); | ||
181 | } | ||
182 | |||
183 | void testCreateCommand() | ||
184 | { | ||
185 | Sink::ApplicationDomain::Event event; | ||
186 | |||
187 | QBENCHMARK { | ||
188 | auto mFactory = new TestEventAdaptorFactory; | ||
189 | static flatbuffers::FlatBufferBuilder entityFbb; | ||
190 | entityFbb.Clear(); | ||
191 | mFactory->createBuffer(event, entityFbb); | ||
192 | |||
193 | static flatbuffers::FlatBufferBuilder fbb; | ||
194 | fbb.Clear(); | ||
195 | // This is the resource buffer type and not the domain type | ||
196 | auto type = fbb.CreateString("event"); | ||
197 | // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
198 | auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
199 | auto location = Sink::Commands::CreateCreateEntity(fbb, type, delta); | ||
200 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | private: | ||
205 | HAWD::State m_hawdState; | ||
206 | }; | ||
207 | |||
208 | QTEST_MAIN(GenericResourceBenchmark) | ||
209 | #include "genericresourcebenchmark.moc" | ||
diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp deleted file mode 100644 index 77a901d..0000000 --- a/tests/genericresourcetest.cpp +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include "testimplementations.h" | ||
6 | |||
7 | #include "event_generated.h" | ||
8 | #include "entity_generated.h" | ||
9 | #include "metadata_generated.h" | ||
10 | #include "createentity_generated.h" | ||
11 | #include "commands.h" | ||
12 | #include "entitybuffer.h" | ||
13 | #include "pipeline.h" | ||
14 | #include "genericresource.h" | ||
15 | #include "definitions.h" | ||
16 | |||
17 | /** | ||
18 | * Test of the generic resource implementation. | ||
19 | * | ||
20 | * This test relies on a working pipeline implementation, and writes to storage. | ||
21 | */ | ||
22 | class GenericResourceTest : public QObject | ||
23 | { | ||
24 | Q_OBJECT | ||
25 | private slots: | ||
26 | |||
27 | void init() | ||
28 | { | ||
29 | Sink::GenericResource::removeFromDisk("sink.test.instance1"); | ||
30 | } | ||
31 | |||
32 | /// Ensure the resource can process messages | ||
33 | void testProcessCommand() | ||
34 | { | ||
35 | flatbuffers::FlatBufferBuilder eventFbb; | ||
36 | eventFbb.Clear(); | ||
37 | { | ||
38 | auto summary = eventFbb.CreateString("summary"); | ||
39 | Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
40 | eventBuilder.add_summary(summary); | ||
41 | auto eventLocation = eventBuilder.Finish(); | ||
42 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
43 | } | ||
44 | |||
45 | flatbuffers::FlatBufferBuilder localFbb; | ||
46 | { | ||
47 | auto uid = localFbb.CreateString("testuid"); | ||
48 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
49 | localBuilder.add_uid(uid); | ||
50 | auto location = localBuilder.Finish(); | ||
51 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
52 | } | ||
53 | |||
54 | flatbuffers::FlatBufferBuilder entityFbb; | ||
55 | Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
56 | |||
57 | flatbuffers::FlatBufferBuilder fbb; | ||
58 | auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>().toStdString().data()); | ||
59 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
60 | Sink::Commands::CreateEntityBuilder builder(fbb); | ||
61 | builder.add_domainType(type); | ||
62 | builder.add_delta(delta); | ||
63 | auto location = builder.Finish(); | ||
64 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
65 | |||
66 | const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
67 | { | ||
68 | flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command.data()), command.size()); | ||
69 | QVERIFY(Sink::Commands::VerifyCreateEntityBuffer(verifyer)); | ||
70 | } | ||
71 | |||
72 | // Actual test | ||
73 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.test.instance1"); | ||
74 | QSignalSpy revisionSpy(pipeline.data(), SIGNAL(revisionUpdated(qint64))); | ||
75 | QVERIFY(revisionSpy.isValid()); | ||
76 | TestResource resource("sink.test.instance1", pipeline); | ||
77 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
78 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
79 | resource.processAllMessages().exec().waitForFinished(); | ||
80 | QCOMPARE(revisionSpy.last().at(0).toInt(), 2); | ||
81 | } | ||
82 | }; | ||
83 | |||
84 | QTEST_MAIN(GenericResourceTest) | ||
85 | #include "genericresourcetest.moc" | ||