summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-02-03 16:54:56 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-02-03 16:54:56 +0100
commitb11b8a774e83aa7de65758e814c3fabea87f6160 (patch)
treede1cc1e43d40afb0bf01f59f15071ceb426d3eaa /tests
parent0acdfd2ac2dd3ebfb05c96e065c896fb2ed4734f (diff)
downloadsink-b11b8a774e83aa7de65758e814c3fabea87f6160.tar.gz
sink-b11b8a774e83aa7de65758e814c3fabea87f6160.zip
Fixed incremental fetching
Diffstat (limited to 'tests')
-rw-r--r--tests/clientapitest.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index 55fdcfc..fb1bdeb 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -69,13 +69,25 @@ public:
69 SinkTraceCtx(ctx) << "Running the fetcher."; 69 SinkTraceCtx(ctx) << "Running the fetcher.";
70 } 70 }
71 SinkTraceCtx(ctx) << "-------------------------."; 71 SinkTraceCtx(ctx) << "-------------------------.";
72 for (const auto &res : results) { 72 int count = 0;
73 for (int i = offset; i < results.size(); i++) {
74 const auto res = results.at(i);
75 count++;
73 // SinkTraceCtx(ctx) << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); 76 // SinkTraceCtx(ctx) << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray();
74 auto parentProperty = res->getProperty("parent").toByteArray(); 77 auto parentProperty = res->getProperty("parent").toByteArray();
75 if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) { 78 if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) {
76 // SinkTraceCtx(ctx) << "Found a hit" << res->identifier(); 79 // SinkTraceCtx(ctx) << "Found a hit" << res->identifier();
77 resultProvider->add(res); 80 resultProvider->add(res);
78 } 81 }
82 if (query.limit()) {
83 if (count >= query.limit()) {
84 SinkTraceCtx(ctx) << "Aborting early after " << count << "results.";
85 offset = i + 1;
86 bool fetchedAll = (i + 1 >= results.size());
87 resultProvider->initialResultSetComplete(parent, fetchedAll);
88 return 0;
89 }
90 }
79 } 91 }
80 resultProvider->initialResultSetComplete(parent, true); 92 resultProvider->initialResultSetComplete(parent, true);
81 return 0; 93 return 0;
@@ -89,6 +101,7 @@ public:
89 QList<typename T::Ptr> results; 101 QList<typename T::Ptr> results;
90 Sink::ResultProviderInterface<typename T::Ptr> *mResultProvider; 102 Sink::ResultProviderInterface<typename T::Ptr> *mResultProvider;
91 bool runAsync = false; 103 bool runAsync = false;
104 int offset = 0;
92}; 105};
93 106
94 107
@@ -285,6 +298,41 @@ private slots:
285 QVERIFY(gotValue); 298 QVERIFY(gotValue);
286 } 299 }
287 300
301 void testMultiresourceIncrementalLoad()
302 {
303 auto facade1 = TestDummyResourceFacade<Sink::ApplicationDomain::Event>::registerFacade("dummyresource.instance1");
304 for (int i = 0; i < 4; i++) {
305 facade1->results << QSharedPointer<Sink::ApplicationDomain::Event>::create("resource1", "id" + QByteArray::number(i), 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
306 }
307 auto facade2 = TestDummyResourceFacade<Sink::ApplicationDomain::Event>::registerFacade("dummyresource.instance2");
308 for (int i = 0; i < 6; i++) {
309 facade2->results << QSharedPointer<Sink::ApplicationDomain::Event>::create("resource2", "id" + QByteArray::number(i), 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
310 }
311 ResourceConfig::addResource("dummyresource.instance1", "dummyresource");
312 ResourceConfig::addResource("dummyresource.instance2", "dummyresource");
313
314 Sink::Query query;
315 query.limit(2);
316
317 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::Event>(query);
318 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
319 QCOMPARE(model->rowCount(QModelIndex()), 4);
320
321 //Try to fetch another round
322 QVERIFY(model->canFetchMore(QModelIndex()));
323 model->fetchMore(QModelIndex());
324 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
325 QCOMPARE(model->rowCount(QModelIndex()), 8);
326
327 //Try to fetch the last round
328 QVERIFY(model->canFetchMore(QModelIndex()));
329 model->fetchMore(QModelIndex());
330 QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool());
331 QCOMPARE(model->rowCount(QModelIndex()), 10);
332
333 QVERIFY(!model->canFetchMore(QModelIndex()));
334 }
335
288 void testModelStress() 336 void testModelStress()
289 { 337 {
290 auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade(); 338 auto facade = TestDummyResourceFacade<Sink::ApplicationDomain::Folder>::registerFacade();