diff options
Diffstat (limited to 'tests/pipelinetest.cpp')
-rw-r--r-- | tests/pipelinetest.cpp | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 112453e..4e04152 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp | |||
@@ -152,23 +152,22 @@ QByteArray deleteEntityCommand(const QByteArray &uid, qint64 revision) | |||
152 | class TestProcessor : public Sink::Preprocessor | 152 | class TestProcessor : public Sink::Preprocessor |
153 | { | 153 | { |
154 | public: | 154 | public: |
155 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | 155 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
156 | { | 156 | { |
157 | newUids << uid; | 157 | newUids << newEntity.identifier(); |
158 | newRevisions << revision; | 158 | newRevisions << newEntity.revision(); |
159 | } | 159 | } |
160 | 160 | ||
161 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 161 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
162 | Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
163 | { | 162 | { |
164 | modifiedUids << uid; | 163 | modifiedUids << newEntity.identifier(); |
165 | modifiedRevisions << revision; | 164 | modifiedRevisions << newEntity.revision(); |
166 | } | 165 | } |
167 | 166 | ||
168 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | 167 | void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE |
169 | { | 168 | { |
170 | deletedUids << uid; | 169 | deletedUids << oldEntity.identifier(); |
171 | deletedRevisions << revision; | 170 | deletedRevisions << oldEntity.revision(); |
172 | deletedSummaries << oldEntity.getProperty("summary").toByteArray(); | 171 | deletedSummaries << oldEntity.getProperty("summary").toByteArray(); |
173 | } | 172 | } |
174 | 173 | ||
@@ -187,6 +186,17 @@ public: | |||
187 | class PipelineTest : public QObject | 186 | class PipelineTest : public QObject |
188 | { | 187 | { |
189 | Q_OBJECT | 188 | Q_OBJECT |
189 | |||
190 | QByteArray instanceIdentifier() | ||
191 | { | ||
192 | return "pipelinetest.instance1"; | ||
193 | } | ||
194 | |||
195 | Sink::ResourceContext getContext() | ||
196 | { | ||
197 | return Sink::ResourceContext{instanceIdentifier(), "test", Sink::AdaptorFactoryRegistry::instance().getFactories("test")}; | ||
198 | } | ||
199 | |||
190 | private slots: | 200 | private slots: |
191 | void initTestCase() | 201 | void initTestCase() |
192 | { | 202 | { |
@@ -195,7 +205,7 @@ private slots: | |||
195 | 205 | ||
196 | void init() | 206 | void init() |
197 | { | 207 | { |
198 | removeFromDisk("sink.pipelinetest.instance1"); | 208 | removeFromDisk(instanceIdentifier()); |
199 | } | 209 | } |
200 | 210 | ||
201 | void testCreate() | 211 | void testCreate() |
@@ -203,15 +213,22 @@ private slots: | |||
203 | flatbuffers::FlatBufferBuilder entityFbb; | 213 | flatbuffers::FlatBufferBuilder entityFbb; |
204 | auto command = createEntityCommand(createEvent(entityFbb)); | 214 | auto command = createEntityCommand(createEvent(entityFbb)); |
205 | 215 | ||
206 | Sink::Pipeline pipeline(Sink::ResourceContext{"sink.pipelinetest.instance1", "test"}); | 216 | Sink::Pipeline pipeline(getContext()); |
207 | 217 | ||
208 | pipeline.startTransaction(); | 218 | pipeline.startTransaction(); |
209 | pipeline.newEntity(command.constData(), command.size()); | 219 | pipeline.newEntity(command.constData(), command.size()); |
210 | pipeline.commit(); | 220 | pipeline.commit(); |
211 | 221 | ||
212 | auto result = getKeys("sink.pipelinetest.instance1", "event.main"); | 222 | auto result = getKeys(instanceIdentifier(), "event.main"); |
213 | qDebug() << result; | 223 | qDebug() << result; |
214 | QCOMPARE(result.size(), 1); | 224 | QCOMPARE(result.size(), 1); |
225 | |||
226 | auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); | ||
227 | auto buffer = getEntity(instanceIdentifier(), "event.main", result.first()); | ||
228 | QVERIFY(!buffer.isEmpty()); | ||
229 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); | ||
230 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); | ||
231 | QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary"), "The modification isn't applied."); | ||
215 | } | 232 | } |
216 | 233 | ||
217 | void testModify() | 234 | void testModify() |
@@ -219,7 +236,7 @@ private slots: | |||
219 | flatbuffers::FlatBufferBuilder entityFbb; | 236 | flatbuffers::FlatBufferBuilder entityFbb; |
220 | auto command = createEntityCommand(createEvent(entityFbb, "summary", "description")); | 237 | auto command = createEntityCommand(createEvent(entityFbb, "summary", "description")); |
221 | 238 | ||
222 | Sink::Pipeline pipeline(Sink::ResourceContext{"sink.pipelinetest.instance1", "test"}); | 239 | Sink::Pipeline pipeline(getContext()); |
223 | 240 | ||
224 | auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); | 241 | auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); |
225 | 242 | ||
@@ -229,7 +246,7 @@ private slots: | |||
229 | pipeline.commit(); | 246 | pipeline.commit(); |
230 | 247 | ||
231 | // Get uid of written entity | 248 | // Get uid of written entity |
232 | auto keys = getKeys("sink.pipelinetest.instance1", "event.main"); | 249 | auto keys = getKeys(instanceIdentifier(), "event.main"); |
233 | QCOMPARE(keys.size(), 1); | 250 | QCOMPARE(keys.size(), 1); |
234 | const auto key = keys.first(); | 251 | const auto key = keys.first(); |
235 | const auto uid = Sink::Storage::DataStore::uidFromKey(key); | 252 | const auto uid = Sink::Storage::DataStore::uidFromKey(key); |
@@ -242,7 +259,7 @@ private slots: | |||
242 | pipeline.commit(); | 259 | pipeline.commit(); |
243 | 260 | ||
244 | // Ensure we've got the new revision with the modification | 261 | // Ensure we've got the new revision with the modification |
245 | auto buffer = getEntity("sink.pipelinetest.instance1", "event.main", Sink::Storage::DataStore::assembleKey(uid, 2)); | 262 | auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 2)); |
246 | QVERIFY(!buffer.isEmpty()); | 263 | QVERIFY(!buffer.isEmpty()); |
247 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); | 264 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); |
248 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); | 265 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); |
@@ -251,7 +268,7 @@ private slots: | |||
251 | QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects."); | 268 | QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects."); |
252 | 269 | ||
253 | // Both revisions are in the store at this point | 270 | // Both revisions are in the store at this point |
254 | QCOMPARE(getKeys("sink.pipelinetest.instance1", "event.main").size(), 2); | 271 | QCOMPARE(getKeys(instanceIdentifier(), "event.main").size(), 2); |
255 | 272 | ||
256 | // Cleanup old revisions | 273 | // Cleanup old revisions |
257 | pipeline.startTransaction(); | 274 | pipeline.startTransaction(); |
@@ -259,7 +276,7 @@ private slots: | |||
259 | pipeline.commit(); | 276 | pipeline.commit(); |
260 | 277 | ||
261 | // And now only the latest revision is left | 278 | // And now only the latest revision is left |
262 | QCOMPARE(getKeys("sink.pipelinetest.instance1", "event.main").size(), 1); | 279 | QCOMPARE(getKeys(instanceIdentifier(), "event.main").size(), 1); |
263 | } | 280 | } |
264 | 281 | ||
265 | void testModifyWithUnrelatedOperationInbetween() | 282 | void testModifyWithUnrelatedOperationInbetween() |
@@ -267,7 +284,7 @@ private slots: | |||
267 | flatbuffers::FlatBufferBuilder entityFbb; | 284 | flatbuffers::FlatBufferBuilder entityFbb; |
268 | auto command = createEntityCommand(createEvent(entityFbb)); | 285 | auto command = createEntityCommand(createEvent(entityFbb)); |
269 | 286 | ||
270 | Sink::Pipeline pipeline(Sink::ResourceContext{"sink.pipelinetest.instance1", "test"}); | 287 | Sink::Pipeline pipeline(getContext()); |
271 | 288 | ||
272 | auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); | 289 | auto adaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); |
273 | 290 | ||
@@ -277,7 +294,7 @@ private slots: | |||
277 | pipeline.commit(); | 294 | pipeline.commit(); |
278 | 295 | ||
279 | // Get uid of written entity | 296 | // Get uid of written entity |
280 | auto keys = getKeys("sink.pipelinetest.instance1", "event.main"); | 297 | auto keys = getKeys(instanceIdentifier(), "event.main"); |
281 | QCOMPARE(keys.size(), 1); | 298 | QCOMPARE(keys.size(), 1); |
282 | const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); | 299 | const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); |
283 | 300 | ||
@@ -299,7 +316,7 @@ private slots: | |||
299 | pipeline.commit(); | 316 | pipeline.commit(); |
300 | 317 | ||
301 | // Ensure we've got the new revision with the modification | 318 | // Ensure we've got the new revision with the modification |
302 | auto buffer = getEntity("sink.pipelinetest.instance1", "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); | 319 | auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); |
303 | QVERIFY(!buffer.isEmpty()); | 320 | QVERIFY(!buffer.isEmpty()); |
304 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); | 321 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); |
305 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); | 322 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); |
@@ -310,14 +327,14 @@ private slots: | |||
310 | { | 327 | { |
311 | flatbuffers::FlatBufferBuilder entityFbb; | 328 | flatbuffers::FlatBufferBuilder entityFbb; |
312 | auto command = createEntityCommand(createEvent(entityFbb)); | 329 | auto command = createEntityCommand(createEvent(entityFbb)); |
313 | Sink::Pipeline pipeline(Sink::ResourceContext{"sink.pipelinetest.instance1", "test"}); | 330 | Sink::Pipeline pipeline(getContext()); |
314 | 331 | ||
315 | // Create the initial revision | 332 | // Create the initial revision |
316 | pipeline.startTransaction(); | 333 | pipeline.startTransaction(); |
317 | pipeline.newEntity(command.constData(), command.size()); | 334 | pipeline.newEntity(command.constData(), command.size()); |
318 | pipeline.commit(); | 335 | pipeline.commit(); |
319 | 336 | ||
320 | auto result = getKeys("sink.pipelinetest.instance1", "event.main"); | 337 | auto result = getKeys(instanceIdentifier(), "event.main"); |
321 | QCOMPARE(result.size(), 1); | 338 | QCOMPARE(result.size(), 1); |
322 | 339 | ||
323 | const auto uid = Sink::Storage::DataStore::uidFromKey(result.first()); | 340 | const auto uid = Sink::Storage::DataStore::uidFromKey(result.first()); |
@@ -329,7 +346,7 @@ private slots: | |||
329 | pipeline.commit(); | 346 | pipeline.commit(); |
330 | 347 | ||
331 | // We have a new revision that indicates the deletion | 348 | // We have a new revision that indicates the deletion |
332 | QCOMPARE(getKeys("sink.pipelinetest.instance1", "event.main").size(), 2); | 349 | QCOMPARE(getKeys(instanceIdentifier(), "event.main").size(), 2); |
333 | 350 | ||
334 | // Cleanup old revisions | 351 | // Cleanup old revisions |
335 | pipeline.startTransaction(); | 352 | pipeline.startTransaction(); |
@@ -337,7 +354,7 @@ private slots: | |||
337 | pipeline.commit(); | 354 | pipeline.commit(); |
338 | 355 | ||
339 | // And all revisions are gone | 356 | // And all revisions are gone |
340 | QCOMPARE(getKeys("sink.pipelinetest.instance1", "event.main").size(), 0); | 357 | QCOMPARE(getKeys(instanceIdentifier(), "event.main").size(), 0); |
341 | } | 358 | } |
342 | 359 | ||
343 | void testPreprocessor() | 360 | void testPreprocessor() |
@@ -346,7 +363,7 @@ private slots: | |||
346 | 363 | ||
347 | auto testProcessor = new TestProcessor; | 364 | auto testProcessor = new TestProcessor; |
348 | 365 | ||
349 | Sink::Pipeline pipeline(Sink::ResourceContext{"sink.pipelinetest.instance1", "test"}); | 366 | Sink::Pipeline pipeline(getContext()); |
350 | pipeline.setPreprocessors("event", QVector<Sink::Preprocessor *>() << testProcessor); | 367 | pipeline.setPreprocessors("event", QVector<Sink::Preprocessor *>() << testProcessor); |
351 | pipeline.startTransaction(); | 368 | pipeline.startTransaction(); |
352 | // pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create()); | 369 | // pipeline.setAdaptorFactory("event", QSharedPointer<TestEventAdaptorFactory>::create()); |
@@ -363,7 +380,7 @@ private slots: | |||
363 | pipeline.commit(); | 380 | pipeline.commit(); |
364 | entityFbb.Clear(); | 381 | entityFbb.Clear(); |
365 | pipeline.startTransaction(); | 382 | pipeline.startTransaction(); |
366 | auto keys = getKeys("sink.pipelinetest.instance1", "event.main"); | 383 | auto keys = getKeys(instanceIdentifier(), "event.main"); |
367 | QCOMPARE(keys.size(), 1); | 384 | QCOMPARE(keys.size(), 1); |
368 | const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); | 385 | const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); |
369 | { | 386 | { |