From 43ae43bc74800473aadf9c5c807603cdf8516d36 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 7 Sep 2015 16:28:25 +0200 Subject: GenericFacadeBenchmark genericfacadebenchmark --- tests/CMakeLists.txt | 1 + tests/genericfacadebenchmark.cpp | 111 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/genericfacadebenchmark.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1c75e96..251e780 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,6 +31,7 @@ manual_tests ( storagebenchmark dummyresourcebenchmark genericresourcebenchmark + genericfacadebenchmark ) auto_tests ( diff --git a/tests/genericfacadebenchmark.cpp b/tests/genericfacadebenchmark.cpp new file mode 100644 index 0000000..483a597 --- /dev/null +++ b/tests/genericfacadebenchmark.cpp @@ -0,0 +1,111 @@ +#include + +#include + +#include +#include +#include +#include + +#include "event_generated.h" + +class TestEventAdaptorFactory : public DomainTypeAdaptorFactory +{ +public: + TestEventAdaptorFactory() + : DomainTypeAdaptorFactory() + { + } + + virtual ~TestEventAdaptorFactory() {}; +}; + +class TestResourceAccess : public Akonadi2::ResourceAccessInterface +{ + Q_OBJECT +public: + virtual ~TestResourceAccess() {}; + KAsync::Job sendCommand(int commandId) Q_DECL_OVERRIDE { return KAsync::null(); } + KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE { return KAsync::null(); } + KAsync::Job synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE { return KAsync::null(); } + +public Q_SLOTS: + void open() Q_DECL_OVERRIDE {} + void close() Q_DECL_OVERRIDE {} +}; + +class TestResourceFacade : public Akonadi2::GenericFacade +{ +public: + TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer > storage, const QSharedPointer resourceAccess) + : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), storage, resourceAccess) + { + + } + virtual ~TestResourceFacade() + { + + } +}; + +class GenericFacadeBenchmark : public QObject +{ + Q_OBJECT +private Q_SLOTS: + + void initTestCase() + { + Akonadi2::Storage store(Akonadi2::storageLocation(), "identifier", Akonadi2::Storage::ReadWrite); + store.removeFromDisk(); + } + + void testLoad() + { + const QByteArray identifier = "identifier"; + const int count = 100000; + + //Setup + auto domainTypeAdaptorFactory = QSharedPointer::create(); + { + Akonadi2::Storage storage(Akonadi2::storageLocation(), identifier, Akonadi2::Storage::ReadWrite); + auto transaction = storage.createTransaction(Akonadi2::Storage::ReadWrite); + auto db = transaction.openDatabase(); + for (int i = 0; i < count; i++) { + auto domainObject = Akonadi2::ApplicationDomain::Event::Ptr::create(); + domainObject->setProperty("uid", "uid"); + domainObject->setProperty("summary", "summary"); + + flatbuffers::FlatBufferBuilder fbb; + domainTypeAdaptorFactory->createBuffer(*domainObject, fbb); + db.write(QString::number(i).toLatin1(), QByteArray::fromRawData(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize())); + } + } + + Akonadi2::Query query; + query.liveQuery = false; + + //Benchmark + QBENCHMARK { + auto resultSet = QSharedPointer >::create(); + auto resourceAccess = QSharedPointer::create(); + auto storage = QSharedPointer >::create("identifier", domainTypeAdaptorFactory); + TestResourceFacade facade(identifier, storage, resourceAccess); + + async::SyncListResult result(resultSet->emitter()); + + facade.load(query, resultSet).exec().waitForFinished(); + resultSet->initialResultSetComplete(); + + //We have to wait for the events that deliver the results to be processed by the eventloop + result.exec(); + + QCOMPARE(result.size(), count); + } + + // Print memory layout, RSS is what is in memory + // std::system("exec pmap -x \"$PPID\""); + } +}; + +QTEST_MAIN(GenericFacadeBenchmark) +#include "genericfacadebenchmark.moc" -- cgit v1.2.3