From kde-commits Fri Dec 09 15:45:48 2016 From: Christian Mollekopf Date: Fri, 09 Dec 2016 15:45:48 +0000 To: kde-commits Subject: [sink/develop] /: Interresourcemovetest/fixed interresourcemove Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=148129962213917 Git commit f425c2070131161dc11bcf70e35f8d1848cadb65 by Christian Mollekopf. Committed on 06/12/2016 at 18:40. Pushed by cmollekopf into branch 'develop'. Interresourcemovetest/fixed interresourcemove We cant take the identifier from the entity where we just cleared the identifier. M +5 -5 common/pipeline.cpp A +151 -0 tests/interresourcemovetest.cpp [License: LGPL] https://commits.kde.org/sink/f425c2070131161dc11bcf70e35f8d1848cadb65 diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 4ea43eb..7ee4b91 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -277,22 +277,22 @@ KAsync::Job Pipeline::modifiedEntity(void con= st *command, size_t size) = SinkTrace() << "Moving entity to new resource " << newEntity.ident= ifier() << newEntity.resourceInstanceIdentifier() << targetResource; auto job =3D TypeHelper{bufferType}.operator(), ApplicationDomain::ApplicationDomainType&>(newEntity); - job =3D job.syncThen([this, newEntity, isMove, targetResourc= e, bufferType](const KAsync::Error &error) { + job =3D job.syncThen([this, current, isMove, targetResource,= bufferType](const KAsync::Error &error) { if (!error) { - SinkTrace() << "Move of " << newEntity.identifier() << "wa= s successfull"; + SinkTrace() << "Move of " << current.identifier() << "was = successfull"; if (isMove) { startTransaction(); flatbuffers::FlatBufferBuilder fbb; - auto entityId =3D fbb.CreateString(newEntity.identifie= r()); + auto entityId =3D fbb.CreateString(current.identifier(= )); auto type =3D fbb.CreateString(bufferType); - auto location =3D Sink::Commands::CreateDeleteEntity(f= bb, newEntity.revision(), entityId, type, true); + auto location =3D Sink::Commands::CreateDeleteEntity(f= bb, current.revision(), entityId, type, true); Sink::Commands::FinishDeleteEntityBuffer(fbb, location= ); const auto data =3D BufferUtils::extractBuffer(fbb); deletedEntity(data, data.size()).exec(); commit(); } } else { - SinkError() << "Failed to move entity " << targetResource = << " to resource " << newEntity.identifier(); + SinkError() << "Failed to move entity " << targetResource = << " to resource " << current.identifier(); } }); job.exec(); diff --git a/tests/interresourcemovetest.cpp b/tests/interresourcemovetest.= cpp new file mode 100644 index 0000000..7561c5b --- /dev/null +++ b/tests/interresourcemovetest.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2016 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ +#include + +#include + +#include "dummyresource/resourcefactory.h" +#include "store.h" +#include "resourceconfig.h" +#include "resourcecontrol.h" +#include "log.h" +#include "test.h" +#include "testutils.h" + +using namespace Sink; +using namespace Sink::ApplicationDomain; + +/** + * Test of complete system using the dummy resource. + * + * This test requires the dummy resource installed. + */ +class InterResourceMoveTest : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() + { + Sink::Test::initTest(); + auto factory =3D Sink::ResourceFactory::load("sink.dummy"); + QVERIFY(factory); + ::DummyResource::removeFromDisk("instance1"); + ::DummyResource::removeFromDisk("instance2"); + ResourceConfig::addResource("instance1", "sink.dummy"); + ResourceConfig::addResource("instance2", "sink.dummy"); + } + + void init() + { + } + + void cleanup() + { + VERIFYEXEC(Sink::Store::removeDataFromDisk(QByteArray("instance1")= )); + VERIFYEXEC(Sink::Store::removeDataFromDisk(QByteArray("instance2")= )); + } + + void testMove() + { + Event event("instance1"); + event.setProperty("uid", "testuid"); + QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testu= id")); + event.setProperty("summary", "summaryValue"); + VERIFYEXEC(Sink::Store::create(event)); + + + Event createdEvent; + // Ensure all local data is processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance1")); + { + auto query =3D Query().resourceFilter("instance1") ; + auto list =3D Sink::Store::read(query.filter("testuid")); + QCOMPARE(list.size(), 1); + createdEvent =3D list.first(); + } + + VERIFYEXEC(Sink::Store::move(createdEvent, "instance2")); + + //FIXME we can't guarantee that that the create command arrives at= instance2 before the flush command, so we'll just wait for a little bit. + QTest::qWait(1000); + //Ensure the move has been processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance1")); + //Ensure the create in the target resource has been processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance2")); + { + auto query =3D Query().resourceFilter("instance2") ; + auto list =3D Sink::Store::read(query.filter("testuid")); + QCOMPARE(list.size(), 1); + } + + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance1")); + { + auto query =3D Query().resourceFilter("instance1") ; + auto list =3D Sink::Store::read(query.filter("testuid")); + QCOMPARE(list.size(), 0); + } + } + + void testCopy() + { + Event event("instance1"); + event.setProperty("uid", "testuid"); + QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testu= id")); + event.setProperty("summary", "summaryValue"); + VERIFYEXEC(Sink::Store::create(event)); + + + Event createdEvent; + // Ensure all local data is processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance1")); + { + auto query =3D Query().resourceFilter("instance1") ; + auto list =3D Sink::Store::read(query.filter("testuid")); + QCOMPARE(list.size(), 1); + createdEvent =3D list.first(); + } + + VERIFYEXEC(Sink::Store::copy(createdEvent, "instance2")); + + //FIXME we can't guarantee that that the create command arrives at= instance2 before the flush command, so we'll just wait for a little bit. + QTest::qWait(100); + //Ensure the copy has been processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance1")); + //Ensure the create in the target resource has been processed + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance2")); + { + auto query =3D Query().resourceFilter("instance2") ; + auto list =3D Sink::Store::read(query.filter("testuid")); + QCOMPARE(list.size(), 1); + } + + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList= () << "instance1")); + { + auto query =3D Query().resourceFilter("instance1") ; + auto list =3D Sink::Store::read(query.filter("testuid")); + QCOMPARE(list.size(), 1); + } + } + +}; + +QTEST_MAIN(InterResourceMoveTest) +#include "interresourcemovetest.moc"