[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [sink/develop] /: Interresourcemovetest/fixed interresourcemove
From:       Christian Mollekopf <chrigi_1 () fastmail ! fm>
Date:       2016-12-09 15:45:48
Message-ID: E1cFNMq-0007L1-Iq () code ! kde ! org
[Download RAW message or body]

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<qint64> Pipeline::modifiedEntity(void const \
*command, size_t size)  
         SinkTrace() << "Moving entity to new resource " << newEntity.identifier() << \
                newEntity.resourceInstanceIdentifier() << targetResource;
         auto job = TypeHelper<CreateHelper>{bufferType}.operator()<KAsync::Job<void>, \
                ApplicationDomain::ApplicationDomainType&>(newEntity);
-        job = job.syncThen<void>([this, newEntity, isMove, targetResource, \
bufferType](const KAsync::Error &error) { +        job = job.syncThen<void>([this, \
current, isMove, targetResource, bufferType](const KAsync::Error &error) {  if \
                (!error) {
-                SinkTrace() << "Move of " << newEntity.identifier() << "was \
successfull"; +                SinkTrace() << "Move of " << current.identifier() << \
"was successfull";  if (isMove) {
                     startTransaction();
                     flatbuffers::FlatBufferBuilder fbb;
-                    auto entityId = fbb.CreateString(newEntity.identifier());
+                    auto entityId = fbb.CreateString(current.identifier());
                     auto type = fbb.CreateString(bufferType);
-                    auto location = Sink::Commands::CreateDeleteEntity(fbb, \
newEntity.revision(), entityId, type, true); +                    auto location = \
                Sink::Commands::CreateDeleteEntity(fbb, current.revision(), entityId, \
                type, true);
                     Sink::Commands::FinishDeleteEntityBuffer(fbb, location);
                     const auto data = 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 <mollekopf@kolabsys.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+#include <QtTest>
+
+#include <QString>
+
+#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 = 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("testuid"));
+        event.setProperty("summary", "summaryValue");
+        VERIFYEXEC(Sink::Store::create<Event>(event));
+
+
+        Event createdEvent;
+        // Ensure all local data is processed
+        VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << \
"instance1")); +        {
+            auto query = Query().resourceFilter("instance1") ;
+            auto list = \
Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); +            \
QCOMPARE(list.size(), 1); +            createdEvent = list.first();
+        }
+
+        VERIFYEXEC(Sink::Store::move<Event>(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 = Query().resourceFilter("instance2") ;
+            auto list = \
Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); +            \
QCOMPARE(list.size(), 1); +        }
+
+        VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << \
"instance1")); +        {
+            auto query = Query().resourceFilter("instance1") ;
+            auto list = \
Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); +            \
QCOMPARE(list.size(), 0); +        }
+    }
+
+    void testCopy()
+    {
+        Event event("instance1");
+        event.setProperty("uid", "testuid");
+        QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid"));
+        event.setProperty("summary", "summaryValue");
+        VERIFYEXEC(Sink::Store::create<Event>(event));
+
+
+        Event createdEvent;
+        // Ensure all local data is processed
+        VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << \
"instance1")); +        {
+            auto query = Query().resourceFilter("instance1") ;
+            auto list = \
Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); +            \
QCOMPARE(list.size(), 1); +            createdEvent = list.first();
+        }
+
+        VERIFYEXEC(Sink::Store::copy<Event>(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 = Query().resourceFilter("instance2") ;
+            auto list = \
Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); +            \
QCOMPARE(list.size(), 1); +        }
+
+        VERIFYEXEC(Sink::ResourceControl::flushMessageQueue(QByteArrayList() << \
"instance1")); +        {
+            auto query = Query().resourceFilter("instance1") ;
+            auto list = \
Sink::Store::read<Event>(query.filter<Event::Uid>("testuid")); +            \
QCOMPARE(list.size(), 1); +        }
+    }
+
+};
+
+QTEST_MAIN(InterResourceMoveTest)
+#include "interresourcemovetest.moc"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic