diff options
Diffstat (limited to 'tests/benchmarks')
20 files changed, 548 insertions, 1247 deletions
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro index 4e840fe..298d99d 100644 --- a/tests/benchmarks/benchmarks.pro +++ b/tests/benchmarks/benchmarks.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += daemon jsondb-listmodel client jsondbcachinglistmodel jsondbsortinglistmodel btrees +SUBDIRS += partition client jsondbcachinglistmodel jsondbsortinglistmodel btrees diff --git a/tests/benchmarks/client/client-benchmark.cpp b/tests/benchmarks/client/client-benchmark.cpp index 4134d90..fc8e0b7 100644 --- a/tests/benchmarks/client/client-benchmark.cpp +++ b/tests/benchmarks/client/client-benchmark.cpp @@ -42,7 +42,6 @@ #include <QtTest/QtTest> #include "client-benchmark.h" #include "private/jsondb-connection_p.h" -#include <json.h> #include "util.h" @@ -93,20 +92,17 @@ void TestJson::initTestCase() #ifndef DONT_START_SERVER removeDbFiles(); QString socketName = QString("testjsondb_%1").arg(getpid()); - mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile); + mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__); #endif connectToServer(); QByteArray friendJson("{\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\", \"indexed\": true}}}"); - JsonReader reader; - // Create schemas for the items - reader.parse(friendJson); QVariantMap friendSchema; friendSchema.insert("name", "Friends"); - friendSchema.insert("schema", reader.result()); + friendSchema.insert("schema", QJsonDocument::fromJson(friendJson).object().toVariantMap()); friendSchema.insert("_type", "_schemaType"); int id = mClient->create(friendSchema); waitForResponse1(id); @@ -271,7 +267,6 @@ void TestJson::queryThousandItems_data() { QTest::addColumn<QString>("queryString"); QTest::newRow("Friends") << QString("[?_type=\"Friends\"]"); - QTest::newRow("Friends[=_uuid]") << QString("[?_type=\"Friends\"][=_uuid]"); QTest::newRow("Friends[={_uuid:_uuid}]") << QString("[?_type=\"Friends\"][={_uuid:_uuid}]"); } diff --git a/tests/benchmarks/client/client.pro b/tests/benchmarks/client/client.pro index 0ae1dd8..44c55ad 100644 --- a/tests/benchmarks/client/client.pro +++ b/tests/benchmarks/client/client.pro @@ -5,10 +5,6 @@ QT = core network testlib jsondb jsondbcompat-private DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\" -INCLUDEPATH += "../../../src/common" -INCLUDEPATH += "../../../src/3rdparty/qjson/src" -SOURCES += ../../../src/3rdparty/qjson/src/json.cpp - CONFIG += qtestlib CONFIG -= app_bundle diff --git a/tests/benchmarks/daemon/daemon.pro b/tests/benchmarks/daemon/daemon.pro deleted file mode 100644 index a76caaf..0000000 --- a/tests/benchmarks/daemon/daemon.pro +++ /dev/null @@ -1,14 +0,0 @@ -TARGET = tst_bench_daemon - -QT = network qml testlib -CONFIG -= app_bundle -CONFIG += testcase - -INCLUDEPATH += $$PWD/../../../src/daemon -LIBS += -L$$QT.jsondb.libs - -DEFINES += SRCDIR=\\\"$$PWD/\\\" -include($$PWD/../../../src/daemon/daemon.pri) -RESOURCES+=../../json.qrc daemon.qrc -SOURCES += \ - bench_daemon.cpp \ diff --git a/tests/benchmarks/daemon/daemon.qrc b/tests/benchmarks/daemon/daemon.qrc deleted file mode 100644 index 8e10790..0000000 --- a/tests/benchmarks/daemon/daemon.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/daemon"> - <file alias="json">../../auto/daemon/json</file> - <file alias="schemas">../../auto/daemon/schemas</file> - </qresource> -</RCC> diff --git a/tests/benchmarks/jsondb-listmodel/jsondb-listmodel.pro b/tests/benchmarks/jsondb-listmodel/jsondb-listmodel.pro deleted file mode 100644 index 3a8098f..0000000 --- a/tests/benchmarks/jsondb-listmodel/jsondb-listmodel.pro +++ /dev/null @@ -1,17 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_listmodel - -QT = core network testlib gui qml jsondbcompat-private -CONFIG -= app_bundle - -include($$PWD/../../shared/shared.pri) -include($$PWD/../../../src/3rdparty/qjson/qjson.pri) - -DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\" - -INCLUDEPATH += $$PWD/../../../src/imports/jsondb-listmodel -HEADERS += $$PWD/../../../src/imports/jsondb-listmodel/jsondb-listmodel.h -SOURCES += $$PWD/../../../src/imports/jsondb-listmodel/jsondb-listmodel.cpp - -HEADERS += listmodel-benchmark.h -SOURCES += listmodel-benchmark.cpp diff --git a/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp b/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp deleted file mode 100644 index a0eb763..0000000 --- a/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.cpp +++ /dev/null @@ -1,564 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QJSEngine> -#include "listmodel-benchmark.h" - -#include "../../shared/util.h" -#include <QQmlEngine> -#include <QQmlComponent> -#include <QQmlContext> - -static const char dbfile[] = "dbFile-test-jsondb"; -ModelData::ModelData(): engine(0), component(0), model(0) -{ -} - -ModelData::~ModelData() -{ - if (model) - delete model; - if (component) - delete component; - if (engine) - delete engine; -} - -TestListModel::TestListModel() - : mProcess(0) -{ -} - -TestListModel::~TestListModel() -{ -} - -void TestListModel::connectListModel(JsonDbListModel *model) -{ - connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this , SLOT(dataChanged(QModelIndex,QModelIndex))); - connect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); - connect(model, SIGNAL(layoutChanged()), this, SLOT(layoutChanged())); - connect(model, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(rowsInserted(QModelIndex, int, int))); - connect(model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(rowsRemoved(QModelIndex, int, int))); - connect(model, SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)), this, SLOT(rowsMoved(QModelIndex, int, int, QModelIndex, int))); -} - -void TestListModel::deleteDbFiles() -{ - // remove all the test files. - QDir currentDir; - QStringList nameFilter; - nameFilter << QString("*.db"); - QFileInfoList databaseFiles = currentDir.entryInfoList(nameFilter, QDir::Files); - foreach (QFileInfo fileInfo, databaseFiles) { - //qDebug() << "Deleted : " << fileInfo.fileName(); - QFile file(fileInfo.fileName()); - file.remove(); - } -} - -void TestListModel::initTestCase() -{ - // make sure there is no old db files. - deleteDbFiles(); - - QString socketName = QString("testjsondb_%1").arg(getpid()); - mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile); - - mClient = new JsonDbClient(this); - QVERIFY(mClient!= 0); - connectToServer(); - - QQmlEngine *engine = new QQmlEngine(); - QStringList pluginPaths = engine->importPathList(); - for (int i=0; (i<pluginPaths.count() && mPluginPath.isEmpty()); i++) { - QDir dir(pluginPaths[i]+"/QtAddOn/JsonDb"); - dir.setFilter(QDir::Files | QDir::NoSymLinks); - QFileInfoList list = dir.entryInfoList(); - for (int i = 0; i < list.size(); ++i) { - QString error; - if (engine->importPlugin(list.at(i).absoluteFilePath(), QString("QtAddOn.JsonDb"), &error)) { - mPluginPath = list.at(i).absoluteFilePath(); - break; - } - } - } - delete engine; - - // Create alot of items in the database - QVariantList friendsList; - for (int i=0; i<1000; i++) { - QVariantMap item; - item.insert("_type", "Friends"); - item.insert("name", QString("Name-%1").arg(i)); - item.insert("phone",QString("%1").arg(qrand())); - friendsList << item; - } - mId = mClient->create(friendsList); - - QVariantList ImageList; - for (int i=0; i<1000; i++) { - QVariantMap item; - item.insert("_type", "Image"); - item.insert("name", QString("Name-%1.jpg").arg(i)); - item.insert("location",QString("/home/qt/Pictures/Myfolder-%1").arg(i)); - ImageList << item; - } - mId = mClient->create(ImageList); - - QVariantList numberList; - for (int i=0; i<1000; i++) { - QVariantMap item; - item.insert("_type", "RandNumber"); - item.insert("number", qrand()%100); - numberList << item; - } - mId = mClient->create(numberList); - - QVariantList trollList; - for (int i=0; i<100; i++) { - QVariantMap item; - item.insert("_type", "Troll"); - item.insert("age", i); - item.insert("name", QString("Troll-%1").arg(i)); - trollList << item; - } - mId = mClient->create(trollList); - - mEventLoop.exec(QEventLoop::AllEvents); -} - -JsonDbListModel *TestListModel::createModel() -{ - ModelData *newModel = new ModelData(); - newModel->engine = new QQmlEngine(); - QString error; - if (!newModel->engine->importPlugin(mPluginPath, QString("QtAddOn.JsonDb"), &error)) { - qDebug()<<"Unable to load the plugin :"<<error; - delete newModel->engine; - return 0; - } - newModel->component = new QQmlComponent(newModel->engine); - newModel->component->setData("import QtQuick 2.0\nimport QtAddOn.JsonDb 1.0 \n JsonDbListModel {id: contactsModel}", QUrl()); - newModel->model = newModel->component->create(); - mModels.append(newModel); - return (JsonDbListModel*)(newModel->model); -} - -void TestListModel::deleteModel(JsonDbListModel *model) -{ - for (int i = 0; i < mModels.count(); i++) { - if (mModels[i]->model == model) { - ModelData *modelData = mModels.takeAt(i); - delete modelData; - return; - } - } -} - -void TestListModel::cleanupTestCase() -{ - if (mClient) { - delete mClient; - mClient = NULL; - } - - if (mProcess) { - mProcess->kill(); - mProcess->waitForFinished(); - delete mProcess; - mProcess = NULL; - } - deleteDbFiles(); -} - -void TestListModel::notified(const QString& notifyUuid, const QVariant& object, const QString& action) -{ - Q_UNUSED(notifyUuid); - Q_UNUSED(object); - Q_UNUSED(action); - //qDebug() << Q_FUNC_INFO << "notifyUuid=" << notifyUuid << "action=" << action << "object=" << object; - //mEventLoop.exit(0); -} - -void TestListModel::response(int id, const QVariant& data) -{ - //qDebug() << Q_FUNC_INFO << "id: " << id << data; - QMap<QString,QVariant> map = data.toMap(); - mLastUuid = map.value("_uuid").toString(); - mLastResponseData = data; - if (mId == id) - mEventLoop.exit(0); -} - -void TestListModel::error(int id, int code, const QString& message) -{ - qDebug() << Q_FUNC_INFO << "id:" << id << "code:" << code << "message:" << message; - if (mId == id) - mEventLoop.exit(0); -} - -void TestListModel::dataChanged(QModelIndex, QModelIndex) -{ - //qDebug() << "dataChanged(QModelIndex,QModelIndex)"; - mEventLoop.exit(0); -} - -void TestListModel::modelReset() -{ - //qDebug() << "modelReset()"; - mEventLoop.exit(0); -} - -void TestListModel::layoutChanged() -{ - //qDebug() << "layoutChanged()"; - mEventLoop.exit(0); -} - -void TestListModel::rowsInserted(QModelIndex parent, int start , int end) -{ - Q_UNUSED(parent); - qDebug() << QString("rowsInserted(QModelIndex, %1, %2)").arg(start).arg(end); - mEventLoop.exit(0); -} - -void TestListModel::rowsRemoved(QModelIndex parent, int start, int end) -{ - Q_UNUSED(parent); - qDebug() << QString("rowsRemoved(QModelIndex, %1, %2)").arg(start).arg(end); - mEventLoop.exit(0); -} - -void TestListModel::rowsMoved(QModelIndex sourceParent, int sourceStart, int sourceEnd, QModelIndex destinationParent, int destinationRow) -{ - Q_UNUSED(sourceParent); - Q_UNUSED(destinationParent); - qDebug() << QString("rowsMoved(QModelIndex, %1, %2, QModelIndex, %3)").arg(sourceStart).arg(sourceEnd).arg(destinationRow); - mEventLoop.exit(0); -} - -void TestListModel::createListModelHundredItems() -{ - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - - connectListModel(listModel); - QStringList rolenames; - rolenames << "age" << "name" << "_type"; - listModel->setScriptableRoleNames(rolenames); - - QBENCHMARK { - listModel->setQuery("[?_type=\"Troll\"]"); - mEventLoop.exec(QEventLoop::AllEvents); - } - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - - -void TestListModel::createListModelThousandItems() -{ - JsonDbListModel *listModel = createModel(); - - connectListModel(listModel); - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type"; - listModel->setScriptableRoleNames(rolenames); - - QBENCHMARK { - listModel->setQuery("[?_type=\"Friends\"]"); - mEventLoop.exec(QEventLoop::AllEvents); - } - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::createListModelGroupedQuery() -{ - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - - connectListModel(listModel); - QStringList rolenames; - rolenames << "_uuid" << "_type" << "number"; - listModel->setScriptableRoleNames(rolenames); - - QBENCHMARK { - listModel->setQuery("[?_type=\"RandNumber\"][?number=77]"); - mEventLoop.exec(QEventLoop::AllEvents); - } - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - - -void TestListModel::createListModelSortedQuery() -{ - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - - connectListModel(listModel); - - QStringList rolenames; - rolenames << "_uuid" << "_type" << "number"; - listModel->setScriptableRoleNames(rolenames); - - QBENCHMARK { - listModel->setQuery("[?_type=\"RandNumber\"][/number]"); - mEventLoop.exec(QEventLoop::AllEvents); - } - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::changeOneItemClient() -{ - - QString queryString("[?_type=\"Friends\"][?name=\"Name-1\"]"); - mId = mClient->query(queryString); - mEventLoop.exec(QEventLoop::AllEvents); - - QVariantMap mapResponse = mLastResponseData.toMap(); - QVariantMap item = mapResponse.value("data").toList().at(0).toMap(); - int i = mapResponse.value("length").toInt(); - QVERIFY(i == 1); - item.insert("phone","111122223"); - - // Make sure that we only exit the eventloop - // on listmodel updates. - disconnect(mClient, 0, this, 0); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type"; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Friends\"][/name]"); - connectListModel(listModel); - - mEventLoop.exec(QEventLoop::AllEvents); - - QBENCHMARK { - mId = mClient->update(item); - mEventLoop.exec(QEventLoop::AllEvents); - } - - connectToServer(); - - mEventLoop.processEvents(); - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::changeOneItemSet() -{ - // Make sure that we only exit the eventloop - // on listmodel updates. - disconnect(mClient, 0, this, 0); - mEventLoop.processEvents(); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type"; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Friends\"][/name]"); - connectListModel(listModel); - - mEventLoop.exec(QEventLoop::AllEvents); - - QJSEngine engine; - QJSValue value = engine.newObject(); - value.setProperty("phone", "987654321"); - - QBENCHMARK { - listModel->set(0,value); - mEventLoop.exec(QEventLoop::AllEvents); - } - - QVERIFY(listModel->get(0, "phone") == "987654321"); - deleteModel(listModel); -} - -void TestListModel::changeOneItemSetProperty() -{ - // Make sure that we only exit the eventloop - // on listmodel updates. - disconnect(mClient, 0, this, 0); - mEventLoop.processEvents(); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type"; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Friends\"]"); - connectListModel(listModel); - - mEventLoop.exec(QEventLoop::AllEvents); - - QBENCHMARK { - listModel->setProperty(1, "phone", "111122223"); - mEventLoop.exec(QEventLoop::AllEvents); - } - - connectToServer(); - - mEventLoop.processEvents(); - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::getOneItemInCache() -{ - disconnect(mClient, 0, this, 0); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - connectListModel(listModel); - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type" ; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Friends\"]"); - mEventLoop.exec(QEventLoop::AllEvents); - - QBENCHMARK { - QVariant res = listModel->data(listModel->index(10,0), listModel->roleFromString("name")); - // Since it is in the cache the fetch value should be valid at this point. - QVERIFY(res.isValid()); - } - - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::getOneItemNotInCache() -{ - disconnect(mClient, 0, this, 0); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - connectListModel(listModel); - listModel->setLimit(80); - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type"; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Friends\"][/name]"); - mEventLoop.exec(QEventLoop::AllEvents); - - bool flip = true; // so we can run multiple benchmarks - - QBENCHMARK { - QVariant res; - if (flip) - res = listModel->data(listModel->index(960,0), listModel->roleFromString("name")); - else - res = listModel->data(listModel->index(10,0), listModel->roleFromString("name")); - - flip = !flip; - } - - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::getOneItemNotInCacheThousandItems() -{ - disconnect(mClient, 0, this, 0); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - connectListModel(listModel); - listModel->setLimit(80); - QStringList rolenames; - rolenames << "name" << "location" << "_type"; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Image\"][/name]"); - mEventLoop.exec(QEventLoop::AllEvents); - - QVERIFY(listModel->count() == 1000); - - bool flip = true; // so we can run multiple benchmarks - - QBENCHMARK { - QVariant res; - if (flip) - res = listModel->data(listModel->index(980,0), listModel->roleFromString("name")); - else - res = listModel->data(listModel->index(10,0), listModel->roleFromString("name")); - - flip = !flip; - } - - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestListModel::scrollThousandItems() -{ - disconnect(mClient, 0, this, 0); - mEventLoop.processEvents(); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - QStringList rolenames; - rolenames << "name" << "phone" << "_uuid" << "_type"; - listModel->setScriptableRoleNames(rolenames); - listModel->setQuery("[?_type=\"Friends\"][/name]"); - listModel->setLimit(80); - connectListModel(listModel); - - mEventLoop.exec(QEventLoop::AllEvents); - - int rowCount = listModel->rowCount(); - - QBENCHMARK { - for( int i=0 ; i<rowCount; i++) - foreach(QString role, rolenames) - listModel->data(listModel->index(i,0), listModel->roleFromString(role)); - } - deleteModel(listModel); -} - - -QTEST_MAIN(TestListModel) diff --git a/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.h b/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.h deleted file mode 100644 index b0a0d9f..0000000 --- a/tests/benchmarks/jsondb-listmodel/listmodel-benchmark.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef LISTMODEL_BENCHMARK_H -#define LISTMODEL_BENCHMARK_H - -#include <QCoreApplication> -#include <QProcess> -#include <QTest> -#include <QDebug> - -#include <QEventLoop> -#include <QLocalSocket> - -#include <jsondb-client.h> -#include <jsondb-error.h> - -#include "clientwrapper.h" -#include "jsondb-listmodel.h" - -QT_BEGIN_NAMESPACE -class QQmlEngine; -class QQmlComponent; -QT_END_NAMESPACE - -QT_USE_NAMESPACE_JSONDB -class JsonDbListModel; - -class ModelData { -public: - ModelData(); - ~ModelData(); - QQmlEngine *engine; - QQmlComponent *component; - QObject *model; -}; - -class TestListModel: public ClientWrapper -{ - Q_OBJECT -public: - TestListModel(); - ~TestListModel(); - - void deleteDbFiles(); - void connectListModel(JsonDbListModel *model); - -public slots: - void notified(const QString& notifyUuid, const QVariant& object, const QString& action); - void response(int id, const QVariant& data); - void error(int id, int code, const QString& message); - - void dataChanged(QModelIndex,QModelIndex); - void modelReset(); - void layoutChanged(); - void rowsInserted(QModelIndex, int, int); - void rowsRemoved(QModelIndex, int, int); - void rowsMoved(QModelIndex, int, int, QModelIndex, int); - -private slots: - void initTestCase(); - void cleanupTestCase(); - - void createListModelHundredItems(); - void createListModelThousandItems(); - void createListModelGroupedQuery(); - void createListModelSortedQuery(); - void changeOneItemClient(); - void changeOneItemSet(); - void changeOneItemSetProperty(); - void getOneItemInCache(); - void getOneItemNotInCache(); - void getOneItemNotInCacheThousandItems(); - void scrollThousandItems(); -private: - JsonDbListModel *createModel(); - void deleteModel(JsonDbListModel *model); -private: - QProcess *mProcess; - QVariant mLastResponseData; - QList<ModelData*> mModels; - QString mPluginPath; -}; - -#endif diff --git a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp index 68c6485..9a3e430 100644 --- a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp +++ b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.cpp @@ -41,11 +41,10 @@ #include <QtTest/QtTest> #include <QJSEngine> +#include <QQmlListReference> #include "jsondbcachinglistmodel-bench.h" -#include "../../shared/util.h" -#include <QQmlListReference> -#include "json.h" +#include "util.h" static const char dbfile[] = "dbFile-jsondb-cached-listmodel"; ModelData::ModelData(): engine(0), component(0), model(0) @@ -56,25 +55,26 @@ ModelData::~ModelData() { if (model) delete model; - if (partition1) - delete partition1; - if (partition2) - delete partition2; - if (component) delete component; - if (partitionComponent1) - delete partitionComponent1; - if (partitionComponent2) - delete partitionComponent2; - if (engine) delete engine; } +const QString qmlProgram = QLatin1String( + "import QtQuick 2.0 \n" + "import QtJsonDb 1.0 as JsonDb \n" + "JsonDb.JsonDbCachingListModel {" + "signal callbackSignal(variant index, variant response);" + "id: contactsModel; cacheSize: 75;" + "partitions: [" + "JsonDb.Partition {name: \"com.nokia.shared.1\"}," + "JsonDb.Partition {name: \"com.nokia.shared.2\"}" + "]" + "}"); + JsonDbCachingListModelBench::JsonDbCachingListModelBench() - : mWaitingForNotification(false), mWaitingForDataChange(false), mWaitingForRowsRemoved(false) { } @@ -97,20 +97,6 @@ void JsonDbCachingListModelBench::deleteDbFiles() } } -QVariant JsonDbCachingListModelBench::readJsonFile(const QString& filename) -{ - QString filepath = findFile(filename); - QFile jsonFile(filepath); - jsonFile.open(QIODevice::ReadOnly); - QByteArray json = jsonFile.readAll(); - JsonReader parser; - bool ok = parser.parse(json); - if (!ok) { - qDebug() << filepath << parser.errorString(); - } - return parser.result(); -} - void JsonDbCachingListModelBench::connectListModel(QAbstractListModel *model) { connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); @@ -129,29 +115,26 @@ void JsonDbCachingListModelBench::initTestCase() deleteDbFiles(); QString socketName = QString("testjsondb_%1").arg(getpid()); - mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile); + mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__); - mClient = new JsonDbClient(this); - connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)), - this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification))); - connect( mClient, SIGNAL(response(int, const QVariant&)), - this, SLOT(response(int, const QVariant&))); - connect( mClient, SIGNAL(error(int, int, const QString&)), - this, SLOT(error(int, int, const QString&))); + connection = new QJsonDbConnection(); + connection->connectToServer(); mPluginPath = findQMLPluginPath("QtJsonDb"); + if (mPluginPath.isEmpty()) + qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb"; // Create the shared Partitions QVariantMap item; item.insert("_type", "Partition"); item.insert("name", "com.nokia.shared.1"); - int id = mClient->create(item); + int id = create(item); waitForResponse1(id); item.clear(); item.insert("_type", "Partition"); item.insert("name", "com.nokia.shared.2"); - id = mClient->create(item); + id = create(item); waitForResponse1(id); } @@ -167,9 +150,8 @@ QAbstractListModel *JsonDbCachingListModelBench::createModel() return 0; } newModel->component = new QQmlComponent(newModel->engine); - newModel->component->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n" - "JsonDb.JsonDbCachingListModel {signal callbackSignal(variant index, variant response); id: contactsModel; cacheSize: 200;}", - QUrl()); + newModel->component->setData(qmlProgram.toLocal8Bit(), QUrl()); + newModel->model = newModel->component->create(); if (newModel->component->isError()) qDebug() << newModel->component->errors(); @@ -177,27 +159,6 @@ QAbstractListModel *JsonDbCachingListModelBench::createModel() QObject::connect(newModel->model, SIGNAL(callbackSignal(QVariant, QVariant)), this, SLOT(callbackSlot(QVariant, QVariant))); - newModel->partitionComponent1 = new QQmlComponent(newModel->engine); - newModel->partitionComponent1->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n" - "JsonDb.Partition {name: \"com.nokia.shared.1\"}", - QUrl()); - newModel->partition1 = newModel->partitionComponent1->create(); - if (newModel->partitionComponent1->isError()) - qDebug() << newModel->partitionComponent1->errors(); - - - newModel->partitionComponent2 = new QQmlComponent(newModel->engine); - newModel->partitionComponent2->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n" - "JsonDb.Partition {name: \"com.nokia.shared.2\"}", - QUrl()); - newModel->partition2 = newModel->partitionComponent2->create(); - if (newModel->partitionComponent2->isError()) - qDebug() << newModel->partitionComponent2->errors(); - - QQmlListReference partitions(newModel->model, "partitions", newModel->engine); - partitions.append(newModel->partition1); - partitions.append(newModel->partition2); - mModels.append(newModel); return (QAbstractListModel*)(newModel->model); } @@ -216,9 +177,9 @@ void JsonDbCachingListModelBench::deleteModel(QAbstractListModel *model) // Delete all the items of this type from JsonDb void JsonDbCachingListModelBench::deleteItems(const QString &type, const QString &partition) { - int id = mClient->query(QString("[?_type=\"%1\"]").arg(type), 0, -1, partition); + int id = query(QString("[?_type=\"%1\"]").arg(type), partition); waitForResponse1(id); - id = mClient->remove(mData.toMap().value("data"), partition); + id = remove(lastResult, partition); waitForResponse1(id); } @@ -239,20 +200,26 @@ void JsonDbCachingListModelBench::callbackSlot(QVariant error, QVariant response callbackError = error.isValid(); callbackMeta = response; callbackResponse = response.toMap().value("object"); - mEventLoop.quit(); + eventLoop1.quit(); } void JsonDbCachingListModelBench::getIndex(int index) { mCallbackReceived = false; - const QString createString = QString("get(%1, function (error, response) {callbackSignal(error, response);});"); + const QString createString = QString("get(%1, function (error, response) { callbackSignal(error, response);});"); const QString getString = QString(createString).arg(index); QQmlExpression expr(mModels.last()->engine->rootContext(), mModels.last()->model, getString); expr.evaluate().toInt(); if (!mCallbackReceived) - waitForCallback(); + waitForCallback1(); +} + +QVariant JsonDbCachingListModelBench::getIndexRaw(QAbstractListModel *model, int index, int role) +{ + QVariant val = model->data(model->index(index), role); + return val; } void JsonDbCachingListModelBench::createIndex(const QString &property, const QString &propertyType) @@ -263,10 +230,10 @@ void JsonDbCachingListModelBench::createIndex(const QString &property, const QSt item.insert("propertyName", property); item.insert("propertyType", propertyType); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); - id = mClient->create(item, "com.nokia.shared.2"); + id = create(item, "com.nokia.shared.2"); waitForResponse1(id); } @@ -274,12 +241,13 @@ void JsonDbCachingListModelBench::createIndex(const QString &property, const QSt // Populate model of 300 items. void JsonDbCachingListModelBench::ModelStartup() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -297,9 +265,11 @@ void JsonDbCachingListModelBench::ModelStartup() QCOMPARE(listModel->rowCount(), 0); QBENCHMARK_ONCE { - waitForStateOrTimeout(); + mWaitingForReset = true; + waitForExitOrTimeout(); } + QCOMPARE(mWaitingForReset, false); QCOMPARE(listModel->rowCount(), 300); deleteItems(__FUNCTION__, "com.nokia.shared.1"); @@ -309,19 +279,20 @@ void JsonDbCachingListModelBench::ModelStartup() // Populate model of 300 items two partitions. void JsonDbCachingListModelBench::ModelStartupTwoPartitions() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i = i+2) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } for (int i=1; i < 300; i = i+2) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.2"); + int id = create(item, "com.nokia.shared.2"); waitForResponse1(id); } @@ -339,7 +310,8 @@ void JsonDbCachingListModelBench::ModelStartupTwoPartitions() QCOMPARE(listModel->rowCount(), 0); QBENCHMARK_ONCE { - waitForStateOrTimeout(); + mWaitingForReset = true; + waitForExitOrTimeout(); } QCOMPARE(listModel->rowCount(), 300); @@ -353,12 +325,13 @@ void JsonDbCachingListModelBench::ModelStartupTwoPartitions() // Populate model of 300 items sorted. void JsonDbCachingListModelBench::ModelStartupSorted() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -377,7 +350,8 @@ void JsonDbCachingListModelBench::ModelStartupSorted() QCOMPARE(listModel->rowCount(), 0); QBENCHMARK_ONCE { - waitForStateOrTimeout(); + mWaitingForReset = true; + waitForExitOrTimeout(); } QCOMPARE(listModel->rowCount(), 300); @@ -389,11 +363,12 @@ void JsonDbCachingListModelBench::ModelStartupSorted() void JsonDbCachingListModelBench::getItemNotInCache() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -411,9 +386,9 @@ void JsonDbCachingListModelBench::getItemNotInCache() // now start it working QCOMPARE(listModel->rowCount(), 0); - waitForStateOrTimeout(); + mWaitingForReset = true; + waitForExitOrTimeout(); QCOMPARE(listModel->rowCount(), 300); - // Now get some items so we know that index 20 is not in the cache getIndex(100); getIndex(151); @@ -430,11 +405,12 @@ void JsonDbCachingListModelBench::getItemNotInCache() void JsonDbCachingListModelBench::deleteItem() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -450,7 +426,8 @@ void JsonDbCachingListModelBench::deleteItem() connectListModel(listModel); // now start it working - waitForStateOrTimeout(); + mWaitingForReset = true; + waitForExitOrTimeout(); QCOMPARE(listModel->rowCount(), 300); QVariantMap itemToRemove; @@ -466,11 +443,13 @@ void JsonDbCachingListModelBench::deleteItem() getIndex(255); // Delete the item - mClient->remove(itemToRemove, "com.nokia.shared.1"); + int id = remove(itemToRemove, "com.nokia.shared.1"); QBENCHMARK_ONCE { waitForItemChanged(true); } + while (lastRequestId < id) + waitForResponse1(id); QCOMPARE(listModel->rowCount(), 299); @@ -478,18 +457,77 @@ void JsonDbCachingListModelBench::deleteItem() deleteModel(listModel); } +void JsonDbCachingListModelBench::flicking() +{ + resetWaitFlags(); + QVariantList items; + QVariantMap item; + for (int i=0; i < 300; i++) { + item.insert("_type", __FUNCTION__); + item.insert("name", QString("Arnie_%1").arg(i)); + items.append(item); + } + int id = create(items, "com.nokia.shared.1"); + waitForResponse1(id); + + items.clear(); + for (int i=0; i < 300; i++) { + item.insert("_type", __FUNCTION__); + item.insert("name", QString("Bertta_%1").arg(i)); + items.append(item); + } + id = create(items, "com.nokia.shared.2"); + waitForResponse1(id); + + createIndex("name", "string"); + + QAbstractListModel *listModel = createModel(); + if (!listModel) return; + listModel->setProperty("cacheSize", 75); + listModel->setProperty("sortOrder", "[/name]"); + QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name"); + listModel->setProperty("roleNames", roleNames); + listModel->setProperty("query", QString("[?_type=\"%1\"]").arg(__FUNCTION__)); + connectListModel(listModel); + + // now start it working + mWaitingForReset = true; + waitForExitOrTimeout(); + QCOMPARE(listModel->rowCount(), 600); + + int noOfCacheMisses = 0; + mItemsUpdated = 0; + // simulate flicking through lhe list + for (int i = 0; i < 600; i++) { + QVariant nameVariant = getIndexRaw (listModel, i, 2); + if (nameVariant.isNull()) + noOfCacheMisses++; + waitForMs(10, 6); + } + + deleteItems(__FUNCTION__, "com.nokia.shared.1"); + deleteItems(__FUNCTION__, "com.nokia.shared.2"); + deleteModel(listModel); +} + void JsonDbCachingListModelBench::modelReset() { - mWaitingForReset = false; - mEventLoop2.exit(0); + if (mWaitingForReset) { + mWaitingForReset = false; + eventLoop1.exit(0); + } } void JsonDbCachingListModelBench::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { Q_UNUSED(topLeft); Q_UNUSED(bottomRight); - mWaitingForDataChange = false; + mItemsUpdated++; + if (mWaitingForChanged) { + mWaitingForChanged = false; + eventLoop1.exit(0); + } } void JsonDbCachingListModelBench::rowsInserted(const QModelIndex &parent, int first, int last) @@ -497,8 +535,11 @@ void JsonDbCachingListModelBench::rowsInserted(const QModelIndex &parent, int fi Q_UNUSED(parent); Q_UNUSED(first); Q_UNUSED(last); - mItemsCreated++; - mEventLoop2.exit(0); + mItemsCreated += last-first+1; + if (mWaitingForRowsInserted) { + mWaitingForRowsInserted = false; + eventLoop1.exit(0); + } } void JsonDbCachingListModelBench::rowsRemoved(const QModelIndex &parent, int first, int last) @@ -506,7 +547,11 @@ void JsonDbCachingListModelBench::rowsRemoved(const QModelIndex &parent, int fir Q_UNUSED(parent); Q_UNUSED(first); Q_UNUSED(last); - mWaitingForRowsRemoved = false; + mItemsRemoved += last-first+1; + if (mWaitingForRemoved) { + mWaitingForRemoved = false; + eventLoop1.exit(0); + } } void JsonDbCachingListModelBench::rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row ) @@ -522,83 +567,143 @@ void JsonDbCachingListModelBench::stateChanged() { // only exit on ready state. QAbstractListModel *model = qobject_cast<QAbstractListModel *>(sender()); - if (model->property("state") == 2) { + if (model->property("state").toInt() == 2 && mWaitingForStateChanged) { mWaitingForStateChanged = false; - mEventLoop2.exit(0); + eventLoop1.exit(0); } } void JsonDbCachingListModelBench::waitForItemsCreated(int items) { - mTimeoutCalled = false; + mTimedOut = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); + timer.start(clientTimeout); + elapsedTimer.start(); - mItemsCreated = 0; - while (mItemsCreated != items && !mTimeoutCalled) - mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout); + while (!mTimedOut && mItemsCreated != items) { + mWaitingForRowsInserted = true; + eventLoop1.exec(QEventLoop::AllEvents); + } + if (mTimedOut) + qDebug () << "waitForItemsCreated Timed out"; +} + +void JsonDbCachingListModelBench::waitForItemsUpdated(int items) +{ + mTimedOut = false; + QTimer timer; + QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.start(clientTimeout); + elapsedTimer.start(); + + while (!mTimedOut && mItemsUpdated != items) { + mWaitingForChanged = true; + eventLoop1.exec(QEventLoop::AllEvents); + } + if (mTimedOut) + qDebug () << "waitForItemsUpdated Timed out"; } void JsonDbCachingListModelBench::waitForExitOrTimeout() { - mTimeoutCalled = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); - mEventLoop2.exec(QEventLoop::AllEvents); + timer.start(clientTimeout); + elapsedTimer.start(); + eventLoop1.exec(QEventLoop::AllEvents); +} + +void JsonDbCachingListModelBench::waitForMs(int ms, int warningThreshold) +{ + QTimer timer; + QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(silentTimeout())); + timer.start(ms); + qint64 elap; + QElapsedTimer elt; + elt.start(); + eventLoop1.exec(QEventLoop::AllEvents); + if ((elap = elt.elapsed()) > ms+warningThreshold) + qDebug() << "Some event took more than " << warningThreshold << "ms" << "(" << elap-ms << "ms )"; } void JsonDbCachingListModelBench::waitForStateOrTimeout() { - mTimeoutCalled = false; + mTimedOut = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); + timer.start(clientTimeout); + elapsedTimer.start(); - mWaitingForStateChanged = true; - while (mWaitingForStateChanged && !mTimeoutCalled) - mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout); + while (mWaitingForStateChanged && !mTimedOut) { + eventLoop1.exec(QEventLoop::AllEvents); + } + if (mTimedOut) + qDebug () << "waitForStateOrTimeout Timed out"; } void JsonDbCachingListModelBench::timeout() { - ClientWrapper::timeout(); - mTimeoutCalled = true; + qDebug () << "JsonDbCachingListModelBench::timeout()"; + RequestWrapper::timeout(); mTimedOut = true; + eventLoop1.quit(); +} + +void JsonDbCachingListModelBench::silentTimeout() +{ + eventLoop1.quit(); +} + +void JsonDbCachingListModelBench::resetWaitFlags() +{ + mItemsCreated = 0; + mItemsUpdated = 0; + mItemsRemoved = 0; + mWaitingForStateChanged = false; + mWaitingForRowsInserted = false; + mWaitingForReset = false; + mWaitingForChanged = false; + mWaitingForRemoved = false; } void JsonDbCachingListModelBench::waitForItemChanged(bool waitForRemove) { - mTimeoutCalled = false; + mTimedOut = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); + timer.start(clientTimeout); + elapsedTimer.start(); - mWaitingForRowsRemoved = true; - mWaitingForDataChange = true; + mWaitingForRemoved = true; + mWaitingForChanged = true; mItemsCreated = 0; mWaitingForReset = true; + mWaitingForStateChanged = true; bool waitMore = true; - while (waitMore && !mTimeoutCalled) { - if (!mWaitingForDataChange) + while (waitMore && !mTimedOut) { + if (!mWaitingForChanged) { + //qDebug() << "waitForItemChanged: mWaitingForChanged"; + break; + } + if (!mWaitingForStateChanged) { + //qDebug() << "waitForItemChanged: mWaitingForStateChanged"; break; - if (mItemsCreated) + } + if (mItemsCreated){ + //qDebug() << "waitForItemChanged: mItemsCreated"; break; - if (!mWaitingForReset) + } + if (!mWaitingForReset){ + //qDebug() << "waitForItemChanged: mWaitingForReset"; break; - if (waitForRemove && !mWaitingForRowsRemoved) + } + if (waitForRemove && !mWaitingForRemoved){ + //qDebug() << "waitForItemChanged: mWaitingForRemoved"; break; - mEventLoop2.processEvents(QEventLoop::AllEvents); + } + eventLoop1.exec(QEventLoop::AllEvents); } } QTEST_MAIN(JsonDbCachingListModelBench) diff --git a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.h b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.h index cfac030..2096dcd 100644 --- a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.h +++ b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel-bench.h @@ -41,22 +41,9 @@ #ifndef JsonDbCachingListModel_Bench_H #define JsonDbCachingListModel_Bench_H -#include <QCoreApplication> -#include <QList> -#include <QTest> -#include <QFile> -#include <QProcess> -#include <QEventLoop> -#include <QDebug> -#include <QLocalSocket> -#include <QTimer> - -#include <jsondb-client.h> -#include <jsondb-error.h> - #include <QAbstractListModel> -#include "clientwrapper.h" -#include "../../shared/qmltestutil.h" +#include "requestwrapper.h" +#include "qmltestutil.h" QT_BEGIN_NAMESPACE class QQmlEngine; @@ -65,22 +52,16 @@ QT_END_NAMESPACE QT_USE_NAMESPACE_JSONDB -class JsonDbListModel; - class ModelData { public: ModelData(); ~ModelData(); QQmlEngine *engine; QQmlComponent *component; - QQmlComponent *partitionComponent1; - QQmlComponent *partitionComponent2; QObject *model; - QObject *partition1; - QObject *partition2; }; -class JsonDbCachingListModelBench: public ClientWrapper +class JsonDbCachingListModelBench: public RequestWrapper { Q_OBJECT public: @@ -97,12 +78,11 @@ public slots: void rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row ); void modelReset(); void stateChanged(); - void callbackSlot(QVariant error, QVariant response); - protected slots: void timeout(); + void silentTimeout(); private slots: void initTestCase(); @@ -112,41 +92,39 @@ private slots: void ModelStartupSorted(); void getItemNotInCache(); void deleteItem(); + void flicking(); private: void waitForExitOrTimeout(); void waitForItemsCreated(int items); + void waitForItemsUpdated(int items); void waitForStateOrTimeout(); + void waitForMs(int ms, int warningThreshold); void waitForItemChanged(bool waitForRemove = false); QStringList getOrderValues(QAbstractListModel *listModel); void getIndex(int index); + QVariant getIndexRaw(QAbstractListModel *model, int index, int role); void createIndex(const QString &property, const QString &propertyType); QAbstractListModel *createModel(); void deleteModel(QAbstractListModel *model); void deleteItems(const QString &type, const QString &partition); - QVariant readJsonFile(const QString &filename); + void resetWaitFlags(); private: QProcess *mProcess; - QStringList mNotificationsReceived; QList<ModelData*> mModels; QString mPluginPath; - QEventLoop mEventLoop2; // for all listmodel slots // Response values + bool mTimedOut; int mItemsCreated; - bool mWaitingForNotification; - bool mWaitingForDataChange; - bool mWaitingForRowsRemoved; - bool mTimeoutCalled; - bool mWaitingForReset; + int mItemsUpdated; + int mItemsRemoved; bool mWaitingForStateChanged; - - bool mTimedOut; - bool callbackError; - bool mCallbackReceived; - QVariant callbackMeta; - QVariant callbackResponse; + bool mWaitingForRowsInserted; + bool mWaitingForReset; + bool mWaitingForChanged; + bool mWaitingForRemoved; }; diff --git a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel.pro b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel.pro index 1c0d1ae..0e69fcb 100644 --- a/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel.pro +++ b/tests/benchmarks/jsondbcachinglistmodel/jsondbcachinglistmodel.pro @@ -3,15 +3,15 @@ TARGET = tst_bench_jsondbcachinglistmodel DEPENDPATH += . INCLUDEPATH += . -QT = core network testlib gui qml jsondbcompat-private +QT = core network testlib gui qml jsondb CONFIG -= app_bundle CONFIG += testcase include($$PWD/../../shared/shared.pri) -include($$PWD/../../../src/3rdparty/qjson/qjson.pri) DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\" DEFINES += SRCDIR=\\\"$$PWD/\\\" -HEADERS += jsondbcachinglistmodel-bench.h +HEADERS += jsondbcachinglistmodel-bench.h \ + $$PWD/../../shared/requestwrapper.h SOURCES += jsondbcachinglistmodel-bench.cpp diff --git a/tests/benchmarks/jsondbcachinglistmodel/partitions.json b/tests/benchmarks/jsondbcachinglistmodel/partitions.json new file mode 100644 index 0000000..1cdd0fa --- /dev/null +++ b/tests/benchmarks/jsondbcachinglistmodel/partitions.json @@ -0,0 +1,4 @@ +[ + { "name" :"com.nokia.shared.1" }, + { "name" :"com.nokia.shared.2" } +] diff --git a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp index 9691f2b..1e99306 100644 --- a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp +++ b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.cpp @@ -43,9 +43,8 @@ #include <QJSEngine> #include "jsondbsortinglistmodel-bench.h" -#include "../../shared/util.h" +#include "util.h" #include <QQmlListReference> -#include "json.h" static const char dbfile[] = "dbFile-jsondb-cached-listmodel"; ModelData::ModelData(): engine(0), component(0), model(0) @@ -56,25 +55,21 @@ ModelData::~ModelData() { if (model) delete model; - if (partition1) - delete partition1; - if (partition2) - delete partition2; - if (component) delete component; - if (partitionComponent1) - delete partitionComponent1; - if (partitionComponent2) - delete partitionComponent2; - if (engine) delete engine; } +const QString qmlProgram = QLatin1String( + "import QtQuick 2.0\n" + "import QtJsonDb 1.0 as JsonDb \n" + "JsonDb.JsonDbSortingListModel {" + "id: contactsModel;" + "partitions: [JsonDb.Partition {name: \"com.nokia.shared.1\"}, JsonDb.Partition {name: \"com.nokia.shared.2\"}]" + "}"); JsonDbSortingListModelBench::JsonDbSortingListModelBench() - : mWaitingForNotification(false), mWaitingForDataChange(false), mWaitingForRowsRemoved(false) { } @@ -97,20 +92,6 @@ void JsonDbSortingListModelBench::deleteDbFiles() } } -QVariant JsonDbSortingListModelBench::readJsonFile(const QString& filename) -{ - QString filepath = findFile(filename); - QFile jsonFile(filepath); - jsonFile.open(QIODevice::ReadOnly); - QByteArray json = jsonFile.readAll(); - JsonReader parser; - bool ok = parser.parse(json); - if (!ok) { - qDebug() << filepath << parser.errorString(); - } - return parser.result(); -} - void JsonDbSortingListModelBench::connectListModel(QAbstractListModel *model) { connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); @@ -129,29 +110,26 @@ void JsonDbSortingListModelBench::initTestCase() deleteDbFiles(); QString socketName = QString("testjsondb_%1").arg(getpid()); - mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile); + mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__); - mClient = new JsonDbClient(this); - connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)), - this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification))); - connect( mClient, SIGNAL(response(int, const QVariant&)), - this, SLOT(response(int, const QVariant&))); - connect( mClient, SIGNAL(error(int, int, const QString&)), - this, SLOT(error(int, int, const QString&))); + connection = new QJsonDbConnection(); + connection->connectToServer(); mPluginPath = findQMLPluginPath("QtJsonDb"); + if (mPluginPath.isEmpty()) + qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb"; // Create the shared Partitions QVariantMap item; item.insert("_type", "Partition"); item.insert("name", "com.nokia.shared.1"); - int id = mClient->create(item); + int id = create(item); waitForResponse1(id); item.clear(); item.insert("_type", "Partition"); item.insert("name", "com.nokia.shared.2"); - id = mClient->create(item); + id = create(item); waitForResponse1(id); } @@ -167,37 +145,12 @@ QAbstractListModel *JsonDbSortingListModelBench::createModel() return 0; } newModel->component = new QQmlComponent(newModel->engine); - newModel->component->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n" - "JsonDb.JsonDbCachingListModel {signal callbackSignal(variant index, variant response); id: contactsModel;}", - QUrl()); + newModel->component->setData(qmlProgram.toLocal8Bit(), QUrl()); + newModel->model = newModel->component->create(); if (newModel->component->isError()) qDebug() << newModel->component->errors(); - QObject::connect(newModel->model, SIGNAL(callbackSignal(QVariant, QVariant)), - this, SLOT(callbackSlot(QVariant, QVariant))); - - newModel->partitionComponent1 = new QQmlComponent(newModel->engine); - newModel->partitionComponent1->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n" - "JsonDb.Partition {name: \"com.nokia.shared.1\"}", - QUrl()); - newModel->partition1 = newModel->partitionComponent1->create(); - if (newModel->partitionComponent1->isError()) - qDebug() << newModel->partitionComponent1->errors(); - - - newModel->partitionComponent2 = new QQmlComponent(newModel->engine); - newModel->partitionComponent2->setData("import QtQuick 2.0\nimport QtJsonDb 1.0 as JsonDb \n" - "JsonDb.Partition {name: \"com.nokia.shared.2\"}", - QUrl()); - newModel->partition2 = newModel->partitionComponent2->create(); - if (newModel->partitionComponent2->isError()) - qDebug() << newModel->partitionComponent2->errors(); - - QQmlListReference partitions(newModel->model, "partitions", newModel->engine); - partitions.append(newModel->partition1); - partitions.append(newModel->partition2); - mModels.append(newModel); return (QAbstractListModel*)(newModel->model); } @@ -216,9 +169,9 @@ void JsonDbSortingListModelBench::deleteModel(QAbstractListModel *model) // Delete all the items of this type from JsonDb void JsonDbSortingListModelBench::deleteItems(const QString &type, const QString &partition) { - int id = mClient->query(QString("[?_type=\"%1\"]").arg(type), 0, -1, partition); + int id = query(QString("[?_type=\"%1\"]").arg(type), partition); waitForResponse1(id); - id = mClient->remove(mData.toMap().value("data"), partition); + id = remove(lastResult, partition); waitForResponse1(id); } @@ -233,26 +186,12 @@ void JsonDbSortingListModelBench::cleanupTestCase() deleteDbFiles(); } -void JsonDbSortingListModelBench::callbackSlot(QVariant error, QVariant response) -{ - mCallbackReceived = true; - callbackError = error.isValid(); - callbackMeta = response; - callbackResponse = response.toMap().value("object"); - mEventLoop.quit(); -} - void JsonDbSortingListModelBench::getIndex(int index) { - mCallbackReceived = false; - - const QString createString = QString("get(%1, function (error, response) {callbackSignal(error, response);});"); + const QString createString = QString("get(%1);"); const QString getString = QString(createString).arg(index); QQmlExpression expr(mModels.last()->engine->rootContext(), mModels.last()->model, getString); - expr.evaluate().toInt(); - - if (!mCallbackReceived) - waitForCallback(); + callbackResponse = expr.evaluate(); } void JsonDbSortingListModelBench::createIndex(const QString &property, const QString &propertyType) @@ -263,10 +202,10 @@ void JsonDbSortingListModelBench::createIndex(const QString &property, const QSt item.insert("propertyName", property); item.insert("propertyType", propertyType); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); - id = mClient->create(item, "com.nokia.shared.2"); + id = create(item, "com.nokia.shared.2"); waitForResponse1(id); } @@ -274,12 +213,13 @@ void JsonDbSortingListModelBench::createIndex(const QString &property, const QSt // Populate model of 300 items. void JsonDbSortingListModelBench::ModelStartup() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -295,8 +235,8 @@ void JsonDbSortingListModelBench::ModelStartup() // now start it working QCOMPARE(listModel->rowCount(), 0); - QBENCHMARK_ONCE { + mWaitingForStateChanged = true; waitForStateOrTimeout(); } @@ -309,19 +249,20 @@ void JsonDbSortingListModelBench::ModelStartup() // Populate model of 300 items two partitions. void JsonDbSortingListModelBench::ModelStartupTwoPartitions() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i = i+2) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } for (int i=1; i < 300; i = i+2) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.2"); + int id = create(item, "com.nokia.shared.2"); waitForResponse1(id); } @@ -339,9 +280,11 @@ void JsonDbSortingListModelBench::ModelStartupTwoPartitions() QCOMPARE(listModel->rowCount(), 0); QBENCHMARK_ONCE { + mWaitingForStateChanged = true; waitForStateOrTimeout(); } + QCOMPARE(mWaitingForReset, false); QCOMPARE(listModel->rowCount(), 300); deleteItems(__FUNCTION__, "com.nokia.shared.1"); @@ -353,12 +296,13 @@ void JsonDbSortingListModelBench::ModelStartupTwoPartitions() // Populate model of 300 items sorted. void JsonDbSortingListModelBench::ModelStartupSorted() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -377,9 +321,11 @@ void JsonDbSortingListModelBench::ModelStartupSorted() QCOMPARE(listModel->rowCount(), 0); QBENCHMARK_ONCE { + mWaitingForStateChanged = true; waitForStateOrTimeout(); } + QCOMPARE(mWaitingForReset, false); QCOMPARE(listModel->rowCount(), 300); deleteItems(__FUNCTION__, "com.nokia.shared.1"); @@ -387,13 +333,14 @@ void JsonDbSortingListModelBench::ModelStartupSorted() } -void JsonDbSortingListModelBench::getItemNotInCache() +void JsonDbSortingListModelBench::getItems() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -409,8 +356,10 @@ void JsonDbSortingListModelBench::getItemNotInCache() // now start it working QCOMPARE(listModel->rowCount(), 0); - + mWaitingForStateChanged = true; waitForStateOrTimeout(); + + QCOMPARE(mWaitingForReset, false); QCOMPARE(listModel->rowCount(), 300); // Now get some items so we know that index 20 is not in the cache @@ -429,11 +378,12 @@ void JsonDbSortingListModelBench::getItemNotInCache() void JsonDbSortingListModelBench::deleteItem() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 300; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -448,14 +398,16 @@ void JsonDbSortingListModelBench::deleteItem() connectListModel(listModel); // now start it working + mWaitingForStateChanged = true; waitForStateOrTimeout(); QCOMPARE(listModel->rowCount(), 300); QVariantMap itemToRemove; // get the item that we shall remove getIndex(20); - itemToRemove.insert("_uuid", callbackResponse.toMap().value("_uuid").toString()); - itemToRemove.insert("_version", callbackResponse.toMap().value("_version").toString()); + QVariantMap retrievedItem = callbackResponse.toMap().value("object").toMap(); + itemToRemove.insert("_uuid", retrievedItem.value("_uuid").toString()); + itemToRemove.insert("_version", retrievedItem.value("_version").toString()); // Now get some items so we know that index 20 is not in the cache getIndex(100); @@ -464,11 +416,13 @@ void JsonDbSortingListModelBench::deleteItem() getIndex(255); // Delete the item - mClient->remove(itemToRemove, "com.nokia.shared.1"); + int id = remove(itemToRemove, "com.nokia.shared.1"); QBENCHMARK_ONCE { waitForItemChanged(true); } + while (lastRequestId < id) + waitForResponse1(id); QCOMPARE(listModel->rowCount(), 299); @@ -479,11 +433,12 @@ void JsonDbSortingListModelBench::deleteItem() void JsonDbSortingListModelBench::scrollThousandItems() { + resetWaitFlags(); QVariantMap item; for (int i=0; i < 1000; i++) { item.insert("_type", __FUNCTION__); item.insert("name", QString("Arnie_%1").arg(i)); - int id = mClient->create(item, "com.nokia.shared.1"); + int id = create(item, "com.nokia.shared.1"); waitForResponse1(id); } @@ -498,6 +453,7 @@ void JsonDbSortingListModelBench::scrollThousandItems() connectListModel(listModel); // now start it working + mWaitingForStateChanged = true; waitForStateOrTimeout(); QCOMPARE(listModel->rowCount(), 1000); @@ -515,15 +471,21 @@ void JsonDbSortingListModelBench::scrollThousandItems() void JsonDbSortingListModelBench::modelReset() { - mWaitingForReset = false; - mEventLoop2.exit(0); + if (mWaitingForReset) { + mWaitingForReset = false; + eventLoop1.exit(0); + } } void JsonDbSortingListModelBench::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { Q_UNUSED(topLeft); Q_UNUSED(bottomRight); - mWaitingForDataChange = false; + mItemsUpdated++; + if (mWaitingForChanged) { + mWaitingForChanged = false; + eventLoop1.exit(0); + } } void JsonDbSortingListModelBench::rowsInserted(const QModelIndex &parent, int first, int last) @@ -531,8 +493,11 @@ void JsonDbSortingListModelBench::rowsInserted(const QModelIndex &parent, int fi Q_UNUSED(parent); Q_UNUSED(first); Q_UNUSED(last); - mItemsCreated++; - mEventLoop2.exit(0); + mItemsCreated += last-first+1; + if (mWaitingForRowsInserted) { + mWaitingForRowsInserted = false; + eventLoop1.exit(0); + } } void JsonDbSortingListModelBench::rowsRemoved(const QModelIndex &parent, int first, int last) @@ -540,7 +505,11 @@ void JsonDbSortingListModelBench::rowsRemoved(const QModelIndex &parent, int fir Q_UNUSED(parent); Q_UNUSED(first); Q_UNUSED(last); - mWaitingForRowsRemoved = false; + mItemsRemoved += last-first+1; + if (mWaitingForRemoved) { + mWaitingForRemoved = false; + eventLoop1.exit(0); + } } void JsonDbSortingListModelBench::rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row ) @@ -556,83 +525,109 @@ void JsonDbSortingListModelBench::stateChanged() { // only exit on ready state. QAbstractListModel *model = qobject_cast<QAbstractListModel *>(sender()); - if (model->property("state") == 2) { + if (model->property("state").toInt() == 2 && mWaitingForStateChanged) { mWaitingForStateChanged = false; - mEventLoop2.exit(0); + eventLoop1.exit(0); } } void JsonDbSortingListModelBench::waitForItemsCreated(int items) { - mTimeoutCalled = false; + mTimedOut = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); + timer.start(clientTimeout); + elapsedTimer.start(); - mItemsCreated = 0; - while (mItemsCreated != items && !mTimeoutCalled) - mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout); + while (!mTimedOut && mItemsCreated != items) { + mWaitingForRowsInserted = true; + eventLoop1.exec(QEventLoop::AllEvents); + } + if (mTimedOut) + qDebug () << "waitForItemsCreated Timed out"; } void JsonDbSortingListModelBench::waitForExitOrTimeout() { - mTimeoutCalled = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); - mEventLoop2.exec(QEventLoop::AllEvents); + timer.start(clientTimeout); + elapsedTimer.start(); + eventLoop1.exec(QEventLoop::AllEvents); } void JsonDbSortingListModelBench::waitForStateOrTimeout() { - mTimeoutCalled = false; + mTimedOut = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); + timer.start(clientTimeout); + elapsedTimer.start(); - mWaitingForStateChanged = true; - while (mWaitingForStateChanged && !mTimeoutCalled) - mEventLoop2.processEvents(QEventLoop::AllEvents, mClientTimeout); + while (mWaitingForStateChanged && !mTimedOut) { + eventLoop1.exec(QEventLoop::AllEvents); + } + if (mTimedOut) + qDebug () << "waitForStateOrTimeout Timed out"; } void JsonDbSortingListModelBench::timeout() { - ClientWrapper::timeout(); - mTimeoutCalled = true; + qDebug () << "JsonDbSortingListModelBench::timeout()"; + RequestWrapper::timeout(); mTimedOut = true; + eventLoop1.quit(); +} + +void JsonDbSortingListModelBench::resetWaitFlags() +{ + mItemsCreated = 0; + mItemsUpdated = 0; + mItemsRemoved = 0; + mWaitingForStateChanged = false; + mWaitingForRowsInserted = false; + mWaitingForReset = false; + mWaitingForChanged = false; + mWaitingForRemoved = false; } void JsonDbSortingListModelBench::waitForItemChanged(bool waitForRemove) { - mTimeoutCalled = false; + mTimedOut = false; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop2, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); + timer.start(clientTimeout); + elapsedTimer.start(); - mWaitingForRowsRemoved = true; - mWaitingForDataChange = true; + mWaitingForRemoved = true; + mWaitingForChanged = true; mItemsCreated = 0; mWaitingForReset = true; + mWaitingForStateChanged = true; bool waitMore = true; - while (waitMore && !mTimeoutCalled) { - if (!mWaitingForDataChange) + while (waitMore && !mTimedOut) { + if (!mWaitingForChanged) { + //qDebug() << "waitForItemChanged: mWaitingForChanged"; break; - if (mItemsCreated) + } + if (!mWaitingForStateChanged) { + //qDebug() << "waitForItemChanged: mWaitingForStateChanged"; break; - if (!mWaitingForReset) + } + if (mItemsCreated){ + //qDebug() << "waitForItemChanged: mItemsCreated"; break; - if (waitForRemove && !mWaitingForRowsRemoved) + } + if (!mWaitingForReset){ + //qDebug() << "waitForItemChanged: mWaitingForReset"; break; - mEventLoop2.processEvents(QEventLoop::AllEvents); + } + if (waitForRemove && !mWaitingForRemoved){ + //qDebug() << "waitForItemChanged: mWaitingForRemoved"; + break; + } + eventLoop1.exec(QEventLoop::AllEvents); } } QTEST_MAIN(JsonDbSortingListModelBench) diff --git a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.h b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.h index 68ae04f..e28a645 100644 --- a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.h +++ b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel-bench.h @@ -41,22 +41,9 @@ #ifndef JsonDbSortingListModel_Bench_H #define JsonDbSortingListModel_Bench_H -#include <QCoreApplication> -#include <QList> -#include <QTest> -#include <QFile> -#include <QProcess> -#include <QEventLoop> -#include <QDebug> -#include <QLocalSocket> -#include <QTimer> - -#include <jsondb-client.h> -#include <jsondb-error.h> - #include <QAbstractListModel> -#include "clientwrapper.h" -#include "../../shared/qmltestutil.h" +#include "requestwrapper.h" +#include "qmltestutil.h" QT_BEGIN_NAMESPACE class QQmlEngine; @@ -65,22 +52,16 @@ QT_END_NAMESPACE QT_USE_NAMESPACE_JSONDB -class JsonDbListModel; - class ModelData { public: ModelData(); ~ModelData(); QQmlEngine *engine; QQmlComponent *component; - QQmlComponent *partitionComponent1; - QQmlComponent *partitionComponent2; QObject *model; - QObject *partition1; - QObject *partition2; }; -class JsonDbSortingListModelBench: public ClientWrapper +class JsonDbSortingListModelBench: public RequestWrapper { Q_OBJECT public: @@ -98,9 +79,6 @@ public slots: void modelReset(); void stateChanged(); - void callbackSlot(QVariant error, QVariant response); - - protected slots: void timeout(); @@ -110,7 +88,7 @@ private slots: void ModelStartup(); void ModelStartupTwoPartitions(); void ModelStartupSorted(); - void getItemNotInCache(); + void getItems(); void deleteItem(); void scrollThousandItems(); @@ -125,29 +103,23 @@ private: QAbstractListModel *createModel(); void deleteModel(QAbstractListModel *model); void deleteItems(const QString &type, const QString &partition); - QVariant readJsonFile(const QString &filename); + void resetWaitFlags(); private: QProcess *mProcess; - QStringList mNotificationsReceived; QList<ModelData*> mModels; QString mPluginPath; - QEventLoop mEventLoop2; // for all listmodel slots // Response values + bool mTimedOut; int mItemsCreated; - bool mWaitingForNotification; - bool mWaitingForDataChange; - bool mWaitingForRowsRemoved; - bool mTimeoutCalled; - bool mWaitingForReset; + int mItemsUpdated; + int mItemsRemoved; bool mWaitingForStateChanged; - - bool mTimedOut; - bool callbackError; - bool mCallbackReceived; - QVariant callbackMeta; - QVariant callbackResponse; + bool mWaitingForRowsInserted; + bool mWaitingForReset; + bool mWaitingForChanged; + bool mWaitingForRemoved; }; diff --git a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel.pro b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel.pro index f1fe37e..60b0320 100644 --- a/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel.pro +++ b/tests/benchmarks/jsondbsortinglistmodel/jsondbsortinglistmodel.pro @@ -3,15 +3,15 @@ TARGET = tst_bench_jsondbsortinglistmodel DEPENDPATH += . INCLUDEPATH += . -QT = core network testlib gui qml jsondbcompat-private +QT = core network testlib gui qml jsondb CONFIG -= app_bundle CONFIG += testcase include($$PWD/../../shared/shared.pri) -include($$PWD/../../../src/3rdparty/qjson/qjson.pri) DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\" DEFINES += SRCDIR=\\\"$$PWD/\\\" -HEADERS += jsondbsortinglistmodel-bench.h +HEADERS += jsondbsortinglistmodel-bench.h \ + $$PWD/../../shared/requestwrapper.h SOURCES += jsondbsortinglistmodel-bench.cpp diff --git a/tests/benchmarks/jsondbsortinglistmodel/partitions.json b/tests/benchmarks/jsondbsortinglistmodel/partitions.json new file mode 100644 index 0000000..1cdd0fa --- /dev/null +++ b/tests/benchmarks/jsondbsortinglistmodel/partitions.json @@ -0,0 +1,4 @@ +[ + { "name" :"com.nokia.shared.1" }, + { "name" :"com.nokia.shared.2" } +] diff --git a/tests/benchmarks/daemon/bench_daemon.cpp b/tests/benchmarks/partition/bench_partition.cpp index f880af8..cae5fc0 100644 --- a/tests/benchmarks/daemon/bench_daemon.cpp +++ b/tests/benchmarks/partition/bench_partition.cpp @@ -47,36 +47,34 @@ #include <QDir> #include <QTime> -#include "json.h" - #include "jsondbpartition.h" #include "jsondbindex.h" #include "jsondbindexquery.h" #include "jsondbsettings.h" -#include "jsondb-strings.h" -#include "jsondb-error.h" +#include "jsondbstrings.h" +#include "jsondberrors.h" #include <qjsonobject.h> #include "../../shared/util.h" -QT_USE_NAMESPACE_JSONDB +QT_USE_NAMESPACE_JSONDB_PARTITION Q_DECLARE_METATYPE(QJsonArray) Q_DECLARE_METATYPE(QJsonObject) -class TestJsonDb: public QObject +class TestPartition: public QObject { Q_OBJECT public: - TestJsonDb(); + TestPartition(); private slots: void init(); void initTestCase(); void cleanupTestCase(); void cleanup(); - void contactListChaff();//moved from auto/daemon + void contactListChaff(); void compact(); void jsonArrayCreate(); void jsonObjectCreate(); @@ -119,17 +117,13 @@ private slots: void benchmarkFindUnindexed(); void benchmarkFindReindexed(); void benchmarkFindNames(); - void findNamesMapL(); - void benchmarkFindNamesMapL(); - void findNamesMapO(); - void benchmarkFindNamesMapO(); + void findNamesMapObject(); + void benchmarkFindNamesMapObject(); void benchmarkCursorCount(); void benchmarkQueryCount(); void benchmarkScriptEngineCreation(); private: - QJsonValue readJsonFile(const QString &filename); - QJsonValue readJson(const QByteArray &json); void removeDbFiles(); void addSchema(const QString &schemaName); void addIndex(const QString &propertyName, const QString &propertyType=QString(), const QString &objectType=QString()); @@ -156,13 +150,13 @@ private: const char *kFilename = "testdatabase"; -TestJsonDb::TestJsonDb() : +TestPartition::TestPartition() : mJsonDbPartition(0) , mOwner(0) { } -void TestJsonDb::removeDbFiles() +void TestPartition::removeDbFiles() { QStringList filters; filters << QString::fromLatin1(kFilename)+QLatin1Char('*'); @@ -172,11 +166,11 @@ void TestJsonDb::removeDbFiles() QFile::remove(fileName); } -void TestJsonDb::initTestCase() +void TestPartition::initTestCase() { QCoreApplication::setOrganizationName("Example"); QCoreApplication::setOrganizationDomain("example.com"); - QCoreApplication::setApplicationName("TestJsonDb"); + QCoreApplication::setApplicationName("TestPartition"); QCoreApplication::setApplicationVersion("1.0"); removeDbFiles(); @@ -185,7 +179,7 @@ void TestJsonDb::initTestCase() mJsonDbPartition = new JsonDbPartition(kFilename, QStringLiteral("com.example.JsonDbTest"), mOwner, this); mJsonDbPartition->open(); - QFile contactsFile(":/daemon/json/largeContactsTest.json"); + QFile contactsFile(":/partition/json/largeContactsTest.json"); QVERIFY(contactsFile.exists()); contactsFile.open(QIODevice::ReadOnly); QByteArray json = contactsFile.readAll(); @@ -234,28 +228,32 @@ void TestJsonDb::initTestCase() qDebug() << "done. Time per item (ms):" << (double)elapsed / count << "count" << count << "elapsed" << elapsed << "ms"; } -void TestJsonDb::init() +void TestPartition::init() { } -void TestJsonDb::cleanupTestCase() +void TestPartition::cleanupTestCase() { if (mJsonDbPartition) { mJsonDbPartition->close(); delete mJsonDbPartition; mJsonDbPartition = 0; } + if (mOwner) { + delete mOwner; + mOwner = 0; + } removeDbFiles(); } -void TestJsonDb::cleanup() +void TestPartition::cleanup() { QCOMPARE(mJsonDbPartition->mTransactionDepth, 0); } -void TestJsonDb::addSchema(const QString &schemaName) +void TestPartition::addSchema(const QString &schemaName) { - QJsonValue schema = readJsonFile(QString(":/daemon/schemas/%1.json").arg(schemaName)).toArray(); + QJsonValue schema = readJsonFile(QString(":/partition/schemas/%1.json").arg(schemaName)).toArray(); JsonDbObject schemaDocument; schemaDocument.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr); schemaDocument.insert("name", schemaName); @@ -265,7 +263,7 @@ void TestJsonDb::addSchema(const QString &schemaName) verifyGoodResult(result); } -void TestJsonDb::addIndex(const QString &propertyName, const QString &propertyType, const QString &objectType) +void TestPartition::addIndex(const QString &propertyName, const QString &propertyType, const QString &objectType) { QJsonObject index; index.insert(JsonDbString::kTypeStr, JsonDbString::kIndexTypeStr); @@ -278,26 +276,26 @@ void TestJsonDb::addIndex(const QString &propertyName, const QString &propertyTy QVERIFY(result.code == JsonDbError::NoError); } -void TestJsonDb::compact() +void TestPartition::compact() { mJsonDbPartition->compact(); } -void TestJsonDb::jsonArrayCreate() +void TestPartition::jsonArrayCreate() { QBENCHMARK { QJsonArray list; } } -void TestJsonDb::jsonObjectCreate() +void TestPartition::jsonObjectCreate() { QBENCHMARK { QJsonObject map; } } -void TestJsonDb::jsonArrayReadValue_data() +void TestPartition::jsonArrayReadValue_data() { QTest::addColumn<QJsonArray>("list"); QTest::addColumn<int>("index"); @@ -315,7 +313,7 @@ void TestJsonDb::jsonArrayReadValue_data() QTest::newRow("large list") << data3 << 12 << 12; } -void TestJsonDb::jsonArrayReadValue() +void TestPartition::jsonArrayReadValue() { QFETCH(QJsonArray, list); QFETCH(int, index); @@ -326,7 +324,7 @@ void TestJsonDb::jsonArrayReadValue() } } -void TestJsonDb::jsonObjectReadValue_data() +void TestPartition::jsonObjectReadValue_data() { QTest::addColumn<QJsonObject>("map"); QTest::addColumn<QString>("property"); @@ -344,7 +342,7 @@ void TestJsonDb::jsonObjectReadValue_data() QTest::newRow("large map") << data2 << QString::number(12) << 12; } -void TestJsonDb::jsonObjectReadValue() +void TestPartition::jsonObjectReadValue() { QFETCH(QJsonObject, map); QFETCH(QString, property); @@ -355,7 +353,7 @@ void TestJsonDb::jsonObjectReadValue() } } -void TestJsonDb::jsonArrayInsertValue() +void TestPartition::jsonArrayInsertValue() { QBENCHMARK { QJsonArray list; @@ -364,7 +362,7 @@ void TestJsonDb::jsonArrayInsertValue() } } -void TestJsonDb::jsonObjectInsertValue() +void TestPartition::jsonObjectInsertValue() { const int iterations = 1024; QVarLengthArray<QString, iterations> names; @@ -379,18 +377,18 @@ void TestJsonDb::jsonObjectInsertValue() } } -void TestJsonDb::benchmarkCreate() +void TestPartition::benchmarkCreate() { - QJsonArray contacts(readJsonFile(":/daemon/json/largeContactsTest.json").toArray()); + QJsonArray contacts(readJsonFile(":/partition/json/largeContactsTest.json").toArray()); QBENCHMARK { JsonDbObject contact(contacts.at(0).toObject()); mJsonDbPartition->updateObject(mOwner, contact); } } -void TestJsonDb::benchmarkFileAppend() +void TestPartition::benchmarkFileAppend() { - QJsonArray contacts(readJsonFile(":/daemon/json/largeContactsTest.json").toArray()); + QJsonArray contacts(readJsonFile(":/partition/json/largeContactsTest.json").toArray()); QFile objectFile("objectFile.bin"); objectFile.open(QIODevice::ReadWrite); @@ -401,9 +399,9 @@ void TestJsonDb::benchmarkFileAppend() } } -void TestJsonDb::benchmarkFileAppend2() +void TestPartition::benchmarkFileAppend2() { - QJsonValue bson(readJsonFile(":/daemon/json/largeContactsTest.json")); + QJsonValue bson(readJsonFile(":/partition/json/largeContactsTest.json")); QJsonArray contacts(bson.toArray()); QFile objectFile("objectFile.bin"); objectFile.open(QIODevice::ReadWrite); @@ -420,7 +418,7 @@ void TestJsonDb::benchmarkFileAppend2() } } -void TestJsonDb::benchmarkParseQuery_data() +void TestPartition::benchmarkParseQuery_data() { QTest::addColumn<QString>("query"); QTest::newRow("1") << "[?foo exists]"; @@ -432,32 +430,25 @@ void TestJsonDb::benchmarkParseQuery_data() QTest::newRow("7") << "[?foo=%bar]"; QTest::newRow("8") << "[?foo=\"bar\" | foo=\"baz\"]"; QTest::newRow("9") << "[?foo=\"bar\"][/foo]"; - QTest::newRow("10") << "[?foo=\"bar\"][= a ]"; QTest::newRow("11") << "[?foo =~ \"/a\\//\"]"; - QTest::newRow("12") << "[?foo=\"bar\"][= a,b,c]"; - QTest::newRow("13") << "[?foo=\"bar\"][= a->foreign,b,c]"; - QTest::newRow("14") << "[?foo=\"bar\"][=[ a,b,c]]"; QTest::newRow("15") << "[?foo=\"bar\"][={ a:x, b:y, c:z}]"; QTest::newRow("16") << "[?foo=\"bar\"][={ a:x->foreign, b:y, c:z}]"; - QTest::newRow("17") << "[?foo=\"bar\"][= _uuid, name.first, name.last ]"; QTest::newRow("18") << "[?_type=\"contact\"][= { uuid: _uuid, first: name.first, last: name.last } ]"; QTest::newRow("19") << "[?telephoneNumbers.*.number=\"6175551212\"]"; - QTest::newRow("20") << "[?_type=\"contact\"][= .telephoneNumbers[*].number]"; QTest::newRow("21") << "[?_type=\"contact\"][?foo startsWith \"bar\"]"; } -void TestJsonDb::benchmarkParseQuery() +void TestPartition::benchmarkParseQuery() { QFETCH(QString, query); QJsonObject bindings; bindings.insert("bar", QString("barValue")); QBENCHMARK { - JsonDbQuery *jq = JsonDbQuery::parse(query, bindings); - delete jq; + QScopedPointer<JsonDbQuery> jq(JsonDbQuery::parse(query, bindings)); } } -void TestJsonDb::benchmarkFieldMatch() +void TestPartition::benchmarkFieldMatch() { int count = mContactList.size(); if (!count) @@ -475,7 +466,7 @@ void TestJsonDb::benchmarkFieldMatch() } } -void TestJsonDb::benchmarkTokenizer() +void TestPartition::benchmarkTokenizer() { QStringList queries = (QStringList() << "[?abc=\"def\"]" @@ -484,10 +475,6 @@ void TestJsonDb::benchmarkTokenizer() << "[?abc->def=\"ghi\"]" << "[?abc.def=\"ghi\"][/abc.def]" << "[?abc.def=\"ghi\"][\\foo]" - << "[?abc.def=\"ghi\"][=foo]" - << "[?abc.def=\"ghi\"][=foo,bar]" - << "[?abc.def=\"ghi\"][=.foo,.bar]" - << "[?abc.def=\"ghi\"][=[.foo,.bar]]" << "[?abc.def=\"ghi\"][={foo:Foo,bar:Bar}][/foo]" ); foreach (QString query, queries) { @@ -508,7 +495,7 @@ QByteArray makeForwardKey(const QJsonValue &fieldValue, const ObjectKey &objectK int forwardKeyCmp(const QByteArray &, const QByteArray &); } } // end namespace QtAddOn::JsonDb -void TestJsonDb::benchmarkForwardKeyCmp() +void TestPartition::benchmarkForwardKeyCmp() { int count = mContactList.size(); @@ -538,7 +525,7 @@ void TestJsonDb::benchmarkForwardKeyCmp() } } -void TestJsonDb::benchmarkParsedQuery() +void TestPartition::benchmarkParsedQuery() { int count = mContactList.size(); if (!count) @@ -573,7 +560,7 @@ void TestJsonDb::benchmarkParsedQuery() } } -void TestJsonDb::benchmarkSchemaValidation_data() +void TestPartition::benchmarkSchemaValidation_data() { QTest::addColumn<QByteArray>("item"); QTest::addColumn<bool>("isPerson"); @@ -593,7 +580,7 @@ void TestJsonDb::benchmarkSchemaValidation_data() << QByteArray("{ \"name\":\"Alice's great-grandmother\", \"age\": 130}") << false << false; } -void TestJsonDb::benchmarkSchemaValidation() +void TestPartition::benchmarkSchemaValidation() { bool validate = jsondbSettings->validateSchemas(); jsondbSettings->setValidateSchemas(true); @@ -615,7 +602,7 @@ void TestJsonDb::benchmarkSchemaValidation() static int schemaId = 0; const QString personSchemaName = QString::fromLatin1("personBenchmark") + QString::number(++schemaId); - QJsonObject personSchemaBody = readJson(person).toObject(); + QJsonObject personSchemaBody = QJsonDocument::fromJson(person).object(); JsonDbObject personSchemaObject; personSchemaObject.insert(JsonDbString::kTypeStr, JsonDbString::kSchemaTypeStr); personSchemaObject.insert("name", personSchemaName); @@ -628,7 +615,7 @@ void TestJsonDb::benchmarkSchemaValidation() QList<QJsonObject> objects; objects.reserve(numberOfIterations); for (uint i = 0; i < numberOfIterations; ++i) { - QJsonObject object = readJson(item).toObject(); + QJsonObject object = QJsonDocument::fromJson(item).object(); object.insert("testingForAdult", (int)i); object.insert(JsonDbString::kTypeStr, personSchemaName); objects.append(object); @@ -650,7 +637,7 @@ void TestJsonDb::benchmarkSchemaValidation() jsondbSettings->setValidateSchemas(validate); } -void TestJsonDb::benchmarkFind() +void TestPartition::benchmarkFind() { int count = mContactList.size(); if (!count) @@ -663,12 +650,13 @@ void TestJsonDb::benchmarkFind() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(item.value("name").toString()); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindByName() +void TestPartition::benchmarkFindByName() { int count = mContactList.size(); if (!count) @@ -679,12 +667,13 @@ void TestJsonDb::benchmarkFindByName() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(mFirstNames[mFirstNames.size()-1]); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindByUuid() +void TestPartition::benchmarkFindByUuid() { int count = mContactList.size(); if (!count) @@ -695,12 +684,13 @@ void TestJsonDb::benchmarkFindByUuid() QString query = QString("[?%1=\"%2\"]") .arg(JsonDbString::kUuidStr) .arg(uuid); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query)); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data()); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindEQ() +void TestPartition::benchmarkFindEQ() { int count = mContactList.size(); if (!count) @@ -713,12 +703,13 @@ void TestJsonDb::benchmarkFindEQ() .arg("contact") .arg(item.propertyLookup("name.first").toString()); QBENCHMARK { - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query)); - verifyGoodQueryResult(queryResult); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data()); + verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindLE() +void TestPartition::benchmarkFindLE() { int count = mContactList.size(); if (!count) @@ -731,12 +722,13 @@ void TestJsonDb::benchmarkFindLE() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(item.propertyLookup("name.first").toString()); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFirst() +void TestPartition::benchmarkFirst() { int count = mContactList.size(); if (!count) @@ -746,12 +738,13 @@ void TestJsonDb::benchmarkFirst() QString query = QString("[?%1=\"%2\"][?name.last exists][/name.first]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkLast() +void TestPartition::benchmarkLast() { int count = mContactList.size(); if (!count) @@ -761,12 +754,13 @@ void TestJsonDb::benchmarkLast() QString query = QString("[?%1=\"%2\"][?name.last exists][\\name.first]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFirst10() +void TestPartition::benchmarkFirst10() { int count = mContactList.size(); if (!count) @@ -776,12 +770,13 @@ void TestJsonDb::benchmarkFirst10() QString query = QString("[?%1=\"%2\"][?name.last exists][/name.first]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 10); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 10); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFind10() +void TestPartition::benchmarkFind10() { int count = mContactList.size(); if (!count) @@ -794,11 +789,12 @@ void TestJsonDb::benchmarkFind10() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(mFirstNames[itemNumber]); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 10); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 10); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFind20() +void TestPartition::benchmarkFind20() { int count = mContactList.size(); if (!count) @@ -812,12 +808,13 @@ void TestJsonDb::benchmarkFind20() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(item.propertyLookup("name.first").toString()); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 20); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 20); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFirstByUuid() +void TestPartition::benchmarkFirstByUuid() { int count = mContactList.size(); if (!count) @@ -827,12 +824,13 @@ void TestJsonDb::benchmarkFirstByUuid() QString query = QString("[?%1=\"%2\"][?name.last exists][/_uuid]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkLastByUuid() +void TestPartition::benchmarkLastByUuid() { int count = mContactList.size(); if (!count) @@ -842,12 +840,13 @@ void TestJsonDb::benchmarkLastByUuid() QString query = QString("[?%1=\"%2\"][?name.last exists][/_uuid]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFirst10ByUuid() +void TestPartition::benchmarkFirst10ByUuid() { int count = mContactList.size(); if (!count) @@ -857,12 +856,13 @@ void TestJsonDb::benchmarkFirst10ByUuid() QString query = QString("[?%1=\"%2\"][?name.last exists][/_uuid]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 10); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 10); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFind10ByUuid() +void TestPartition::benchmarkFind10ByUuid() { int count = mContactList.size(); if (!count) @@ -874,12 +874,13 @@ void TestJsonDb::benchmarkFind10ByUuid() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(mUuids[itemNumber]); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 10); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 10); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindUnindexed() +void TestPartition::benchmarkFindUnindexed() { int count = mContactList.size(); if (!count) @@ -892,12 +893,13 @@ void TestJsonDb::benchmarkFindUnindexed() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(item.value("firstName").toString()); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query)); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data()); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindReindexed() +void TestPartition::benchmarkFindReindexed() { int count = mContactList.size(); if (!count) @@ -914,72 +916,51 @@ void TestJsonDb::benchmarkFindReindexed() .arg(JsonDbString::kTypeStr) .arg("contact") .arg(item.value("lastName").toString()); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query)); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data()); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::benchmarkFindNames() +void TestPartition::benchmarkFindNames() { QBENCHMARK { QString query = QString("[?%1=\"%2\"]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); } } -void TestJsonDb::findNamesMapL() -{ - QBENCHMARK_ONCE { - QString query = QString("[?%1=\"%2\"][= [_uuid, name.first, name.last] ]") - .arg(JsonDbString::kTypeStr) - .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query)); - verifyGoodQueryResult(queryResult); - QCOMPARE(queryResult.values.size(), mContactList.size()); - } -} - -void TestJsonDb::benchmarkFindNamesMapL() -{ - QBENCHMARK { - QString query = QString("[?%1=\"%2\"][= [_uuid, name.first, name.last] ]") - .arg(JsonDbString::kTypeStr) - .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); - verifyGoodQueryResult(queryResult); - QCOMPARE(queryResult.values.size(), 1); - } -} - - -void TestJsonDb::findNamesMapO() +void TestPartition::findNamesMapObject() { QBENCHMARK_ONCE { QString query = QString("[?%1=\"%2\"][= { uuid: _uuid, first: name.first, last: name.last } ]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query)); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data()); verifyGoodQueryResult(queryResult); QCOMPARE(queryResult.data.size(), mContactList.size()); } } -void TestJsonDb::benchmarkFindNamesMapO() +void TestPartition::benchmarkFindNamesMapObject() { QBENCHMARK { QString query = QString("[?%1=\"%2\"][= { uuid: _uuid, first: name.first, last: name.last } ]") .arg(JsonDbString::kTypeStr) .arg("contact"); - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, JsonDbQuery::parse(query), 1); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(query)); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data(), 1); verifyGoodQueryResult(queryResult); QCOMPARE(queryResult.data.size(), 1); } } -void TestJsonDb::benchmarkCursorCount() +void TestPartition::benchmarkCursorCount() { QStringList queries = (QStringList() << "[/name.first]" @@ -1003,7 +984,7 @@ void TestJsonDb::benchmarkCursorCount() } } -void TestJsonDb::benchmarkQueryCount() +void TestPartition::benchmarkQueryCount() { QStringList queries = (QStringList() << "[/name.first]" @@ -1011,39 +992,13 @@ void TestJsonDb::benchmarkQueryCount() ); foreach (QString query, queries) { QBENCHMARK { - JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, - JsonDbQuery::parse(QString("%1[count]").arg(query))); + QScopedPointer<JsonDbQuery> parsedQuery(JsonDbQuery::parse(QString("%1[count]").arg(query))); + JsonDbQueryResult queryResult = mJsonDbPartition->queryObjects(mOwner, parsedQuery.data()); } } } -QJsonValue TestJsonDb::readJsonFile(const QString& filename) -{ - QString filepath = filename; - QFile jsonFile(filepath); - jsonFile.open(QIODevice::ReadOnly); - QByteArray json = jsonFile.readAll(); - JsonReader parser; - bool ok = parser.parse(json); - if (!ok) { - qDebug() << filepath << parser.errorString(); - } - QVariant v = parser.result(); - return QJsonObject::fromVariantMap(v.toMap()); -} - -QJsonValue TestJsonDb::readJson(const QByteArray& json) -{ - JsonReader parser; - bool ok = parser.parse(json); - if (!ok) { - qDebug() << parser.errorString(); - } - QVariant v = parser.result(); - return QJsonObject::fromVariantMap(v.toMap()); -} - -void TestJsonDb::benchmarkScriptEngineCreation() +void TestPartition::benchmarkScriptEngineCreation() { QJSValue result; QBENCHMARK { @@ -1052,11 +1007,12 @@ void TestJsonDb::benchmarkScriptEngineCreation() QJSValue globalObject = engine->globalObject(); result = engine->evaluate(QString("var reduce = function(k, v, s) { s.count = s.count + v.count; return s; };")); + delete engine; engine = 0; } } -void TestJsonDb::contactListChaff() +void TestPartition::contactListChaff() { QBENCHMARK { for (int ii = 0; ii < mContactList.size(); ii++) { @@ -1075,5 +1031,5 @@ void TestJsonDb::contactListChaff() } } -QTEST_MAIN(TestJsonDb) -#include "bench_daemon.moc" +QTEST_MAIN(TestPartition) +#include "bench_partition.moc" diff --git a/tests/benchmarks/partition/partition.pro b/tests/benchmarks/partition/partition.pro new file mode 100644 index 0000000..d09d215 --- /dev/null +++ b/tests/benchmarks/partition/partition.pro @@ -0,0 +1,18 @@ +TARGET = tst_bench_partition + +QT = network qml testlib jsondbpartition +CONFIG -= app_bundle +CONFIG += testcase + +LIBS += -L$$QT.jsondb.libs + +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +RESOURCES+=../../json.qrc partition.qrc + +# HACK, remove when jsondbpartition separates private api from public api +include(../../../src/3rdparty/btree/btree.pri) +include(../../../src/hbtree/hbtree.pri) + +SOURCES += \ + bench_partition.cpp \ diff --git a/tests/benchmarks/partition/partition.qrc b/tests/benchmarks/partition/partition.qrc new file mode 100644 index 0000000..f490be7 --- /dev/null +++ b/tests/benchmarks/partition/partition.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/partition"> + <file alias="json">../../auto/partition/json</file> + <file alias="schemas">../../auto/partition/schemas</file> + </qresource> +</RCC> diff --git a/tests/benchmarks/tests.xml b/tests/benchmarks/tests.xml index 3f5efac..0d4cd1b 100644 --- a/tests/benchmarks/tests.xml +++ b/tests/benchmarks/tests.xml @@ -6,13 +6,9 @@ <description>Client API performance 01</description> <step>cd /usr/lib/qt5jsondb-tests/benchmarks/client; date && ./tst_bench_client && date</step> </case> - <case name="tst_bench_daemon" timeout="5000" component="qt5jsondb"> + <case name="tst_bench_partition" timeout="5000" component="qt5jsondb"> <description>Server-side performance</description> - <step>cd /usr/lib/qt5jsondb-tests/benchmarks/daemon; date && ./tst_bench_daemon && date</step> - </case> - <case name="tst_bench_listmodel" timeout="5000" component="qt5jsondb"> - <description>JsonDbListModel performance</description> - <step>cd /usr/lib/qt5jsondb-tests/benchmarks/jsondb-listmodel; date && ./tst_bench_listmodel -platform minimal && date</step> + <step>cd /usr/lib/qt5jsondb-tests/benchmarks/partition; date && ./tst_bench_partition && date</step> </case> <case name="tst_bench_jsondbcachinglistmodel" timeout="5000" component="qt5jsondb"> <description>JsonDbCachingListModel performance</description> |